Skip to content

Commit

Permalink
Use include-what-you-use on lib/core (#32046)
Browse files Browse the repository at this point in the history
* A first pass at running IWYU with some manual fixes

* Refert platform file changes

* Move one header up due to self-review

* Move self-header to top of file

* Another pass this time with -Xiwyu flags

* Start adding a IWYU mapping so we need less manual fixes

* Fix command line

* Update iwyu.imp

* Remove forward decl

* Fix for compile

* Fixes to compile locally ... several things could be cleaned

* One more cleanup, linux all-clusters compiles at least

---------

Co-authored-by: Andrei Litvin <[email protected]>
  • Loading branch information
andy31415 and andreilitvin authored Feb 13, 2024
1 parent f5b4caf commit f8d7d1d
Show file tree
Hide file tree
Showing 23 changed files with 165 additions and 140 deletions.
22 changes: 22 additions & 0 deletions iwyu.imp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# General IWYU command example:
#
# iwyu_tool.py \
# -p out/linux-x64-all-clusters-clang/compile_commands.json \
# src/lib/core/ \
# -- \
# -Xiwyu --mapping_file=$(pwd)/iwyu.imp \
# -Xiwyu --no_comments \
# -Xiwyu --comment_style=none \
# -Xiwyu --cxx17ns \
# -Xiwyu no_fwd_decls \
# | tee out/iwyu.out
#
# cd out/linux-x64-all-clusters-clang
#
# fix_includes.py <../iwyu.out
#
[
{ include: [ '"system/SystemBuildConfig.h"', private, '<system/SystemConfig.h>', public ] },
{ include: [ '"core/CHIPBuildConfig.h"', private, '<lib/core/CHIPConfig.h>', public ] },
{ include: [ '@"platform/.*/CHIPPlatformConfig.h"', private, '<lib/core/CHIPConfig.h>', public ] },
]
8 changes: 1 addition & 7 deletions src/lib/core/CHIPError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @file
* This file contains functions for working with CHIP errors.
*/

#include <stddef.h>
#include <lib/core/CHIPError.h>

#include <lib/core/CHIPConfig.h>
#include <lib/core/ErrorStr.h>
Expand Down
1 change: 0 additions & 1 deletion src/lib/core/CHIPError.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

#include <inttypes.h>
#include <limits>
#include <stdint.h>
#include <type_traits>

namespace chip {
Expand Down
9 changes: 1 addition & 8 deletions src/lib/core/CHIPKeyIds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <lib/core/CHIPKeyIds.h>

/**
* @file
* This file implements CHIP key types helper functions.
*
*/
#include "CHIPKeyIds.h"

#include <lib/core/CHIPCore.h>
#include <lib/support/CodeUtils.h>

namespace chip {
Expand Down
2 changes: 0 additions & 2 deletions src/lib/core/CHIPKeyIds.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
* key flags, key ID fields, and helper API functions.
*
*/

#pragma once

#include <limits.h>
#include <stdint.h>

namespace chip {
Expand Down
15 changes: 5 additions & 10 deletions src/lib/core/ErrorStr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @file
* This file implements functions to translate error codes used
* throughout the CHIP package into human-readable strings.
*
*/
#include <lib/core/ErrorStr.h>

#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif

#include <lib/core/CHIPConfig.h>
#include <lib/core/CHIPError.h>
#include <lib/support/DLLUtil.h>

#include <inttypes.h>
#include <stdio.h>

#include <lib/core/CHIPConfig.h>
#include <lib/core/ErrorStr.h>

namespace chip {

/**
Expand Down
1 change: 0 additions & 1 deletion src/lib/core/ErrorStr.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <stdint.h>

#include <lib/core/CHIPError.h>
#include <lib/support/DLLUtil.h>

namespace chip {

Expand Down
13 changes: 10 additions & 3 deletions src/lib/core/OTAImageHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <lib/core/OTAImageHeader.h>

#include "OTAImageHeader.h"

#include <lib/core/TLV.h>
#include <lib/core/CHIPError.h>
#include <lib/core/Optional.h>
#include <lib/core/TLVReader.h>
#include <lib/core/TLVTags.h>
#include <lib/core/TLVTypes.h>
#include <lib/support/BufferReader.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/ScopedBuffer.h>
#include <lib/support/Span.h>

#include <string.h>

namespace chip {

Expand Down
1 change: 1 addition & 0 deletions src/lib/core/OTAImageHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#pragma once

#include <lib/core/CHIPError.h>
#include <lib/core/Optional.h>
#include <lib/support/ScopedBuffer.h>
#include <lib/support/Span.h>
Expand Down
11 changes: 6 additions & 5 deletions src/lib/core/TLVCircularBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@
* to continually add top-level TLV elements by evicting
* pre-existing elements.
*/
#include <lib/core/TLVCircularBuffer.h>

#ifndef __STDC_LIMIT_MACROS
#define __STDC_LIMIT_MACROS
#endif
#include <lib/core/TLVCircularBuffer.h>

#include <lib/core/CHIPCore.h>
#include <lib/core/CHIPEncoding.h>
#include <lib/core/TLV.h>

#include <lib/core/CHIPError.h>
#include <lib/core/TLVReader.h>
#include <lib/core/TLVTags.h>
#include <lib/core/TLVWriter.h>
#include <lib/support/BufferWriter.h>
#include <lib/support/CodeUtils.h>

#include <stdint.h>
Expand Down
8 changes: 4 additions & 4 deletions src/lib/core/TLVCircularBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
#pragma once

#include <lib/core/CHIPError.h>
#include <lib/core/TLV.h>
#include <lib/core/TLVTags.h>
#include <lib/core/TLVTypes.h>

#include <lib/core/TLVBackingStore.h>
#include <lib/core/TLVReader.h>
#include <lib/core/TLVWriter.h>
#include <lib/support/DLLUtil.h>

#include <stdint.h>
#include <stdlib.h>

namespace chip {
Expand Down
17 changes: 5 additions & 12 deletions src/lib/core/TLVDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @file
* This file implements interfaces for debugging and logging
* CHIP TLV.
*
*/
#include <lib/core/TLVDebug.h>

#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif

#include <ctype.h>
#include <inttypes.h>
#include <string.h>

#include <lib/core/TLV.h>
#include <lib/core/TLVDebug.h>
#include <lib/core/CHIPError.h>
#include <lib/core/TLVReader.h>
#include <lib/core/TLVTags.h>
#include <lib/core/TLVTypes.h>
#include <lib/core/TLVUtilities.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>

namespace chip {

Expand Down
14 changes: 3 additions & 11 deletions src/lib/core/TLVDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @file
* This file defines types and interfaces for debugging and
* logging CHIP TLV.
*
*/

#pragma once

#include <stddef.h>
#include <stdint.h>

#include <lib/core/CHIPError.h>
#include <lib/core/TLV.h>
#include <lib/core/TLVReader.h>
#include <lib/core/TLVTags.h>
#include <lib/core/TLVTypes.h>

namespace chip {

namespace TLV {

/**
Expand Down
26 changes: 17 additions & 9 deletions src/lib/core/TLVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,32 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <lib/core/TLVReader.h>

/**
* @file
* This file implements a parser for the CHIP TLV (Tag-Length-Value) encoding format.
*
*/
#include <stdint.h>
#include <string.h>

#include <stdlib.h>

#include <lib/core/CHIPCore.h>
#include <lib/core/CHIPConfig.h>
#include <lib/core/CHIPEncoding.h>
#include <lib/core/CHIPError.h>
#include <lib/core/CHIPSafeCasts.h>
#include <lib/core/TLV.h>
#include <lib/core/DataModelTypes.h>
#include <lib/core/Optional.h>
#include <lib/core/TLVBackingStore.h>
#include <lib/core/TLVCommon.h>
#include <lib/core/TLVTags.h>
#include <lib/core/TLVTypes.h>
#include <lib/support/BufferWriter.h>
#include <lib/support/BytesToHex.h>
#include <lib/support/CHIPMem.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/SafeInt.h>
#include <lib/support/Span.h>
#include <lib/support/logging/TextOnlyLogging.h>

#if CHIP_CONFIG_TLV_VALIDATE_CHAR_STRING_ON_READ
#include <lib/support/utf8.h>
#endif

namespace chip {
namespace TLV {
Expand Down
19 changes: 15 additions & 4 deletions src/lib/core/TLVReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,25 @@
* shares many properties with the commonly used JSON serialization format while being considerably
* more compact over the wire.
*/

#pragma once

#include <stddef.h>
#include <stdint.h>
#include <type_traits>
#include <utility>

#include <lib/core/CHIPError.h>
#include <lib/core/DataModelTypes.h>
#include <lib/core/Optional.h>

#include "TLVCommon.h"
#include "TLVWriter.h"
#include <lib/core/TLVBackingStore.h>
#include <lib/core/TLVTags.h>
#include <lib/core/TLVTypes.h>
#include <lib/support/BitFlags.h>
#include <lib/support/BitMask.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/DLLUtil.h>
#include <lib/support/ScopedBuffer.h>
#include <lib/support/Span.h>

/**
* @namespace chip::TLV
Expand Down
7 changes: 6 additions & 1 deletion src/lib/core/TLVTags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "TLVTags.h"
#include <lib/core/TLVTags.h>

#include <inttypes.h>

#include <lib/support/StringBuilder.h>
#include <lib/support/logging/TextOnlyLogging.h>

namespace chip {
namespace TLV {
Expand Down
10 changes: 2 additions & 8 deletions src/lib/core/TLVTags.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @file
* This file contains definitions for working with CHIP TLV tags.
*
*/

#pragma once

#include <cstdint>
#include <lib/support/StringBuilder.h>
#include <lib/support/TypeTraits.h>

#include <cstdint>
#include <type_traits>

namespace chip {
Expand Down
26 changes: 15 additions & 11 deletions src/lib/core/TLVUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @file
* This file implements an updating encoder for the CHIP TLV
* (Tag-Length-Value) encoding format.
*
*/

#include <lib/core/CHIPCore.h>
#include <lib/core/CHIPEncoding.h>
#include <lib/core/TLV.h>
#include <lib/core/TLVUpdater.h>

#include <stdint.h>
#include <string.h>

#include <lib/core/CHIPConfig.h>
#include <lib/core/CHIPError.h>
#include <lib/core/TLVCommon.h>
#include <lib/core/TLVReader.h>
#include <lib/core/TLVTags.h>
#include <lib/core/TLVTypes.h>
#include <lib/core/TLVWriter.h>
#include <lib/support/BufferWriter.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/logging/Constants.h>
#include <lib/support/logging/TextOnlyLogging.h>

namespace chip {
namespace TLV {
Expand Down
Loading

0 comments on commit f8d7d1d

Please sign in to comment.