From 15bd4885a47870f6459957d878cb8e0154affb71 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Fri, 18 Nov 2022 14:17:57 +0100 Subject: [PATCH] [darwin-framework-tool] Do not build Matter SDK twice when config_enable_yaml_tests=false --- .../chip-tool/commands/common/Command.cpp | 2 +- examples/chip-tool/commands/common/Command.h | 1 - .../common/CredentialIssuerCommands.h | 8 ++- .../discover/DiscoverCommissionersCommand.cpp | 1 + .../example/ExampleCredentialIssuerCommands.h | 1 + examples/darwin-framework-tool/BUILD.gn | 68 +++++++++++++++---- .../commands/clusters/ModelCommandBridge.h | 2 - .../commands/common/CHIPCommandBridge.h | 1 + .../pairing/OpenCommissioningWindowCommand.h | 4 +- .../templates/tests/commands.zapt | 1 + scripts/build/build_darwin_framework.py | 4 ++ .../zap-generated/test/Commands.h | 1 + 12 files changed, 73 insertions(+), 21 deletions(-) diff --git a/examples/chip-tool/commands/common/Command.cpp b/examples/chip-tool/commands/common/Command.cpp index 077e0fb715f589..ebfb99bad5c9e5 100644 --- a/examples/chip-tool/commands/common/Command.cpp +++ b/examples/chip-tool/commands/common/Command.cpp @@ -17,8 +17,8 @@ */ #include "Command.h" -#include "platform/PlatformManager.h" +#include #include #include #include diff --git a/examples/chip-tool/commands/common/Command.h b/examples/chip-tool/commands/common/Command.h index 96de49477621d8..265bf1af3c5925 100644 --- a/examples/chip-tool/commands/common/Command.h +++ b/examples/chip-tool/commands/common/Command.h @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include diff --git a/examples/chip-tool/commands/common/CredentialIssuerCommands.h b/examples/chip-tool/commands/common/CredentialIssuerCommands.h index 2a5df5a42abe63..1ea712ffa9593f 100644 --- a/examples/chip-tool/commands/common/CredentialIssuerCommands.h +++ b/examples/chip-tool/commands/common/CredentialIssuerCommands.h @@ -19,12 +19,18 @@ #pragma once #include -#include #include #include #include #include +namespace chip { +namespace Controller { +struct SetupParams; +class OperationalCredentialsDelegate; +} // namespace Controller +} // namespace chip + class CredentialIssuerCommands { public: diff --git a/examples/chip-tool/commands/discover/DiscoverCommissionersCommand.cpp b/examples/chip-tool/commands/discover/DiscoverCommissionersCommand.cpp index b2fe353931328a..0d1c9a032de02c 100644 --- a/examples/chip-tool/commands/discover/DiscoverCommissionersCommand.cpp +++ b/examples/chip-tool/commands/discover/DiscoverCommissionersCommand.cpp @@ -18,6 +18,7 @@ #include "DiscoverCommissionersCommand.h" #include +#include using namespace ::chip; diff --git a/examples/chip-tool/commands/example/ExampleCredentialIssuerCommands.h b/examples/chip-tool/commands/example/ExampleCredentialIssuerCommands.h index da4716e957e921..e06466ca4ab67d 100644 --- a/examples/chip-tool/commands/example/ExampleCredentialIssuerCommands.h +++ b/examples/chip-tool/commands/example/ExampleCredentialIssuerCommands.h @@ -19,6 +19,7 @@ #pragma once #include +#include #include #include #include diff --git a/examples/darwin-framework-tool/BUILD.gn b/examples/darwin-framework-tool/BUILD.gn index 5a9fbabfbbe5b2..51746d12455679 100644 --- a/examples/darwin-framework-tool/BUILD.gn +++ b/examples/darwin-framework-tool/BUILD.gn @@ -143,20 +143,6 @@ executable("darwin-framework-tool") { deps = [ ":build-darwin-framework", - "${chip_root}/src/app/tests/suites/commands/delay", - - # IM is needed for MTRError - "${chip_root}/src/app/tests/suites/commands/interaction_model", - - # Log is needed by tests UserPrompt and Log - "${chip_root}/src/app/tests/suites/commands/log", - - # System is needed by tests FactoryReset etc.. - "${chip_root}/src/app/tests/suites/commands/system", - - # pics is needed by tests - "${chip_root}/src/app/tests/suites/pics", - "${chip_root}/third_party/inipp", "${chip_root}/third_party/jsoncpp", ] @@ -175,6 +161,60 @@ executable("darwin-framework-tool") { "Security.framework", ] + # When config_enable_yaml_tests=true the Matter SDK is pulled in as a dependency because the code of the test suite + # uses some helpers from the Matter SDK. As a result, the SDK is built twice. Once because of this dependency and once + # when the Matter.framework is built. + # It may results in different versions of the Matter SDK between the output binary and the linked Matter.framework. + # + # When config_enable_yaml_tests=false the Matter SDK is built once when the Matter.framework is built and the resulting + # libCHIP.a library is linked statically to the output binary. + if (config_enable_yaml_tests) { + deps += [ + "${chip_root}/src/app/tests/suites/commands/delay", + + # IM is needed for MTRError + "${chip_root}/src/app/tests/suites/commands/interaction_model", + + # Log is needed by tests UserPrompt and Log + "${chip_root}/src/app/tests/suites/commands/log", + + # System is needed by tests FactoryReset etc.. + "${chip_root}/src/app/tests/suites/commands/system", + + # pics is needed by tests + "${chip_root}/src/app/tests/suites/pics", + ] + } else { + include_dirs = [ + "${chip_root}/config/standalone/", + "${chip_root}/src/", + "${chip_root}/src/include/", + "${chip_root}/third_party/nlassert/repo/include/", + "${chip_root}/third_party/nlio/repo/include/", + "${chip_root}/zzz_generated/app-common/", + "${root_gen_dir}/include", + "${root_out_dir}/macos_framework_output/Build/Intermediates.noindex/Matter.build/${output_sdk_type}/Matter.build/out/gen/include", + ] + + defines = [ + "CHIP_HAVE_CONFIG_H=1", + "CHIP_SYSTEM_CONFIG_USE_SOCKETS=1", + ] + + frameworks += [ + "CoreFoundation.framework", + "Foundation.framework", + "CoreBluetooth.framework", + "Network.framework", + ] + + # Other SDKs are linked statically to Matter.framework but the macosx SDK is linked dynamically but needs some symbols that are + # not exposed by the dylib. + if (sdk == "macosx") { + libs = [ "${root_out_dir}/macos_framework_output/Build/Intermediates.noindex/Matter.build/${output_sdk_type}/Matter.build/out/lib/libCHIP.a" ] + } + } + public_configs = [ ":config" ] output_dir = root_out_dir diff --git a/examples/darwin-framework-tool/commands/clusters/ModelCommandBridge.h b/examples/darwin-framework-tool/commands/clusters/ModelCommandBridge.h index df6cf196c04569..447d2c2ae5ccf6 100644 --- a/examples/darwin-framework-tool/commands/clusters/ModelCommandBridge.h +++ b/examples/darwin-framework-tool/commands/clusters/ModelCommandBridge.h @@ -24,8 +24,6 @@ class ModelCommand : public CHIPCommandBridge { public: - using ChipDevice = ::chip::OperationalDeviceProxy; - ModelCommand(const char * _Nonnull commandName) : CHIPCommandBridge(commandName) {} void AddArguments() diff --git a/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.h b/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.h index ca11c746e30e09..bf5e7b49fce0fd 100644 --- a/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.h +++ b/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include "../provider/OTAProviderDelegate.h" diff --git a/examples/darwin-framework-tool/commands/pairing/OpenCommissioningWindowCommand.h b/examples/darwin-framework-tool/commands/pairing/OpenCommissioningWindowCommand.h index e9fc4ce373b352..68c0d2b7aab6aa 100644 --- a/examples/darwin-framework-tool/commands/pairing/OpenCommissioningWindowCommand.h +++ b/examples/darwin-framework-tool/commands/pairing/OpenCommissioningWindowCommand.h @@ -31,8 +31,8 @@ class OpenCommissioningWindowCommand : public CHIPCommandBridge "1 to use Enhanced Commissioning Method.\n 0 to use Basic Commissioning Method."); AddArgument("window-timeout", 0, UINT16_MAX, &mCommissioningWindowTimeoutMs, "Time, in seconds, before the commissioning window closes."); - AddArgument("iteration", chip::kSpake2p_Min_PBKDF_Iterations, chip::kSpake2p_Max_PBKDF_Iterations, &mIteration, - "Number of PBKDF iterations to use to derive the verifier. Ignored if 'option' is 0."); + AddArgument("iteration", chip::Crypto::kSpake2p_Min_PBKDF_Iterations, chip::Crypto::kSpake2p_Max_PBKDF_Iterations, + &mIteration, "Number of PBKDF iterations to use to derive the verifier. Ignored if 'option' is 0."); AddArgument("discriminator", 0, 4096, &mDiscriminator, "Discriminator to use for advertising. Ignored if 'option' is 0."); AddArgument("timeout", 0, UINT16_MAX, &mTimeout, "Time, in seconds, before this command is considered to have timed out."); } diff --git a/examples/darwin-framework-tool/templates/tests/commands.zapt b/examples/darwin-framework-tool/templates/tests/commands.zapt index adfa4662f7b1c5..4040d94975a8be 100644 --- a/examples/darwin-framework-tool/templates/tests/commands.zapt +++ b/examples/darwin-framework-tool/templates/tests/commands.zapt @@ -4,6 +4,7 @@ #if CONFIG_ENABLE_YAML_TESTS +#include #include #include #include diff --git a/scripts/build/build_darwin_framework.py b/scripts/build/build_darwin_framework.py index d84ea53cf20837..77b033d019883f 100644 --- a/scripts/build/build_darwin_framework.py +++ b/scripts/build/build_darwin_framework.py @@ -65,6 +65,10 @@ def build_darwin_framework(args): # Build Matter.framework as a static library "SUPPORTS_TEXT_BASED_API=NO", "MACH_O_TYPE=staticlib", + # Change visibility flags such that both darwin-framework-tool and Matter.framework + # are built with the same flags. + "GCC_INLINES_ARE_PRIVATE_EXTERN=NO", + "GCC_SYMBOLS_PRIVATE_EXTERN=NO", ] command_result = run_command(command) diff --git a/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h b/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h index 560a723adefbd1..2329031ef9ec52 100644 --- a/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h +++ b/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h @@ -21,6 +21,7 @@ #if CONFIG_ENABLE_YAML_TESTS +#include #include #include #include