-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compile time code generation - add relevant code to all example build…
…s (plus one sample codegen moved) (#23247) * Compile time code generation. Picked PluginApplicationCallbacks because it is simple and added it to a compile-time generated list. The main exercise for this is to make sure we can inject the appropriate calls to compile time generation to all examples. It is not yet perfect as it only involves include directories, however it does a "if it compiles it works, otherwise it fails to compile" approach. Uses codegen.py rather than ZAP for this particular file. For other files, we may chose to use ZAP however for that we have to: - ensure it is stand-alone runnable (likely as an installable app) - figure out any multi-processing conflicts as cmake/gn WILL run build steps in parallel and zap shares a common DB. * Remove PluginApplicationCallbacks.zapt * Restyle * Add idl to build instructions * Disable pylint for now. It looks like pylint is a lot more strict than expected and this was triggered only if we have dependencies * Ensure we run codegen so sanitizer can find generated files * Revert telink changes after master merge: no need for separate codegen anymore as telink now uses standard data model methods * Ensure all needed codegen is done (for clang tidy at least). Tested in linux, may need to adjust darwin * Code review comment: centralize the generator/string for known generators * Undo undesired file creation * Adjust the run_codegen_targets a bit * Undo shellharden: it breaks the script * Add exception on shellharden on run_codegen_targets * Fix clang tidy location for darwin: it uses out/default not out/sanitizers * Add a server cluster to the several_clusters unit test, to validate that we generate server callbacks to * Make bridge generate ONLY client clusters as it reuses the same name of generation * Separate client and server headers for bridge codegen * Resolve bridge: clients have default names, Server headers are separate. This is until we figure out real names * Fix build rules * Do not lint test matter files for spec compliance * Github runners do not use bash by default. Make the conditionals different for lint skipping * Fix operator for lint exception check * Undo typo
- Loading branch information
Showing
84 changed files
with
548 additions
and
2,301 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Run chip code generation. | ||
# | ||
# Example usage: | ||
# chip_codegen("app" | ||
# INPUT "some_file.matter" | ||
# GENERATOR "bridge" | ||
# OUTPUTS | ||
# "bridge/OnOff.h" | ||
# "bridge/LevelControl.h" | ||
# "bridge/Switch.h" | ||
# # ... more outputs | ||
# OUTPUT_PATH DIR_NAME_VAR | ||
# OUTPUT_FILES FILE_NAMES_VAR | ||
# ) | ||
# | ||
# Arguments: | ||
# INPUT - the name of the ".matter" file to use for generation | ||
# GENERATOR - generator to use for codegen.py | ||
# OUTPUTS - EXPECTED output names. MUST match actual outputs | ||
# | ||
# OUTPUT_PATH - [OUT] output variable will contain the directory where the | ||
# files will be generated | ||
# OUTPUT_FILES - [OUT] output variable will contain the path of generated files. | ||
# suitable to be added within a build target | ||
# | ||
function(chip_codegen TARGET_NAME) | ||
cmake_parse_arguments(ARG | ||
"" | ||
"INPUT;GENERATOR;OUTPUT_PATH;OUTPUT_FILES" | ||
"OUTPUTS" | ||
${ARGN} | ||
) | ||
|
||
set(GEN_FOLDER "${CMAKE_BINARY_DIR}/gen/${TARGET_NAME}/${ARG_GENERATOR}") | ||
|
||
string(REPLACE ";" "\n" OUTPUT_AS_NEWLINES "${ARG_OUTPUTS}") | ||
|
||
file(MAKE_DIRECTORY "${GEN_FOLDER}") | ||
file(GENERATE | ||
OUTPUT "${GEN_FOLDER}/expected.outputs" | ||
CONTENT "${OUTPUT_AS_NEWLINES}" | ||
) | ||
|
||
|
||
set(OUT_NAMES) | ||
foreach(NAME IN LISTS ARG_OUTPUTS) | ||
list(APPEND OUT_NAMES "${GEN_FOLDER}/${NAME}") | ||
endforeach() | ||
|
||
# Python is expected to be in the path | ||
# | ||
# find_package(Python3 REQUIRED) | ||
add_custom_command( | ||
OUTPUT "${OUT_NAMES}" | ||
COMMAND "${CHIP_ROOT}/scripts/codegen.py" | ||
ARGS "--generator" "${ARG_GENERATOR}" | ||
"--output-dir" "${GEN_FOLDER}" | ||
"--expected-outputs" "${GEN_FOLDER}/expected.outputs" | ||
"${ARG_INPUT}" | ||
DEPENDS | ||
"${ARG_INPUT}" | ||
VERBATIM | ||
) | ||
|
||
add_custom_target(${TARGET_NAME} DEPENDS "${OUT_NAMES}") | ||
|
||
# Forward outputs to the parent | ||
set(${ARG_OUTPUT_FILES} "${OUT_NAMES}" PARENT_SCOPE) | ||
set(${ARG_OUTPUT_PATH} "${GEN_FOLDER}" PARENT_SCOPE) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# | ||
# Copyright (c) 2022 Project CHIP Authors | ||
# All rights reserved. | ||
# | ||
# 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. | ||
# | ||
|
||
|
||
|
||
macro(chip_app_component_codegen IDL_NAME) | ||
include("${CHIP_ROOT}/build/chip/chip_codegen.cmake") | ||
|
||
# The IDF build system performs a two-pass expansion to determine | ||
# component expansion. The first pass runs in script-mode | ||
# to determine idf_component_register REQUIRES and PRIV_REQUIRES. | ||
# | ||
# We can only set up code generation during the 2nd pass | ||
# | ||
# see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html | ||
if (NOT CMAKE_BUILD_EARLY_EXPANSION) | ||
|
||
chip_codegen(app-codegen | ||
INPUT "${IDL_NAME}" | ||
GENERATOR "cpp-app" | ||
OUTPUTS | ||
"app/PluginApplicationCallbacks.h" | ||
OUTPUT_PATH APP_GEN_DIR | ||
OUTPUT_FILES APP_GEN_FILES | ||
) | ||
|
||
target_include_directories(${COMPONENT_LIB} PUBLIC "${APP_GEN_DIR}") | ||
|
||
add_dependencies(${COMPONENT_LIB} app-codegen) | ||
endif() | ||
endmacro() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.