Skip to content

Commit

Permalink
Reduce the number of include roots
Browse files Browse the repository at this point in the history
There seems to be little agreement about where to root #includes.  We
should not use every possible convention for this. Reduce the number of
include roots by removing those that add little value.

In particular this decreases the number of "bare" includes with no
directory component. It is beneficial for readability to leave a clue
about which component the header belongs to in the path.

It also removes some cases where headers with very generic names are
included with quotes and shadowed by local headers in some directories,
e.g. "config.h" and "common.h".

This does not completely fix the inconsistencies, but fixes the low
hanging fruit. Remaining issues include:

- We still include relative to both src/ and src/lib/
  (does "lib" still make sense ? Its contents don't correspond to libCHIP's)

- src/platform/ is still the only directory that uses src/include/

- "project configs" are typically included by adding include_dirs rather
  than setting *_PROJECT_CONFIG_INCLUDE relative to a common root
  • Loading branch information
mspang committed Apr 23, 2021
1 parent 5b9f9dc commit 34812a1
Show file tree
Hide file tree
Showing 175 changed files with 258 additions and 340 deletions.
4 changes: 2 additions & 2 deletions build/chip/linux/gdbus_library.gni
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ template("gdbus_library") {
assert(defined(invoker.dbus_out_dir), "Please specify dbus_out_dir")

dbus_out_dir = invoker.dbus_out_dir
dbus_gen_dir = "${root_gen_dir}/${dbus_out_dir}"
dbus_gen_dir = "${root_gen_dir}/include/${dbus_out_dir}"

config("${library_name}_config") {
include_dirs = [ root_gen_dir ]
include_dirs = [ "${root_gen_dir}/include" ]
}

dbus_sources = []
Expand Down
7 changes: 3 additions & 4 deletions config/esp32/components/chip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,13 @@ target_include_directories(${COMPONENT_LIB} PRIVATE

target_include_directories(${COMPONENT_LIB} INTERFACE
"${CHIP_ROOT}/src/platform/ESP32"
"${CHIP_ROOT}/src/include/"
"${CHIP_ROOT}/src/include"
"${CHIP_ROOT}/src/lib"
"${CHIP_ROOT}/src/"
"${CHIP_ROOT}/src/system"
"${CHIP_ROOT}/src"
"${CHIP_ROOT}/third_party/nlassert/repo/include"
"${CHIP_ROOT}/third_party/nlio/repo/include"
"${CMAKE_CURRENT_BINARY_DIR}/src/include"
"${CMAKE_CURRENT_BINARY_DIR}/include"
"${CMAKE_CURRENT_BINARY_DIR}/gen/third_party/connectedhomeip/src/app/include"
"${CMAKE_CURRENT_BINARY_DIR}/gen/include"
)

Expand Down
4 changes: 0 additions & 4 deletions config/nrfconnect/chip-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,10 @@ zephyr_interface_library_named(chip)
target_compile_definitions(chip INTERFACE CHIP_HAVE_CONFIG_H)
target_include_directories(chip INTERFACE
${CHIP_ROOT}/src
${CHIP_ROOT}/src/app/server
${CHIP_ROOT}/src/app/util
${CHIP_ROOT}/src/include
${CHIP_ROOT}/src/lib
${CHIP_ROOT}/src/lib/core
${CHIP_ROOT}/third_party/nlassert/repo/include
${CMAKE_CURRENT_BINARY_DIR}/gen/include
${CMAKE_CURRENT_BINARY_DIR}/gen/third_party/connectedhomeip/src/app/include
)
target_link_directories(chip INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/lib)
target_link_libraries(chip INTERFACE -Wl,--whole-archive ${CHIP_ZEPHYR_SHELL_LIBRARY} -Wl,--no-whole-archive,--start-group ${CHIP_LIBRARIES} -Wl,--end-group)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <app/InteractionModelEngine.h>

// Currently we need some work to keep compatible with ember lib.
#include <util/ember-compatibility-functions.h>
#include <app/util/ember-compatibility-functions.h>

namespace chip {
namespace app {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
// Prevent multiple inclusion
#pragma once

#include "basic-types.h"
#include "enums.h"
#include <app/util/basic-types.h>
#include <stdint.h>

// Struct for ApplicationLauncherApp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
// Prevent multiple inclusion
#pragma once

#include "af-types.h"
#include <app/util/af-types.h>
4 changes: 2 additions & 2 deletions examples/all-clusters-app/all-clusters-common/gen/callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#pragma once

#include "af-structs.h"
#include "af-types.h"
#include "basic-types.h"
#include <app/util/af-types.h>
#include <app/util/basic-types.h>

#include <app/Command.h>
#include <lib/support/Span.h>
Expand Down
3 changes: 0 additions & 3 deletions examples/all-clusters-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
# The list of src and include dirs must be in sync with that in all-clusters-app/esp32/main/component.mk
idf_component_register(PRIV_INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/util"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/all-clusters-app/all-clusters-common"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/third_party/nlio/repo/include"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <stdarg.h>
#include <stdlib.h>

#include "af-types.h"
#include <app/util/af-types.h>

namespace chip {
namespace DeviceManager {
Expand Down
8 changes: 4 additions & 4 deletions examples/all-clusters-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/

#include "AppDelegate.h"
#include "BluetoothWidget.h"
#include "Button.h"
#include "CHIPDeviceManager.h"
Expand All @@ -24,10 +23,8 @@
#include "Globals.h"
#include "LEDWidget.h"
#include "ListScreen.h"
#include "OnboardingCodesUtil.h"
#include "QRCodeScreen.h"
#include "ScreenManager.h"
#include "Server.h"
#include "WiFiWidget.h"
#include "esp_heap_caps_init.h"
#include "esp_log.h"
Expand All @@ -48,8 +45,11 @@
#include <string>
#include <vector>

#include <app/server/AppDelegate.h>
#include <app/server/Mdns.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <platform/CHIPDeviceLayer.h>
#include <server/Mdns.h>
#include <setup_payload/ManualSetupPayloadGenerator.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <support/CHIPMem.h>
Expand Down
4 changes: 2 additions & 2 deletions examples/all-clusters-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
#include <platform/CHIPDeviceLayer.h>
#include <platform/PlatformManager.h>

#include "af.h"
#include "gen/attribute-id.h"
#include "gen/cluster-id.h"
#include <app/Command.h>
#include <app/chip-zcl-zpro-codec.h>
#include <app/server/Mdns.h>
#include <app/util/af-types.h>
#include <app/util/af.h>
#include <app/util/attribute-storage.h>
#include <app/util/util.h>
#include <core/CHIPError.h>
#include <support/CHIPMem.h>
#include <support/RandUtils.h>

#include "Server.h"
#include <app/server/Server.h>

#include <cassert>
#include <iostream>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <app/InteractionModelEngine.h>

// Currently we need some work to keep compatible with ember lib.
#include <util/ember-compatibility-functions.h>
#include <app/util/ember-compatibility-functions.h>

namespace chip {
namespace app {
Expand Down
2 changes: 1 addition & 1 deletion examples/bridge-app/bridge-common/gen/af-structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
// Prevent multiple inclusion
#pragma once

#include "basic-types.h"
#include "enums.h"
#include <app/util/basic-types.h>
#include <stdint.h>

// Struct for ApplicationLauncherApp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
// Prevent multiple inclusion
#pragma once

#include "af-types.h"
#include <app/util/af-types.h>
4 changes: 2 additions & 2 deletions examples/bridge-app/bridge-common/gen/callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#pragma once

#include "af-structs.h"
#include "af-types.h"
#include "basic-types.h"
#include <app/util/af-types.h>
#include <app/util/basic-types.h>

#include <app/Command.h>
#include <lib/support/Span.h>
Expand Down
4 changes: 2 additions & 2 deletions examples/bridge-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
#include <platform/CHIPDeviceLayer.h>
#include <platform/PlatformManager.h>

#include "af.h"
#include "gen/attribute-id.h"
#include "gen/cluster-id.h"
#include <app/chip-zcl-zpro-codec.h>
#include <app/util/af-types.h>
#include <app/util/af.h>
#include <app/util/attribute-storage.h>
#include <app/util/util.h>
#include <core/CHIPError.h>
Expand All @@ -34,7 +34,7 @@

#include "LightingManager.h"
#include "Options.h"
#include "Server.h"
#include <app/server/Server.h>

#include <cassert>
#include <iostream>
Expand Down
2 changes: 1 addition & 1 deletion examples/chip-tool/commands/common/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#pragma once

#include <app/util/DataModelHandler.h>
#include <app/server/DataModelHandler.h>
#include <controller/CHIPDeviceController.h>
#include <inet/InetInterface.h>
#include <support/logging/CHIPLogging.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/chip-tool/gen/IMClusterCommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <app/InteractionModelEngine.h>

// Currently we need some work to keep compatible with ember lib.
#include <util/ember-compatibility-functions.h>
#include <app/util/ember-compatibility-functions.h>

namespace chip {
namespace app {
Expand Down
2 changes: 1 addition & 1 deletion examples/chip-tool/gen/af-structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
// Prevent multiple inclusion
#pragma once

#include "basic-types.h"
#include "enums.h"
#include <app/util/basic-types.h>
#include <stdint.h>

// Struct for ApplicationLauncherApp
Expand Down
2 changes: 1 addition & 1 deletion examples/chip-tool/gen/call-command-handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
// Prevent multiple inclusion
#pragma once

#include "af-types.h"
#include <app/util/af-types.h>
4 changes: 2 additions & 2 deletions examples/chip-tool/gen/callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#pragma once

#include "af-structs.h"
#include "af-types.h"
#include "basic-types.h"
#include <app/util/af-types.h>
#include <app/util/basic-types.h>

#include <app/Command.h>
#include <lib/support/Span.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/common/QRCode/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
idf_component_register(SRCS "repo/c/qrcodegen.c"
INCLUDE_DIRS "repo/c")

target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-unknown-pragmas")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-unknown-pragmas")
8 changes: 4 additions & 4 deletions examples/lighting-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
#include "AppConfig.h"
#include "AppEvent.h"
#include "ButtonHandler.h"
#include "DataModelHandler.h"
#include "LEDWidget.h"
#include "OnboardingCodesUtil.h"
#include "Server.h"
#include "Service.h"
#include "attribute-storage.h"
#include "gen/attribute-id.h"
#include "gen/attribute-type.h"
#include "gen/cluster-id.h"
#include "lcd.h"
#include "qrcodegen.h"
#include <app/server/DataModelHandler.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <app/util/attribute-storage.h>

#include <assert.h>

Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/efr32/src/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
*/

#include "AppConfig.h"
#include "DataModelHandler.h"
#include "LightingManager.h"
#include <app/server/DataModelHandler.h>

#include "gen/attribute-id.h"
#include "gen/cluster-id.h"
Expand Down
4 changes: 2 additions & 2 deletions examples/lighting-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
#include <AppTask.h>

#include "AppConfig.h"
#include "DataModelHandler.h"
#include "Server.h"
#include "init_efrPlatform.h"
#include <app/server/DataModelHandler.h>
#include <app/server/Server.h>

#ifdef HEAP_MONITORING
#include "MemMonitoring.h"
Expand Down
3 changes: 0 additions & 3 deletions examples/lighting-app/k32w/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ k32w_sdk("sdk") {
"main",
"${k32w_platform_dir}/app/project_include",
"${k32w_platform_dir}/app/support",
"${chip_root}/examples/lighting-app/lighting-common",
"${chip_root}/src/app/util",
"${chip_root}/src/app/server",
"${k32w_platform_dir}/util/include",
]

Expand Down
6 changes: 3 additions & 3 deletions examples/lighting-app/k32w/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
*/
#include "AppTask.h"
#include "AppEvent.h"
#include "Server.h"
#include "support/ErrorStr.h"
#include <app/server/Server.h>

#include "OnboardingCodesUtil.h"
#include <app/server/OnboardingCodesUtil.h>
#include <platform/CHIPDeviceLayer.h>
#include <platform/internal/DeviceNetworkInfo.h>
#include <support/ThreadOperationalDataset.h>

#include "attribute-storage.h"
#include "gen/attribute-id.h"
#include "gen/attribute-type.h"
#include "gen/cluster-id.h"
#include <app/util/attribute-storage.h>

#include "Keyboard.h"
#include "LED.h"
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/k32w/main/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
#include "AppTask.h"
#include "LightingManager.h"

#include "af.h"
#include "gen/attribute-id.h"
#include "gen/cluster-id.h"
#include <app/util/af-types.h>
#include <app/util/af.h>

using namespace ::chip;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <app/InteractionModelEngine.h>

// Currently we need some work to keep compatible with ember lib.
#include <util/ember-compatibility-functions.h>
#include <app/util/ember-compatibility-functions.h>

namespace chip {
namespace app {
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/lighting-common/gen/af-structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
// Prevent multiple inclusion
#pragma once

#include "basic-types.h"
#include "enums.h"
#include <app/util/basic-types.h>
#include <stdint.h>

// Struct for ApplicationLauncherApp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
// Prevent multiple inclusion
#pragma once

#include "af-types.h"
#include <app/util/af-types.h>
4 changes: 2 additions & 2 deletions examples/lighting-app/lighting-common/gen/callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#pragma once

#include "af-structs.h"
#include "af-types.h"
#include "basic-types.h"
#include <app/util/af-types.h>
#include <app/util/basic-types.h>

#include <app/Command.h>
#include <lib/support/Span.h>
Expand Down
Loading

0 comments on commit 34812a1

Please sign in to comment.