Skip to content

Commit bdde9cf

Browse files
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 <andreilitvin@google.com>
1 parent e0b8a84 commit bdde9cf

File tree

8 files changed

+125
-13
lines changed

8 files changed

+125
-13
lines changed

build/chip/chip_codegen.gni

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ template("_chip_build_time_codegen") {
3535
include_dirs = [ target_gen_dir ]
3636
}
3737

38-
pw_python_action("${_name}_codegen") {
38+
pw_python_action("${_name}_generate") {
3939
script = "${chip_root}/scripts/codegen.py"
4040

4141
# TODO: this seems to touch internals. Is this ok? speeds up builds!
@@ -99,7 +99,7 @@ template("_chip_build_time_codegen") {
9999
if (!defined(deps)) {
100100
deps = []
101101
}
102-
deps += [ ":${_name}_codegen" ]
102+
deps += [ ":${_name}_generate" ]
103103
}
104104
}
105105

@@ -152,7 +152,7 @@ template("_chip_build_time_zapgen") {
152152
_output_subdir = "zap-generated"
153153
}
154154

155-
pw_python_action("${_name}_zap") {
155+
pw_python_action("${_name}_generate") {
156156
script = "${chip_root}/scripts/tools/zap/generate.py"
157157

158158
# TODO: this seems to touch internals. Is this ok? speeds up builds!
@@ -211,7 +211,7 @@ template("_chip_build_time_zapgen") {
211211
if (!defined(public_deps)) {
212212
public_deps = []
213213
}
214-
public_deps += [ ":${_name}_zap" ]
214+
public_deps += [ ":${_name}_generate" ]
215215
}
216216
}
217217

scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/access.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// Prevent multiple inclusion
2121
#pragma once
2222

23-
#include <app/util/privilege-storage.h>
23+
#include <app/util/privilege-constants.h>
2424

2525
// Prevent changing generated format
2626
// clang-format off

scripts/tools/zap/tests/outputs/lighting-app/app-templates/access.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// Prevent multiple inclusion
2121
#pragma once
2222

23-
#include <app/util/privilege-storage.h>
23+
#include <app/util/privilege-constants.h>
2424

2525
// Prevent changing generated format
2626
// clang-format off

src/app/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ static_library("interaction-model") {
229229
"dynamic_server/AccessControl.cpp",
230230
"dynamic_server/AccessControl.h",
231231
"dynamic_server/DynamicDispatcher.cpp",
232+
"util/privilege-constants.h",
232233
"util/privilege-storage.cpp",
233234
"util/privilege-storage.h",
234235
]

src/app/chip_data_model.gni

+93
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@ _app_root = get_path_info(".", "abspath")
3232
#
3333
# Forwards all the remaining variables to the source_set.
3434
#
35+
#
36+
#
37+
# Additional underlying source sets that will be provided
38+
#
39+
# - ${name}-endpoint-metadata
40+
# contains HEADERS that define endpoint metadata from zap/matter files:
41+
# - zap-generated/gen_config.h
42+
# - zap-generated/endpoint_config.h
43+
# - zap-generated/access.h
44+
# - PluginApplicationCallbacks.h
45+
# - ${name}-callbacks
46+
# contains the callback implementation for cluster init:
47+
# - cluster-init-callback.cpp
48+
# - callback-stub.cpp (contains __weak__ implementations. TODO: we should not be using
49+
# weak linkage over time at all)
50+
# - ${name}-command-dispatch:
51+
# contains the implementation of `DispatchServerCommand` which forwards data to
52+
# `emberAf....Cluster...Callback` callbacks
53+
# - zap-generated/IMClusterCommandHandler.cpp
54+
#
3555
template("chip_data_model") {
3656
_data_model_name = target_name
3757

@@ -87,6 +107,79 @@ template("chip_data_model") {
87107
]
88108
}
89109

110+
# where generated files reside
111+
# TODO: where can this reside?
112+
if (chip_code_pre_generated_directory == "") {
113+
_zapgen_gen_dir = "${target_gen_dir}/zapgen"
114+
_codegen_gen_dir = "${target_gen_dir}"
115+
} else {
116+
# NOTE: if zap and matter file will reside in different locations
117+
# this path will change between zapgen and codegen
118+
_pregen_dir =
119+
chip_code_pre_generated_directory + "/" +
120+
string_replace(rebase_path(invoker.zap_file, chip_root), ".zap", "")
121+
122+
_zapgen_gen_dir = "${_pregen_dir}/zap/app-templates"
123+
_codegen_gen_dir = "${_pregen_dir}/codegen/cpp-app"
124+
}
125+
126+
# Fixed source sets for allowing reasonable dependencies on things:
127+
source_set("${_data_model_name}-endpoint-metadata") {
128+
sources = [
129+
"${_codegen_gen_dir}/app/PluginApplicationCallbacks.h",
130+
"${_zapgen_gen_dir}/zap-generated/access.h",
131+
"${_zapgen_gen_dir}/zap-generated/endpoint_config.h",
132+
"${_zapgen_gen_dir}/zap-generated/gen_config.h",
133+
]
134+
135+
deps = [ "${chip_root}/src/lib/core:chip_config_header" ]
136+
137+
if (chip_code_pre_generated_directory == "") {
138+
deps += [
139+
":${_data_model_name}_codegen_generate",
140+
":${_data_model_name}_zapgen_generate",
141+
]
142+
}
143+
}
144+
145+
source_set("${_data_model_name}-callbacks") {
146+
sources = [
147+
"${_codegen_gen_dir}/app/callback-stub.cpp",
148+
"${_codegen_gen_dir}/app/cluster-init-callback.cpp",
149+
]
150+
151+
deps = [
152+
"${chip_root}/src/app/common:ids",
153+
"${chip_root}/src/lib/support:span",
154+
"${chip_root}/src/protocols/interaction_model",
155+
]
156+
157+
if (chip_code_pre_generated_directory == "") {
158+
deps += [ ":${_data_model_name}_codegen_generate" ]
159+
}
160+
}
161+
162+
if (!chip_build_controller_dynamic_server) {
163+
source_set("${_data_model_name}-command-dispatch") {
164+
sources =
165+
[ "${_zapgen_gen_dir}/zap-generated/IMClusterCommandHandler.cpp" ]
166+
167+
deps = [
168+
"${chip_root}/src/app",
169+
"${chip_root}/src/app:interaction-model",
170+
"${chip_root}/src/app/common:cluster-objects",
171+
"${chip_root}/src/app/common:enums",
172+
"${chip_root}/src/app/common:ids",
173+
"${chip_root}/src/lib/core",
174+
"${chip_root}/src/lib/support",
175+
]
176+
177+
if (chip_code_pre_generated_directory == "") {
178+
deps += [ ":${_data_model_name}_zapgen_generate" ]
179+
}
180+
}
181+
}
182+
90183
source_set(_data_model_name) {
91184
forward_variables_from(invoker,
92185
"*",

src/app/util/privilege-constants.h

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#pragma once
18+
19+
inline constexpr int kMatterAccessPrivilegeView = 0;
20+
inline constexpr int kMatterAccessPrivilegeOperate = 1;
21+
inline constexpr int kMatterAccessPrivilegeManage = 2;
22+
inline constexpr int kMatterAccessPrivilegeAdminister = 3;
23+
inline constexpr int kMatterAccessPrivilegeMaxValue = kMatterAccessPrivilegeAdminister;

src/app/util/privilege-storage.h

+1-6
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@
1616
*/
1717
#pragma once
1818

19+
#include <app/util/privilege-constants.h>
1920
#include <lib/core/DataModelTypes.h>
2021

21-
inline constexpr int kMatterAccessPrivilegeView = 0;
22-
inline constexpr int kMatterAccessPrivilegeOperate = 1;
23-
inline constexpr int kMatterAccessPrivilegeManage = 2;
24-
inline constexpr int kMatterAccessPrivilegeAdminister = 3;
25-
inline constexpr int kMatterAccessPrivilegeMaxValue = kMatterAccessPrivilegeAdminister;
26-
2722
int MatterGetAccessPrivilegeForReadAttribute(chip::ClusterId cluster, chip::AttributeId attribute);
2823
int MatterGetAccessPrivilegeForWriteAttribute(chip::ClusterId cluster, chip::AttributeId attribute);
2924
int MatterGetAccessPrivilegeForInvokeCommand(chip::ClusterId cluster, chip::CommandId command);

src/app/zap-templates/templates/app/access.zapt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Prevent multiple inclusion
44
#pragma once
55

6-
#include <app/util/privilege-storage.h>
6+
#include <app/util/privilege-constants.h>
77

88
// Prevent changing generated format
99
// clang-format off

0 commit comments

Comments
 (0)