Skip to content

Commit f8d7d1d

Browse files
Use include-what-you-use on lib/core (project-chip#32046)
* 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 <andreilitvin@google.com>
1 parent f5b4caf commit f8d7d1d

23 files changed

+165
-140
lines changed

iwyu.imp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# General IWYU command example:
2+
#
3+
# iwyu_tool.py \
4+
# -p out/linux-x64-all-clusters-clang/compile_commands.json \
5+
# src/lib/core/ \
6+
# -- \
7+
# -Xiwyu --mapping_file=$(pwd)/iwyu.imp \
8+
# -Xiwyu --no_comments \
9+
# -Xiwyu --comment_style=none \
10+
# -Xiwyu --cxx17ns \
11+
# -Xiwyu no_fwd_decls \
12+
# | tee out/iwyu.out
13+
#
14+
# cd out/linux-x64-all-clusters-clang
15+
#
16+
# fix_includes.py <../iwyu.out
17+
#
18+
[
19+
{ include: [ '"system/SystemBuildConfig.h"', private, '<system/SystemConfig.h>', public ] },
20+
{ include: [ '"core/CHIPBuildConfig.h"', private, '<lib/core/CHIPConfig.h>', public ] },
21+
{ include: [ '@"platform/.*/CHIPPlatformConfig.h"', private, '<lib/core/CHIPConfig.h>', public ] },
22+
]

src/lib/core/CHIPError.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
19-
/**
20-
* @file
21-
* This file contains functions for working with CHIP errors.
22-
*/
23-
24-
#include <stddef.h>
18+
#include <lib/core/CHIPError.h>
2519

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

src/lib/core/CHIPError.h

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
#include <inttypes.h>
3535
#include <limits>
36-
#include <stdint.h>
3736
#include <type_traits>
3837

3938
namespace chip {

src/lib/core/CHIPKeyIds.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,8 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18+
#include <lib/core/CHIPKeyIds.h>
1819

19-
/**
20-
* @file
21-
* This file implements CHIP key types helper functions.
22-
*
23-
*/
24-
#include "CHIPKeyIds.h"
25-
26-
#include <lib/core/CHIPCore.h>
2720
#include <lib/support/CodeUtils.h>
2821

2922
namespace chip {

src/lib/core/CHIPKeyIds.h

-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222
* key flags, key ID fields, and helper API functions.
2323
*
2424
*/
25-
2625
#pragma once
2726

28-
#include <limits.h>
2927
#include <stdint.h>
3028

3129
namespace chip {

src/lib/core/ErrorStr.cpp

+5-10
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,19 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
19-
/**
20-
* @file
21-
* This file implements functions to translate error codes used
22-
* throughout the CHIP package into human-readable strings.
23-
*
24-
*/
18+
#include <lib/core/ErrorStr.h>
2519

2620
#ifndef __STDC_FORMAT_MACROS
2721
#define __STDC_FORMAT_MACROS
2822
#endif
2923

24+
#include <lib/core/CHIPConfig.h>
25+
#include <lib/core/CHIPError.h>
26+
#include <lib/support/DLLUtil.h>
27+
3028
#include <inttypes.h>
3129
#include <stdio.h>
3230

33-
#include <lib/core/CHIPConfig.h>
34-
#include <lib/core/ErrorStr.h>
35-
3631
namespace chip {
3732

3833
/**

src/lib/core/ErrorStr.h

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <stdint.h>
2929

3030
#include <lib/core/CHIPError.h>
31-
#include <lib/support/DLLUtil.h>
3231

3332
namespace chip {
3433

src/lib/core/OTAImageHeader.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
#include <lib/core/OTAImageHeader.h>
1718

18-
#include "OTAImageHeader.h"
19-
20-
#include <lib/core/TLV.h>
19+
#include <lib/core/CHIPError.h>
20+
#include <lib/core/Optional.h>
21+
#include <lib/core/TLVReader.h>
22+
#include <lib/core/TLVTags.h>
23+
#include <lib/core/TLVTypes.h>
2124
#include <lib/support/BufferReader.h>
2225
#include <lib/support/CodeUtils.h>
26+
#include <lib/support/ScopedBuffer.h>
27+
#include <lib/support/Span.h>
28+
29+
#include <string.h>
2330

2431
namespace chip {
2532

src/lib/core/OTAImageHeader.h

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#pragma once
1919

20+
#include <lib/core/CHIPError.h>
2021
#include <lib/core/Optional.h>
2122
#include <lib/support/ScopedBuffer.h>
2223
#include <lib/support/Span.h>

src/lib/core/TLVCircularBuffer.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,17 @@
2626
* to continually add top-level TLV elements by evicting
2727
* pre-existing elements.
2828
*/
29+
#include <lib/core/TLVCircularBuffer.h>
2930

3031
#ifndef __STDC_LIMIT_MACROS
3132
#define __STDC_LIMIT_MACROS
3233
#endif
33-
#include <lib/core/TLVCircularBuffer.h>
34-
35-
#include <lib/core/CHIPCore.h>
36-
#include <lib/core/CHIPEncoding.h>
37-
#include <lib/core/TLV.h>
3834

35+
#include <lib/core/CHIPError.h>
36+
#include <lib/core/TLVReader.h>
37+
#include <lib/core/TLVTags.h>
38+
#include <lib/core/TLVWriter.h>
39+
#include <lib/support/BufferWriter.h>
3940
#include <lib/support/CodeUtils.h>
4041

4142
#include <stdint.h>

src/lib/core/TLVCircularBuffer.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
#pragma once
3131

3232
#include <lib/core/CHIPError.h>
33-
#include <lib/core/TLV.h>
34-
#include <lib/core/TLVTags.h>
35-
#include <lib/core/TLVTypes.h>
36-
33+
#include <lib/core/TLVBackingStore.h>
34+
#include <lib/core/TLVReader.h>
35+
#include <lib/core/TLVWriter.h>
3736
#include <lib/support/DLLUtil.h>
3837

38+
#include <stdint.h>
3939
#include <stdlib.h>
4040

4141
namespace chip {

src/lib/core/TLVDebug.cpp

+5-12
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,20 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
19-
/**
20-
* @file
21-
* This file implements interfaces for debugging and logging
22-
* CHIP TLV.
23-
*
24-
*/
18+
#include <lib/core/TLVDebug.h>
2519

2620
#ifndef __STDC_FORMAT_MACROS
2721
#define __STDC_FORMAT_MACROS
2822
#endif
2923

30-
#include <ctype.h>
3124
#include <inttypes.h>
32-
#include <string.h>
3325

34-
#include <lib/core/TLV.h>
35-
#include <lib/core/TLVDebug.h>
26+
#include <lib/core/CHIPError.h>
27+
#include <lib/core/TLVReader.h>
28+
#include <lib/core/TLVTags.h>
29+
#include <lib/core/TLVTypes.h>
3630
#include <lib/core/TLVUtilities.h>
3731
#include <lib/support/CodeUtils.h>
38-
#include <lib/support/logging/CHIPLogging.h>
3932

4033
namespace chip {
4134

src/lib/core/TLVDebug.h

+3-11
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,16 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
19-
/**
20-
* @file
21-
* This file defines types and interfaces for debugging and
22-
* logging CHIP TLV.
23-
*
24-
*/
25-
2618
#pragma once
2719

2820
#include <stddef.h>
29-
#include <stdint.h>
3021

3122
#include <lib/core/CHIPError.h>
32-
#include <lib/core/TLV.h>
23+
#include <lib/core/TLVReader.h>
24+
#include <lib/core/TLVTags.h>
25+
#include <lib/core/TLVTypes.h>
3326

3427
namespace chip {
35-
3628
namespace TLV {
3729

3830
/**

src/lib/core/TLVReader.cpp

+17-9
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,32 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18+
#include <lib/core/TLVReader.h>
1819

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

25-
#include <stdlib.h>
26-
27-
#include <lib/core/CHIPCore.h>
23+
#include <lib/core/CHIPConfig.h>
2824
#include <lib/core/CHIPEncoding.h>
25+
#include <lib/core/CHIPError.h>
2926
#include <lib/core/CHIPSafeCasts.h>
30-
#include <lib/core/TLV.h>
27+
#include <lib/core/DataModelTypes.h>
28+
#include <lib/core/Optional.h>
29+
#include <lib/core/TLVBackingStore.h>
30+
#include <lib/core/TLVCommon.h>
31+
#include <lib/core/TLVTags.h>
32+
#include <lib/core/TLVTypes.h>
33+
#include <lib/support/BufferWriter.h>
3134
#include <lib/support/BytesToHex.h>
3235
#include <lib/support/CHIPMem.h>
3336
#include <lib/support/CodeUtils.h>
3437
#include <lib/support/SafeInt.h>
38+
#include <lib/support/Span.h>
39+
#include <lib/support/logging/TextOnlyLogging.h>
40+
41+
#if CHIP_CONFIG_TLV_VALIDATE_CHAR_STRING_ON_READ
3542
#include <lib/support/utf8.h>
43+
#endif
3644

3745
namespace chip {
3846
namespace TLV {

src/lib/core/TLVReader.h

+15-4
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,25 @@
2424
* shares many properties with the commonly used JSON serialization format while being considerably
2525
* more compact over the wire.
2626
*/
27-
2827
#pragma once
2928

29+
#include <stddef.h>
30+
#include <stdint.h>
31+
#include <type_traits>
32+
#include <utility>
33+
34+
#include <lib/core/CHIPError.h>
3035
#include <lib/core/DataModelTypes.h>
3136
#include <lib/core/Optional.h>
32-
33-
#include "TLVCommon.h"
34-
#include "TLVWriter.h"
37+
#include <lib/core/TLVBackingStore.h>
38+
#include <lib/core/TLVTags.h>
39+
#include <lib/core/TLVTypes.h>
40+
#include <lib/support/BitFlags.h>
41+
#include <lib/support/BitMask.h>
42+
#include <lib/support/CodeUtils.h>
43+
#include <lib/support/DLLUtil.h>
44+
#include <lib/support/ScopedBuffer.h>
45+
#include <lib/support/Span.h>
3546

3647
/**
3748
* @namespace chip::TLV

src/lib/core/TLVTags.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
#include "TLVTags.h"
18+
#include <lib/core/TLVTags.h>
19+
20+
#include <inttypes.h>
21+
22+
#include <lib/support/StringBuilder.h>
23+
#include <lib/support/logging/TextOnlyLogging.h>
1924

2025
namespace chip {
2126
namespace TLV {

src/lib/core/TLVTags.h

+2-8
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,12 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
19-
/**
20-
* @file
21-
* This file contains definitions for working with CHIP TLV tags.
22-
*
23-
*/
24-
2518
#pragma once
2619

27-
#include <cstdint>
2820
#include <lib/support/StringBuilder.h>
2921
#include <lib/support/TypeTraits.h>
22+
23+
#include <cstdint>
3024
#include <type_traits>
3125

3226
namespace chip {

src/lib/core/TLVUpdater.cpp

+15-11
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,22 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
19-
/**
20-
* @file
21-
* This file implements an updating encoder for the CHIP TLV
22-
* (Tag-Length-Value) encoding format.
23-
*
24-
*/
25-
26-
#include <lib/core/CHIPCore.h>
27-
#include <lib/core/CHIPEncoding.h>
28-
#include <lib/core/TLV.h>
18+
#include <lib/core/TLVUpdater.h>
19+
20+
#include <stdint.h>
21+
#include <string.h>
22+
23+
#include <lib/core/CHIPConfig.h>
24+
#include <lib/core/CHIPError.h>
25+
#include <lib/core/TLVCommon.h>
26+
#include <lib/core/TLVReader.h>
27+
#include <lib/core/TLVTags.h>
28+
#include <lib/core/TLVTypes.h>
29+
#include <lib/core/TLVWriter.h>
30+
#include <lib/support/BufferWriter.h>
2931
#include <lib/support/CodeUtils.h>
32+
#include <lib/support/logging/Constants.h>
33+
#include <lib/support/logging/TextOnlyLogging.h>
3034

3135
namespace chip {
3236
namespace TLV {

0 commit comments

Comments
 (0)