Skip to content

Commit

Permalink
Define explicit data_model sub-targets for generated files (#32343)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
2 people authored and pull[bot] committed Apr 24, 2024
1 parent d4e4bbb commit 1766740
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 13 deletions.
8 changes: 4 additions & 4 deletions build/chip/chip_codegen.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -99,7 +99,7 @@ template("_chip_build_time_codegen") {
if (!defined(deps)) {
deps = []
}
deps += [ ":${_name}_codegen" ]
deps += [ ":${_name}_generate" ]
}
}

Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -211,7 +211,7 @@ template("_chip_build_time_zapgen") {
if (!defined(public_deps)) {
public_deps = []
}
public_deps += [ ":${_name}_zap" ]
public_deps += [ ":${_name}_generate" ]
}
}

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

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

// Prevent changing generated format
// clang-format off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// Prevent multiple inclusion
#pragma once

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

// Prevent changing generated format
// clang-format off
Expand Down
1 change: 1 addition & 0 deletions src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down
93 changes: 93 additions & 0 deletions src/app/chip_data_model.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
"*",
Expand Down
23 changes: 23 additions & 0 deletions src/app/util/privilege-constants.h
Original file line number Diff line number Diff line change
@@ -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;
7 changes: 1 addition & 6 deletions src/app/util/privilege-storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@
*/
#pragma once

#include <app/util/privilege-constants.h>
#include <lib/core/DataModelTypes.h>

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);
Expand Down
2 changes: 1 addition & 1 deletion src/app/zap-templates/templates/app/access.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Prevent multiple inclusion
#pragma once

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

// Prevent changing generated format
// clang-format off
Expand Down

0 comments on commit 1766740

Please sign in to comment.