From 1766740aae7ad8ae8424448a1a417832406c621c Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Thu, 29 Feb 2024 13:02:34 -0500 Subject: [PATCH] Define explicit `data_model` sub-targets for generated files (#32343) * Define some source sets for data_model * Update dependencies, this seems to work for non-gen for now (with odd naming) * Rename the generate commands and hopefully this makes pregen work * Start using privilege-constants * Add missing file * Fix lint error * Fix android build ... a bit ugly as this dynamic server business is too coupled * Restyle * fix dependency --------- Co-authored-by: Andrei Litvin --- build/chip/chip_codegen.gni | 8 +- .../all-clusters-app/app-templates/access.h | 2 +- .../lighting-app/app-templates/access.h | 2 +- src/app/BUILD.gn | 1 + src/app/chip_data_model.gni | 93 +++++++++++++++++++ src/app/util/privilege-constants.h | 23 +++++ src/app/util/privilege-storage.h | 7 +- .../zap-templates/templates/app/access.zapt | 2 +- 8 files changed, 125 insertions(+), 13 deletions(-) create mode 100644 src/app/util/privilege-constants.h diff --git a/build/chip/chip_codegen.gni b/build/chip/chip_codegen.gni index 08d9f17da6c1be..07f24bdc3e6bc0 100644 --- a/build/chip/chip_codegen.gni +++ b/build/chip/chip_codegen.gni @@ -35,7 +35,7 @@ template("_chip_build_time_codegen") { include_dirs = [ target_gen_dir ] } - pw_python_action("${_name}_codegen") { + pw_python_action("${_name}_generate") { script = "${chip_root}/scripts/codegen.py" # TODO: this seems to touch internals. Is this ok? speeds up builds! @@ -99,7 +99,7 @@ template("_chip_build_time_codegen") { if (!defined(deps)) { deps = [] } - deps += [ ":${_name}_codegen" ] + deps += [ ":${_name}_generate" ] } } @@ -152,7 +152,7 @@ template("_chip_build_time_zapgen") { _output_subdir = "zap-generated" } - pw_python_action("${_name}_zap") { + pw_python_action("${_name}_generate") { script = "${chip_root}/scripts/tools/zap/generate.py" # TODO: this seems to touch internals. Is this ok? speeds up builds! @@ -211,7 +211,7 @@ template("_chip_build_time_zapgen") { if (!defined(public_deps)) { public_deps = [] } - public_deps += [ ":${_name}_zap" ] + public_deps += [ ":${_name}_generate" ] } } diff --git a/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/access.h b/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/access.h index 82dab06aeeae0f..f2260156616eed 100644 --- a/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/access.h +++ b/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/access.h @@ -20,7 +20,7 @@ // Prevent multiple inclusion #pragma once -#include +#include // Prevent changing generated format // clang-format off diff --git a/scripts/tools/zap/tests/outputs/lighting-app/app-templates/access.h b/scripts/tools/zap/tests/outputs/lighting-app/app-templates/access.h index 119c12e6f05c06..d2b8c67daa3fa7 100644 --- a/scripts/tools/zap/tests/outputs/lighting-app/app-templates/access.h +++ b/scripts/tools/zap/tests/outputs/lighting-app/app-templates/access.h @@ -20,7 +20,7 @@ // Prevent multiple inclusion #pragma once -#include +#include // Prevent changing generated format // clang-format off diff --git a/src/app/BUILD.gn b/src/app/BUILD.gn index e6754bd8c32a31..618e51df303f3c 100644 --- a/src/app/BUILD.gn +++ b/src/app/BUILD.gn @@ -229,6 +229,7 @@ static_library("interaction-model") { "dynamic_server/AccessControl.cpp", "dynamic_server/AccessControl.h", "dynamic_server/DynamicDispatcher.cpp", + "util/privilege-constants.h", "util/privilege-storage.cpp", "util/privilege-storage.h", ] diff --git a/src/app/chip_data_model.gni b/src/app/chip_data_model.gni index a065d833b43846..29c5f0399737cc 100644 --- a/src/app/chip_data_model.gni +++ b/src/app/chip_data_model.gni @@ -32,6 +32,26 @@ _app_root = get_path_info(".", "abspath") # # Forwards all the remaining variables to the source_set. # +# +# +# Additional underlying source sets that will be provided +# +# - ${name}-endpoint-metadata +# contains HEADERS that define endpoint metadata from zap/matter files: +# - zap-generated/gen_config.h +# - zap-generated/endpoint_config.h +# - zap-generated/access.h +# - PluginApplicationCallbacks.h +# - ${name}-callbacks +# contains the callback implementation for cluster init: +# - cluster-init-callback.cpp +# - callback-stub.cpp (contains __weak__ implementations. TODO: we should not be using +# weak linkage over time at all) +# - ${name}-command-dispatch: +# contains the implementation of `DispatchServerCommand` which forwards data to +# `emberAf....Cluster...Callback` callbacks +# - zap-generated/IMClusterCommandHandler.cpp +# template("chip_data_model") { _data_model_name = target_name @@ -87,6 +107,79 @@ template("chip_data_model") { ] } + # where generated files reside + # TODO: where can this reside? + if (chip_code_pre_generated_directory == "") { + _zapgen_gen_dir = "${target_gen_dir}/zapgen" + _codegen_gen_dir = "${target_gen_dir}" + } else { + # NOTE: if zap and matter file will reside in different locations + # this path will change between zapgen and codegen + _pregen_dir = + chip_code_pre_generated_directory + "/" + + string_replace(rebase_path(invoker.zap_file, chip_root), ".zap", "") + + _zapgen_gen_dir = "${_pregen_dir}/zap/app-templates" + _codegen_gen_dir = "${_pregen_dir}/codegen/cpp-app" + } + + # Fixed source sets for allowing reasonable dependencies on things: + source_set("${_data_model_name}-endpoint-metadata") { + sources = [ + "${_codegen_gen_dir}/app/PluginApplicationCallbacks.h", + "${_zapgen_gen_dir}/zap-generated/access.h", + "${_zapgen_gen_dir}/zap-generated/endpoint_config.h", + "${_zapgen_gen_dir}/zap-generated/gen_config.h", + ] + + deps = [ "${chip_root}/src/lib/core:chip_config_header" ] + + if (chip_code_pre_generated_directory == "") { + deps += [ + ":${_data_model_name}_codegen_generate", + ":${_data_model_name}_zapgen_generate", + ] + } + } + + source_set("${_data_model_name}-callbacks") { + sources = [ + "${_codegen_gen_dir}/app/callback-stub.cpp", + "${_codegen_gen_dir}/app/cluster-init-callback.cpp", + ] + + deps = [ + "${chip_root}/src/app/common:ids", + "${chip_root}/src/lib/support:span", + "${chip_root}/src/protocols/interaction_model", + ] + + if (chip_code_pre_generated_directory == "") { + deps += [ ":${_data_model_name}_codegen_generate" ] + } + } + + if (!chip_build_controller_dynamic_server) { + source_set("${_data_model_name}-command-dispatch") { + sources = + [ "${_zapgen_gen_dir}/zap-generated/IMClusterCommandHandler.cpp" ] + + deps = [ + "${chip_root}/src/app", + "${chip_root}/src/app:interaction-model", + "${chip_root}/src/app/common:cluster-objects", + "${chip_root}/src/app/common:enums", + "${chip_root}/src/app/common:ids", + "${chip_root}/src/lib/core", + "${chip_root}/src/lib/support", + ] + + if (chip_code_pre_generated_directory == "") { + deps += [ ":${_data_model_name}_zapgen_generate" ] + } + } + } + source_set(_data_model_name) { forward_variables_from(invoker, "*", diff --git a/src/app/util/privilege-constants.h b/src/app/util/privilege-constants.h new file mode 100644 index 00000000000000..a9f56b509ca4cc --- /dev/null +++ b/src/app/util/privilege-constants.h @@ -0,0 +1,23 @@ +/** + * + * Copyright (c) 2024 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +inline constexpr int kMatterAccessPrivilegeView = 0; +inline constexpr int kMatterAccessPrivilegeOperate = 1; +inline constexpr int kMatterAccessPrivilegeManage = 2; +inline constexpr int kMatterAccessPrivilegeAdminister = 3; +inline constexpr int kMatterAccessPrivilegeMaxValue = kMatterAccessPrivilegeAdminister; diff --git a/src/app/util/privilege-storage.h b/src/app/util/privilege-storage.h index 02d55488fd0780..6222d891b9c92a 100644 --- a/src/app/util/privilege-storage.h +++ b/src/app/util/privilege-storage.h @@ -16,14 +16,9 @@ */ #pragma once +#include #include -inline constexpr int kMatterAccessPrivilegeView = 0; -inline constexpr int kMatterAccessPrivilegeOperate = 1; -inline constexpr int kMatterAccessPrivilegeManage = 2; -inline constexpr int kMatterAccessPrivilegeAdminister = 3; -inline constexpr int kMatterAccessPrivilegeMaxValue = kMatterAccessPrivilegeAdminister; - int MatterGetAccessPrivilegeForReadAttribute(chip::ClusterId cluster, chip::AttributeId attribute); int MatterGetAccessPrivilegeForWriteAttribute(chip::ClusterId cluster, chip::AttributeId attribute); int MatterGetAccessPrivilegeForInvokeCommand(chip::ClusterId cluster, chip::CommandId command); diff --git a/src/app/zap-templates/templates/app/access.zapt b/src/app/zap-templates/templates/app/access.zapt index 483de62bce4c60..96ad5f54ae5075 100644 --- a/src/app/zap-templates/templates/app/access.zapt +++ b/src/app/zap-templates/templates/app/access.zapt @@ -3,7 +3,7 @@ // Prevent multiple inclusion #pragma once -#include +#include // Prevent changing generated format // clang-format off