project-chip / connectedhomeip

Matter (formerly Project CHIP) creates more connections between more objects, simplifying development for manufacturers and increasing compatibility for consumers, guided by the Connectivity Standards Alliance.
https://buildwithmatter.com
Apache License 2.0
7.37k stars 1.98k forks source link

build broken with chip_enable_ble=false #3179

Closed msandstedt closed 3 years ago

msandstedt commented 3 years ago

Problem

I cannot get connectedhomeip to build for Linux and Darwin targets at HEAD of master with chip_config_network_layer_ble=false. I am testing at this hash:

commit 23e3f5ac87bda18ce203e1241a056de08cbcf719 (upstream/master, master)
Author: Vivien Nicolas <vnicolas@apple.com>
Date:   Fri Oct 9 05:53:27 2020 +0200

Reproducer is:

connectedhomeip$ uname -a
Darwin MN-MSANDSTEDT-M 19.2.0 Darwin Kernel Version 19.2.0: Sat Nov  9 03:47:04 PST 2019; root:xnu-6153.61.1~20/RELEASE_X86_64 x86_64
connectedhomeip$ git checkout 23e3f5ac87bda18ce203e1241a056de08cbcf719
M   examples/common/m5stack-tft/repo
M   third_party/bluez/repo
M   third_party/nlio/repo
M   third_party/ot-br-posix/repo
M   third_party/ot-commissioner/repo
M   third_party/pigweed/repo
Note: checking out '23e3f5ac87bda18ce203e1241a056de08cbcf719'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 23e3f5ac Add Barrier Control cluster commands to chip-tool and src/app/ (#3066)
connectedhomeip$ git submodule update --init --recursive
Submodule path 'third_party/bluez/repo': checked out 'b8c156ffa3ab524813cdf4e0fd9afce59ff675bf'
Submodule path 'third_party/nlio/repo': checked out '5bc9ff07974c503d283ea8edf5b301f65e167e74'
Submodule path 'third_party/ot-br-posix/repo': checked out 'd1671cfa4777d3a1bb565b88856f1ef446fe760f'
Submodule path 'third_party/ot-commissioner/repo': checked out '99372e440c65cc41cd04a809cb6de2c24d54a99e'
Submodule path 'third_party/pigweed/repo': checked out 'bb2bc72fcb4936e9a7ca016870d784aa7937d43c'
connectedhomeip$ gn gen out --args='chip_config_network_layer_ble=false'
Done. Made 176 targets from 82 files in 357ms
ninja -C out
ninja: Entering directory `out' 
[1/1] Regenerating ninja files
[22/385] c++ obj/src/ble/tests/libBleLayerTests.TestBleErrorStr.cpp.o
FAILED: obj/src/ble/tests/libBleLayerTests.TestBleErrorStr.cpp.o
g++ -MMD -MF obj/src/ble/tests/libBleLayerTests.TestBleErrorStr.cpp.o.d -O0 -g2 -fno-common -ffunction-sections -fdata-sections -fno-exceptions -fPIC -Wall -Werror -Wno-deprecated-declarations -Wno-unknown-warning-option -Wno-missing-field-initializers -Wno-unused-but-set-variable -Wno-unused-variable -Wno-psabi -Wno-cast-function-type -Wno-maybe-uninitialized -fdiagnostics-color -fno-strict-aliasing -std=gnu++11 -fno-rtti -Wno-non-virtual-dtor -Wno-deprecated-copy  -I../third_party/nlunit-test/repo/src -c ../src/ble/tests/TestBleErrorStr.cpp -o obj/src/ble/tests/libBleLayerTests.TestBleErrorStr.cpp.o
../src/ble/tests/TestBleErrorStr.cpp:41:10: fatal error: 'ble/BleError.h' file not found
#include <ble/BleError.h>
         ^~~~~~~~~~~~~~~~
1 error generated.

At this hash I am able to make this build work with the following changes:

connectedhomeip$ git checkout bcdff23a71cf5854db4a23de78e611cceed580b6
connectedhomeip$ echo "diff --git a/src/BUILD.gn b/src/BUILD.gn
index 863be6f6..e197b5b9 100644
--- a/src/BUILD.gn
+++ b/src/BUILD.gn
@@ -27,9 +27,6 @@ config("includes") {

   defines = [ "CHIP_SEPARATE_CONFIG_H=1" ]

-  if (current_os == "linux") {
-    defines += [ "CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE=1" ]
-  }
 }

 if (chip_build_tests) {
diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp
index e1a132fe..45d4d900 100644
--- a/src/controller/CHIPDeviceController.cpp
+++ b/src/controller/CHIPDeviceController.cpp
@@ -157,12 +157,12 @@ CHIP_ERROR ChipDeviceController::ConnectDevice(NodeId remoteDeviceId, Rendezvous
     VerifyOrExit(mState == kState_Initialized, err = CHIP_ERROR_INCORRECT_STATE);
     VerifyOrExit(mConState == kConnectionState_NotConnected, err = CHIP_ERROR_INCORRECT_STATE);

-#if CONFIG_DEVICE_LAYER
+#if CONFIG_DEVICE_LAYER && CONFIG_NETWORK_LAYER_BLE
     if (!params.HasBleLayer())
     {
         params.SetBleLayer(DeviceLayer::ConnectivityMgr().GetBleLayer());
     }
-#endif // CONFIG_DEVICE_LAYER
+#endif // CONFIG_DEVICE_LAYER && CONFIG_NETWORK_LAYER_BLE

     rendezvousSession = new RendezvousSession(this, params.SetLocalNodeId(mLocalDeviceId));
     err               = rendezvousSession->Init();
diff --git a/src/platform/Darwin/CHIPDevicePlatformConfig.h b/src/platform/Darwin/CHIPDevicePlatformConfig.h
index 4a719631..b3a98bd0 100644
--- a/src/platform/Darwin/CHIPDevicePlatformConfig.h
+++ b/src/platform/Darwin/CHIPDevicePlatformConfig.h
@@ -31,7 +31,11 @@

 #define CHIP_DEVICE_CONFIG_ENABLE_THREAD 0

+#if CONFIG_NETWORK_LAYER_BLE
 #define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1
+#else
+#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 0
+#endif

 #define CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC 0

diff --git a/src/platform/Linux/CHIPDevicePlatformConfig.h b/src/platform/Linux/CHIPDevicePlatformConfig.h
index 5039554d..c87b7779 100644
--- a/src/platform/Linux/CHIPDevicePlatformConfig.h
+++ b/src/platform/Linux/CHIPDevicePlatformConfig.h
@@ -33,7 +33,9 @@
 #define CHIP_DEVICE_CONFIG_ENABLE_THREAD 1
 #endif

-#ifndef CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
+#if CONFIG_NETWORK_LAYER_BLE
+#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1
+#else
 #define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 0
 #endif

diff --git a/src/transport/RendezvousSession.h b/src/transport/RendezvousSession.h
index d789c6dc..ae645d34 100644
--- a/src/transport/RendezvousSession.h
+++ b/src/transport/RendezvousSession.h
@@ -22,6 +22,9 @@
 #include <transport/RendezvousParameters.h>
 #include <transport/RendezvousSessionDelegate.h>
 #include <transport/SecurePairingSession.h>
+#include <system/SystemPacketBuffer.h>
+
+using ::chip::System::PacketBuffer;

 namespace chip {
" | patch -p1
connectedhomeip$ gn gen out --args='chip_config_network_layer_ble=false'
Done. Made 151 targets from 75 files in 130ms 
connectedhomeip$ ninja -C out
ninja: Entering directory `out'
[106/449] ar libmbedtls.a
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: lib/libmbedtls.a(libmbedtls.padlock.c.o) has no symbols
[388/449] ar libDeviceLayer.a
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: obj/src/platform/lib/libDeviceLayer.a(libDeviceLayer.BLEManagerImpl.cpp.o) has no symbols
[431/449] ar libCHIP.a
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: lib/libCHIP.a(libDeviceLayer.BLEManagerImpl.cpp.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: lib/libCHIP.a(lwip.dhcp6.c.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: lib/libCHIP.a(lwip.inet6.c.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: lib/libCHIP.a(lwip.api_lib.c.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: lib/libCHIP.a(lwip.api_msg.c.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: lib/libCHIP.a(lwip.if.c.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: lib/libCHIP.a(lwip.netbuf.c.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: lib/libCHIP.a(lwip.netdb.c.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: lib/libCHIP.a(lwip.netifapi.c.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: lib/libCHIP.a(lwip.sockets.c.o) has no symbols
[449/449] stamp obj/default.stamp

That is the latest commit at which I'm able to build with this flag. Immediately after that, this commit seems to break the build for other reasons, that are now resolved in master, but make it impossible to bisect further to locate other regressions related to build with chip_config_network_layer_ble=false:

commit b173fee5fe34711e333963af9c0be5aeb1e0806c (HEAD, refs/bisect/bad)
Author: Michael Spang <spang@google.com>
Date:   Tue Sep 22 17:59:09 2020 -0400

    Remove <iostream> (#2759)
issue-label-bot[bot] commented 3 years ago

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.94. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

msandstedt commented 3 years ago

I seem to have a fix with simply the following:

commit e64fbc3226571b73b816241874357edc9d4634bb (HEAD -> fix_ble, mine/fix_ble)
Author: Michael Sandstedt <michael.sandstedt@smartthings.com>
Date:   Tue Oct 13 09:18:19 2020 -0500

    [build] fix linux builds with chip_enable_ble=false (#3179)

diff --git a/src/BUILD.gn b/src/BUILD.gn
index 863be6f6..d29ec3b5 100644
--- a/src/BUILD.gn
+++ b/src/BUILD.gn
@@ -27,8 +27,8 @@ config("includes") {

   defines = [ "CHIP_SEPARATE_CONFIG_H=1" ]

-  if (current_os == "linux") {
-    defines += [ "CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE=1" ]
+  if (chip_device_platform == "linux") {
+    defines += [ "CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE=${chip_enable_ble}" ]
   }
 }

I will submit a PR shortly.