Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile time code generation - add relevant code to all example builds (plus one sample codegen moved) #23247

Merged
merged 27 commits into from
Oct 21, 2022
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
608aef8
Compile time code generation.
andy31415 Oct 18, 2022
1cae095
Remove PluginApplicationCallbacks.zapt
andy31415 Oct 18, 2022
6c2b5b0
Restyle
andy31415 Oct 18, 2022
7d49af5
Add idl to build instructions
andy31415 Oct 18, 2022
c410d7d
Disable pylint for now. It looks like pylint is a lot more strict tha…
andy31415 Oct 18, 2022
1aad352
Ensure we run codegen so sanitizer can find generated files
andy31415 Oct 18, 2022
2167e93
Merge branch 'master' into build_time_codegen
andy31415 Oct 19, 2022
98b1b5c
Merge branch 'master' into build_time_codegen
andy31415 Oct 19, 2022
e03c5fd
Merge branch 'master' into build_time_codegen
andy31415 Oct 19, 2022
bc5a25d
Revert telink changes after master merge: no need for separate codege…
andy31415 Oct 19, 2022
5527a0e
Ensure all needed codegen is done (for clang tidy at least). Tested i…
andy31415 Oct 19, 2022
24a36d1
Code review comment: centralize the generator/string for known genera…
andy31415 Oct 19, 2022
94722a7
Undo undesired file creation
andy31415 Oct 19, 2022
8fa2471
Adjust the run_codegen_targets a bit
andy31415 Oct 19, 2022
dd5a181
Undo shellharden: it breaks the script
andy31415 Oct 19, 2022
c07b25e
Add exception on shellharden on run_codegen_targets
andy31415 Oct 19, 2022
892e39a
Fix clang tidy location for darwin: it uses out/default not out/sanit…
andy31415 Oct 19, 2022
ae38dc4
Add a server cluster to the several_clusters unit test, to validate t…
andy31415 Oct 20, 2022
cf2deca
Make bridge generate ONLY client clusters as it reuses the same name …
andy31415 Oct 20, 2022
575fd5d
Separate client and server headers for bridge codegen
andy31415 Oct 20, 2022
34eddf4
Resolve bridge: clients have default names, Server headers are separa…
andy31415 Oct 20, 2022
a730f6e
Fix build rules
andy31415 Oct 20, 2022
1dbe889
Do not lint test matter files for spec compliance
andy31415 Oct 20, 2022
b1e8c77
Github runners do not use bash by default. Make the conditionals diff…
andy31415 Oct 20, 2022
209d0c9
Fix operator for lint exception check
andy31415 Oct 20, 2022
3568c88
Undo typo
andy31415 Oct 21, 2022
1198775
Merge branch 'master' into build_time_codegen
andy31415 Oct 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
andy31415 committed Oct 18, 2022
commit 608aef87f01566b9988eed0428a7fa15ec94f624
70 changes: 70 additions & 0 deletions build/chip/chip_codegen.cmake
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()
45 changes: 45 additions & 0 deletions build/chip/esp32/esp32_codegen.cmake
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()
8 changes: 6 additions & 2 deletions examples/all-clusters-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
# The list of src and include dirs must be in sync with that in all-clusters-app/esp32/main/component.mk
set(PRIV_INCLUDE_DIRS_LIST
@@ -137,6 +136,12 @@ idf_component_register(PRIV_INCLUDE_DIRS ${PRIV_INCLUDE_DIRS_LIST}
EXCLUDE_SRCS ${EXCLUDE_SRCS_LIST}
PRIV_REQUIRES ${PRIV_REQUIRES_LIST})

get_filename_component(CHIP_ROOT ${CMAKE_SOURCE_DIR}/third_party/connectedhomeip REALPATH)

include("${CHIP_ROOT}/build/chip/esp32/esp32_codegen.cmake")

chip_app_component_codegen("${CHIP_ROOT}/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter")

set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17)
target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H")
target_compile_options(${COMPONENT_LIB} PUBLIC
@@ -145,7 +150,6 @@ target_compile_options(${COMPONENT_LIB} PUBLIC

if (CONFIG_ENABLE_PW_RPC)

get_filename_component(CHIP_ROOT ${CMAKE_SOURCE_DIR}/third_party/connectedhomeip REALPATH)

set(PIGWEED_ROOT "${CHIP_ROOT}/third_party/pigweed/repo")
include(${PIGWEED_ROOT}/pw_build/pigweed.cmake)
8 changes: 6 additions & 2 deletions examples/all-clusters-minimal-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -128,6 +128,12 @@ idf_component_register(PRIV_INCLUDE_DIRS ${PRIV_INCLUDE_DIRS_LIST}
SRC_DIRS ${SRC_DIRS_LIST}
PRIV_REQUIRES ${PRIV_REQUIRES_LIST})

get_filename_component(CHIP_ROOT ${CMAKE_SOURCE_DIR}/third_party/connectedhomeip REALPATH)

include("${CHIP_ROOT}/build/chip/esp32/esp32_codegen.cmake")

chip_app_component_codegen("${CHIP_ROOT}/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter")

set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17)
target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H")
target_compile_options(${COMPONENT_LIB} PUBLIC
@@ -136,8 +142,6 @@ target_compile_options(${COMPONENT_LIB} PUBLIC

if (CONFIG_ENABLE_PW_RPC)

get_filename_component(CHIP_ROOT ${CMAKE_SOURCE_DIR}/third_party/connectedhomeip REALPATH)

set(PIGWEED_ROOT "${CHIP_ROOT}/third_party/pigweed/repo")
include(${PIGWEED_ROOT}/pw_build/pigweed.cmake)
include(${PIGWEED_ROOT}/pw_protobuf_compiler/proto.cmake)
6 changes: 6 additions & 0 deletions examples/bridge-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -54,6 +54,12 @@ idf_component_register(PRIV_INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/providers"
PRIV_REQUIRES chip QRCode bt)

get_filename_component(CHIP_ROOT ${CMAKE_SOURCE_DIR}/third_party/connectedhomeip REALPATH)

include("${CHIP_ROOT}/build/chip/esp32/esp32_codegen.cmake")

chip_app_component_codegen("${CHIP_ROOT}/examples/bridge-app/bridge-common/bridge-app.matter")

set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 14)
target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H")
target_compile_options(${COMPONENT_LIB} PUBLIC
7 changes: 4 additions & 3 deletions examples/chef/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_LIST_DIR}/../../../.. REALPATH)
get_filename_component(CHIP_ROOT ../third_party/connectedhomeip REALPATH)
get_filename_component(CHEF ${CMAKE_CURRENT_SOURCE_DIR}/../../ REALPATH)
get_filename_component(GEN_DIR ${CHEF}/out/${SAMPLE_NAME}/zap-generated REALPATH)

@@ -107,6 +107,9 @@ idf_component_register(PRIV_INCLUDE_DIRS
PRIV_REQUIRES chip nvs_flash bt console esp32_mbedtls QRCode tft screen-framework spidriver
SRC_DIRS ${SRC_DIRS_LIST})

include("${CHIP_ROOT}/build/chip/esp32/esp32_codegen.cmake")
chip_app_component_codegen("${CHEF}/devices/${SAMPLE_NAME}.matter")

set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17)
target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H")
target_compile_options(${COMPONENT_LIB} PUBLIC
@@ -115,8 +118,6 @@ target_compile_options(${COMPONENT_LIB} PUBLIC

if (CONFIG_ENABLE_PW_RPC)

get_filename_component(CHIP_ROOT ../third_party/connectedhomeip REALPATH)

set(PIGWEED_ROOT "${CHIP_ROOT}/third_party/pigweed/repo")
include(${PIGWEED_ROOT}/pw_build/pigweed.cmake)
include(${PIGWEED_ROOT}/pw_protobuf_compiler/proto.cmake)
2 changes: 2 additions & 0 deletions examples/dynamic-bridge-app/bridge-common/BUILD.gn
Original file line number Diff line number Diff line change
@@ -22,6 +22,8 @@ chip_data_model("dynamic-bridge-common") {

zap_pregenerated_dir =
"${chip_root}/zzz_generated/dynamic-bridge-app/zap-generated"


is_server = true

# TODO: the definition of DYNAMIC_ENDPOINT_COUNT needs find a common home!
7 changes: 6 additions & 1 deletion examples/light-switch-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -14,8 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
idf_component_register(PRIV_INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/light-switch-app"
"${CMAKE_CURRENT_LIST_DIR}/include"
@@ -61,6 +61,11 @@ idf_component_register(PRIV_INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/groups-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/group-key-mgmt-server"
PRIV_REQUIRES chip QRCode bt app_update)
get_filename_component(CHIP_ROOT ${CMAKE_SOURCE_DIR}/third_party/connectedhomeip REALPATH)

include("${CHIP_ROOT}/build/chip/esp32/esp32_codegen.cmake")

chip_app_component_codegen("${CHIP_ROOT}/examples/light-switch-app/light-switch-common/light-switch-app.matter")

set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17)
target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H")
15 changes: 15 additions & 0 deletions examples/light-switch-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -24,6 +24,19 @@ get_filename_component(GEN_DIR ${CHIP_ROOT}/zzz_generated/ REALPATH)

set(CONF_FILE ${CHIP_ROOT}/config/telink/app/zephyr.conf prj.conf)

include("${CHIP_ROOT}/build/chip/chip_codegen.cmake")

# TODO: this CMakeFile should use src/app/chip_data_model.cmake
# and then codegen would be inherited
chip_codegen(app-codegen
INPUT "${CHIP_ROOT}/examples/light-switch-app/light-switch-common/light-switch-app.matter"
GENERATOR "cpp-app"
OUTPUTS
"app/PluginApplicationCallbacks.h"
OUTPUT_PATH APP_GEN_DIR
OUTPUT_FILES APP_GEN_FILES
)

# Load NCS/Zephyr build system
list(APPEND ZEPHYR_EXTRA_MODULES ${CHIP_ROOT}/config/telink/chip-module)
find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
@@ -36,11 +49,13 @@ target_compile_options(app PRIVATE -fpermissive)

target_include_directories(app PRIVATE
include
${APP_GEN_DIR}
${GEN_DIR}/app-common
${GEN_DIR}/light-switch-app
${NLIO_ROOT}
${TELINK_COMMON}/util/include
${TELINK_COMMON}/app/include)
add_dependencies(app app-codegen)

add_definitions(
"-DCHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER=<lib/address_resolve/AddressResolve_DefaultImpl.h>"
8 changes: 7 additions & 1 deletion examples/lighting-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -17,12 +17,13 @@
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

set(PRIV_INCLUDE_DIRS_LIST
"${APP_GEN_DIR}"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/lighting-app"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/providers"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/lighting-app/lighting-common/include"
"${CMAKE_CURRENT_LIST_DIR}/include"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32"
)
)
set(SRC_DIRS_LIST
"${CMAKE_CURRENT_LIST_DIR}"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated/attributes"
@@ -90,6 +91,11 @@ endif (CONFIG_ENABLE_PW_RPC)
idf_component_register(PRIV_INCLUDE_DIRS ${PRIV_INCLUDE_DIRS_LIST}
SRC_DIRS ${SRC_DIRS_LIST}
PRIV_REQUIRES ${PRIV_REQUIRES_LIST})
get_filename_component(CHIP_ROOT ${CMAKE_SOURCE_DIR}/third_party/connectedhomeip REALPATH)

include("${CHIP_ROOT}/build/chip/esp32/esp32_codegen.cmake")

chip_app_component_codegen("${CHIP_ROOT}/examples/lighting-app/lighting-common/lighting-app.matter")

set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17)
target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H")
15 changes: 15 additions & 0 deletions examples/lighting-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -24,6 +24,19 @@ get_filename_component(GEN_DIR ${CHIP_ROOT}/zzz_generated/ REALPATH)

set(CONF_FILE ${CHIP_ROOT}/config/telink/app/zephyr.conf prj.conf)

include("${CHIP_ROOT}/build/chip/chip_codegen.cmake")

# TODO: this CMakeFile should use src/app/chip_data_model.cmake
# and then codegen would be inherited
chip_codegen(app-codegen
INPUT "${CHIP_ROOT}/examples/lighting-app/lighting-common/lighting-app.matter"
GENERATOR "cpp-app"
OUTPUTS
"app/PluginApplicationCallbacks.h"
OUTPUT_PATH APP_GEN_DIR
OUTPUT_FILES APP_GEN_FILES
)

# Load NCS/Zephyr build system
list(APPEND ZEPHYR_EXTRA_MODULES ${CHIP_ROOT}/config/telink/chip-module)
find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
@@ -36,11 +49,13 @@ target_compile_options(app PRIVATE -fpermissive)

target_include_directories(app PRIVATE
include
${APP_GEN_DIR}
${GEN_DIR}/app-common
${GEN_DIR}/lighting-app
${NLIO_ROOT}
${TELINK_COMMON}/util/include
${TELINK_COMMON}/app/include)
add_dependencies(app app-codegen)

add_definitions(
"-DCHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER=<lib/address_resolve/AddressResolve_DefaultImpl.h>"
13 changes: 11 additions & 2 deletions examples/lock-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

get_filename_component(CHIP_ROOT ${CMAKE_SOURCE_DIR}/third_party/connectedhomeip REALPATH)

if (CONFIG_ENABLE_PW_RPC)
idf_component_register(INCLUDE_DIRS
"${CMAKE_CURRENT_LIST_DIR}"
@@ -67,8 +69,7 @@ idf_component_register(INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/identify-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/groups-server"
PRIV_REQUIRES bt chip QRCode)

get_filename_component(CHIP_ROOT ${CMAKE_SOURCE_DIR}/third_party/connectedhomeip REALPATH)
add_dependencies(${COMPONENT_LIB} app-codegen)

set(PIGWEED_ROOT "${CHIP_ROOT}/third_party/pigweed/repo")
include(${PIGWEED_ROOT}/pw_build/pigweed.cmake)
@@ -186,10 +187,18 @@ idf_component_register(PRIV_INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/groups-server"
PRIV_REQUIRES chip QRCode bt)

add_dependencies(${COMPONENT_LIB} app-codegen)

set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17)
target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H")
target_compile_options(${COMPONENT_LIB} PUBLIC
"-DCHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER=<lib/address_resolve/AddressResolve_DefaultImpl.h>"
)

endif (CONFIG_ENABLE_PW_RPC)

get_filename_component(CHIP_ROOT ${CMAKE_SOURCE_DIR}/third_party/connectedhomeip REALPATH)

include("${CHIP_ROOT}/build/chip/esp32/esp32_codegen.cmake")

chip_app_component_codegen("${CHIP_ROOT}/examples/lock-app/lock-common/lock-app.matter")
6 changes: 5 additions & 1 deletion examples/ota-provider-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
#
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
idf_component_register(PRIV_INCLUDE_DIRS
idf_component_register(PRIV_INCLUDE_DIRS
"${CMAKE_CURRENT_LIST_DIR}/include"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/ota-provider-app/"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/ota-provider-app"
@@ -59,6 +59,10 @@ idf_component_register(PRIV_INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/ota-provider-app/ota-provider-common/BdxOtaSender.cpp"
PRIV_REQUIRES chip QRCode bt console spiffs)

get_filename_component(CHIP_ROOT ${CMAKE_SOURCE_DIR}/third_party/connectedhomeip REALPATH)
include("${CHIP_ROOT}/build/chip/esp32/esp32_codegen.cmake")
chip_app_component_codegen("${CHIP_ROOT}/examples/ota-provider-app/ota-provider-common/ota-provider-app.matter")

spiffs_create_partition_image(img_storage ${CMAKE_SOURCE_DIR}/spiffs_image FLASH_IN_PROJECT)
set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 14)
target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H")
8 changes: 6 additions & 2 deletions examples/ota-requestor-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@
#
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
get_filename_component(CHIP_ROOT ${CMAKE_SOURCE_DIR}/third_party/connectedhomeip REALPATH)

set(PRIV_INCLUDE_DIRS_LIST
"${CMAKE_CURRENT_LIST_DIR}/include"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src"
@@ -86,6 +88,9 @@ idf_component_register(PRIV_INCLUDE_DIRS ${PRIV_INCLUDE_DIRS_LIST}
SRC_DIRS ${SRC_DIRS_LIST}
PRIV_REQUIRES ${PRIV_REQUIRES_LIST})

include("${CHIP_ROOT}/build/chip/esp32/esp32_codegen.cmake")
chip_app_component_codegen("${CHIP_ROOT}/examples/ota-requestor-app/ota-requestor-common/ota-requestor-app.matter")

set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17)
target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H")
target_compile_options(${COMPONENT_LIB} PUBLIC
@@ -94,9 +99,8 @@ target_compile_options(${COMPONENT_LIB} PUBLIC

if (CONFIG_ENABLE_PW_RPC)

get_filename_component(CHIP_ROOT ${CMAKE_SOURCE_DIR}/third_party/connectedhomeip REALPATH)

set(PIGWEED_ROOT "${CHIP_ROOT}/third_party/pigweed/repo")
set(PIGWEED_ROOT "${cHIP_ROOT}/third_party/pigweed/repo")
include(${PIGWEED_ROOT}/pw_build/pigweed.cmake)
include(${PIGWEED_ROOT}/pw_protobuf_compiler/proto.cmake)
set(dir_pw_third_party_nanopb "${CHIP_ROOT}/third_party/nanopb/repo" CACHE STRING "" FORCE)
15 changes: 15 additions & 0 deletions examples/ota-requestor-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -24,6 +24,19 @@ get_filename_component(GEN_DIR ${CHIP_ROOT}/zzz_generated/ REALPATH)

set(CONF_FILE ${CHIP_ROOT}/config/telink/app/zephyr.conf prj.conf)

include("${CHIP_ROOT}/build/chip/chip_codegen.cmake")

# TODO: this CMakeFile should use src/app/chip_data_model.cmake
# and then codegen would be inherited
chip_codegen(app-codegen
INPUT "${CHIP_ROOT}/examples/ota-requestor-app/ota-requestor-common/ota-requestor-app.matter"
GENERATOR "cpp-app"
OUTPUTS
"app/PluginApplicationCallbacks.h"
OUTPUT_PATH APP_GEN_DIR
OUTPUT_FILES APP_GEN_FILES
)

# Load NCS/Zephyr build system
list(APPEND ZEPHYR_EXTRA_MODULES ${CHIP_ROOT}/config/telink/chip-module)
find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
@@ -36,11 +49,13 @@ target_compile_options(app PRIVATE -fpermissive)

target_include_directories(app PRIVATE
include
${APP_GEN_DIR}
${GEN_DIR}/app-common
${GEN_DIR}/ota-requestor-app
${NLIO_ROOT}
${TELINK_COMMON}/util/include
${TELINK_COMMON}/app/include)
add_dependencies(app app-codegen)

add_definitions(
"-DCHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER=<lib/address_resolve/AddressResolve_DefaultImpl.h>"
4 changes: 2 additions & 2 deletions examples/pigweed-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -14,15 +14,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

idf_component_register(INCLUDE_DIRS
idf_component_register(INCLUDE_DIRS
"${CMAKE_CURRENT_LIST_DIR}"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/pw_sys_io/public"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/common/pigweed"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/common/pigweed/esp32"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/lib/support"
"${IDF_PATH}/components/freertos/include/freertos"

SRC_DIRS
"${CMAKE_CURRENT_LIST_DIR}"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32"
Original file line number Diff line number Diff line change
@@ -15,7 +15,9 @@
# limitations under the License.
#
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

get_filename_component(CHIP_ROOT ${CMAKE_SOURCE_DIR}/third_party/connectedhomeip REALPATH)

set(PRIV_INCLUDE_DIRS_LIST
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/temperature-measurement-app/"
"${CMAKE_CURRENT_LIST_DIR}/include"
@@ -78,6 +80,9 @@ idf_component_register(PRIV_INCLUDE_DIRS ${PRIV_INCLUDE_DIRS_LIST}
SRC_DIRS ${SRC_DIRS_LIST}
PRIV_REQUIRES ${PRIV_REQUIRES_LIST})

include("${CHIP_ROOT}/build/chip/esp32/esp32_codegen.cmake")
chip_app_component_codegen("${CHIP_ROOT}/examples/temperature-measurement-app/esp32/main/temperature-measurement.matter")

set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17)
target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H")
target_compile_options(${COMPONENT_LIB} PUBLIC
@@ -86,8 +91,6 @@ target_compile_options(${COMPONENT_LIB} PUBLIC

if (CONFIG_ENABLE_PW_RPC)

get_filename_component(CHIP_ROOT ${CMAKE_SOURCE_DIR}/third_party/connectedhomeip REALPATH)

set(PIGWEED_ROOT "${CHIP_ROOT}/third_party/pigweed/repo")
include(${PIGWEED_ROOT}/pw_build/pigweed.cmake)
include(${PIGWEED_ROOT}/pw_protobuf_compiler/proto.cmake)
5 changes: 5 additions & 0 deletions scripts/codegen.py
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
from idl.generators import FileSystemGeneratorStorage, GeneratorStorage
from idl.generators.java import JavaGenerator
from idl.generators.bridge import BridgeGenerator
from idl.generators.cpp.application import CppApplicationGenerator


class CodeGeneratorTypes(enum.Enum):
@@ -39,12 +40,15 @@ class CodeGeneratorTypes(enum.Enum):
"""
JAVA = enum.auto()
BRIDGE = enum.auto()
CPP_APPLICATION = enum.auto()

def CreateGenerator(self, *args, **kargs):
if self == CodeGeneratorTypes.JAVA:
return JavaGenerator(*args, **kargs)
elif self == CodeGeneratorTypes.BRIDGE:
return BridgeGenerator(*args, **kargs)
elif self == CodeGeneratorTypes.CPP_APPLICATION:
return CppApplicationGenerator(*args, **kargs)
else:
raise Error("Unknown code generator type")

@@ -76,6 +80,7 @@ def write_new_data(self, relative_path: str, content: str):
__GENERATORS__ = {
'java': CodeGeneratorTypes.JAVA,
'bridge': CodeGeneratorTypes.BRIDGE,
'cpp-app': CodeGeneratorTypes.CPP_APPLICATION,
}


Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <app-common/zap-generated/callbacks/PluginCallbacks.h>

#define MATTER_PLUGINS_INIT \
{%- for cluster in clusters | sort(attribute='name') %}
Matter{{ cluster.name }}Plugin{{ cluster.side | clusterSideString }}InitCallback();{{ " \\" if not loop.last else ""}}
{%- endfor %}

61 changes: 61 additions & 0 deletions scripts/idl/generators/cpp/application/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright (c) 2022 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.

from idl.generators import CodeGenerator, GeneratorStorage
from idl.matter_idl_types import Idl, ClusterSide, Field, Attribute, Cluster, FieldQuality, Command, DataType
from idl import matter_idl_types
from idl.generators.types import ParseDataType, BasicString, BasicInteger, FundamentalType, IdlType, IdlEnumType, IdlBitmapType, TypeLookupContext
from typing import Union, List, Set
from stringcase import capitalcase

import enum
import logging


def clusterSideString(side: ClusterSide):
if side == ClusterSide.CLIENT:
return "Client"
elif side == ClusterSide.SERVER:
return "Server"
else:
raise Exception("Unknown cluster side %r" % (side, ))


class CppApplicationGenerator(CodeGenerator):
"""
Generation of cpp code for application implementation for matter.
"""

def __init__(self, storage: GeneratorStorage, idl: Idl):
"""
Inintialization is specific for java generation and will add
filters as required by the java .jinja templates to function.
"""
super().__init__(storage, idl)

self.jinja_env.filters['clusterSideString'] = clusterSideString

def internal_render_all(self):
"""
Renders the cpp and header files required for applications
"""

# Header containing a macro to initialize all cluster plugins
self.internal_render_one_output(
template_path="cpp/application/PluginApplicationCallbacksHeader.jinja",
output_file_name="app/PluginApplicationCallbacks.h",
vars={
'clusters': self.idl.clusters,
}
)
5 changes: 4 additions & 1 deletion scripts/idl/test_generators.py
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@
from idl.matter_idl_types import Idl
from idl.generators.java import JavaGenerator
from idl.generators.bridge import BridgeGenerator
from idl.generators.cpp.application import CppApplicationGenerator
from idl.generators import GeneratorStorage


@@ -96,7 +97,7 @@ def write_new_data(self, relative_path: str, content: str):

# This will display actual diffs in the output files
self.checker.assertEqual(
self.get_existing_data(relative_path), content)
self.get_existing_data(relative_path), content, "Content of %s" % relative_path)

# Even if no diff, to be build system friendly, we do NOT expect any
# actual data writes.
@@ -119,6 +120,8 @@ def _create_generator(self, storage: GeneratorStorage, idl: Idl):
return JavaGenerator(storage, idl)
if self.generator_name.lower() == 'bridge':
return BridgeGenerator(storage, idl)
if self.generator_name.lower() == 'cpp-app':
return CppApplicationGenerator(storage, idl)
else:
raise Exception("Unknown generator for testing: %s",
self.generator_name.lower())
5 changes: 5 additions & 0 deletions scripts/idl/tests/available_tests.yaml
Original file line number Diff line number Diff line change
@@ -57,3 +57,8 @@ bridge:
bridge/First.h: outputs/several_clusters/bridge/First.h
bridge/Second.h: outputs/several_clusters/bridge/Second.h
bridge/Third.h: outputs/several_clusters/bridge/Third.h

cpp-app:
inputs/several_clusters.matter:
app/PluginApplicationCallbacks.h: outputs/several_clusters/cpp-app/PluginApplicationCallbacks.h

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <app-common/zap-generated/callbacks/PluginCallbacks.h>

#define MATTER_PLUGINS_INIT \
MatterFirstPluginClientInitCallback(); \
MatterSecondPluginClientInitCallback(); \
MatterThirdPluginClientInitCallback();

31 changes: 29 additions & 2 deletions src/app/chip_data_model.cmake
Original file line number Diff line number Diff line change
@@ -16,7 +16,15 @@

set(CHIP_APP_BASE_DIR ${CMAKE_CURRENT_LIST_DIR})

#
if (NOT CHIP_ROOT)
# TODO: these are WORKAROUNDS and should be removed
if(DEFINED ameba_matter_root)
SET(CHIP_ROOT "${ameba_matter_root}")
endif()
endif()

include("${CHIP_ROOT}/build/chip/chip_codegen.cmake")

# Configure ${APP_TARGET} with source files associated with ${CLUSTER} cluster
#
function(chip_configure_cluster APP_TARGET CLUSTER)
@@ -52,9 +60,11 @@ endfunction()
# INCLUDE_SERVER Include source files from src/app/server directory
# ZAP_FILE Path to the ZAP file, used to determine the list of clusters
# supported by the application.
# IDL .matter IDL file to use for codegen. Inferred from ZAP_FILE
# if not provided
#
function(chip_configure_data_model APP_TARGET)
cmake_parse_arguments(ARG "INCLUDE_SERVER" "ZAP_FILE;GEN_DIR" "" ${ARGN})
cmake_parse_arguments(ARG "INCLUDE_SERVER" "ZAP_FILE;GEN_DIR;IDL" "" ${ARGN})

if (ARG_INCLUDE_SERVER)
target_sources(${APP_TARGET} PRIVATE
@@ -72,6 +82,23 @@ function(chip_configure_data_model APP_TARGET)

if (ARG_ZAP_FILE)
chip_configure_zap_file(${APP_TARGET} ${ARG_ZAP_FILE})
if (NOT ARG_IDL)
string(REPLACE ".zap" ".matter" ARG_IDL ${ARG_ZAP_FILE})
endif()
endif()

if (ARG_IDL)
chip_codegen(${APP_TARGET}-codegen
INPUT "${ARG_IDL}"
GENERATOR "cpp-app"
OUTPUTS
"app/PluginApplicationCallbacks.h"
OUTPUT_PATH APP_GEN_DIR
OUTPUT_FILES APP_GEN_FILES
)

target_include_directories(${APP_TARGET} PRIVATE "${APP_GEN_DIR}")
add_dependencies(${APP_TARGET} ${APP_TARGET}-codegen)
endif()

target_sources(${APP_TARGET} PRIVATE
24 changes: 24 additions & 0 deletions src/app/chip_data_model.gni
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")
import("${chip_root}/build/chip/chip_codegen.gni")
import("${chip_root}/src/platform/python.gni")

import("${chip_root}/src/lib/core/core.gni")
@@ -31,11 +32,31 @@ _zap_cluster_list_script = get_path_info("zap_cluster_list.py", "abspath")
# zap_file
# Path to the ZAP input file.
#
# idl
# Path to the .matter IDL corresponding to the zap file. This is for
# dependencies on build-time code generation.
#
# Forwards all the remaining variables to the source_set.
#
template("chip_data_model") {
_data_model_name = target_name

if (defined(invoker.idl)) {
_idl = invoker.idl
} else {
# Assume that IDL name is the same as the zap file name, but instead of
# '.zap' use '.matter' as extension. This is currently the case in the
# sample apps, but may change in the future
print("AUTO-DETECTING input matter IDL file.")
_idl = string_replace(invoker.zap_file, ".zap", ".matter")
}

chip_codegen("${_data_model_name}_codegen") {
input = _idl
generator = "cpp-app"
outputs = [ "app/PluginApplicationCallbacks.h" ]
}

config("${_data_model_name}_config") {
include_dirs = []

@@ -60,6 +81,8 @@ template("chip_data_model") {
sources = []
}

sources += get_target_outputs(":${_data_model_name}_codegen")

sources += [
"${_app_root}/clusters/barrier-control-server/barrier-control-server.h",
"${_app_root}/clusters/basic/basic.h",
@@ -163,6 +186,7 @@ template("chip_data_model") {
}

public_deps += [
":${_data_model_name}_codegen",
"${chip_root}/src/app",
"${chip_root}/src/app/common:cluster-objects",
"${chip_root}/src/controller",
4 changes: 3 additions & 1 deletion src/app/util/util.cpp
Original file line number Diff line number Diff line change
@@ -25,7 +25,9 @@
#include <app/util/af-event.h>
#include <app/util/af.h>
#include <app/util/ember-compatibility-functions.h>
#include <zap-generated/PluginApplicationCallbacks.h>

// TODO: figure out a clear path for compile-time codegen
#include <app/PluginApplicationCallbacks.h>

#ifdef EMBER_AF_PLUGIN_GROUPS_SERVER
#include <app/clusters/groups-server/groups-server.h>
5 changes: 0 additions & 5 deletions src/app/zap-templates/app-templates.json
Original file line number Diff line number Diff line change
@@ -41,11 +41,6 @@
}
],
"templates": [
{
"path": "templates/app/callbacks/PluginApplicationCallbacks.zapt",
"name": "Matter Application Callbacks header",
"output": "PluginApplicationCallbacks.h"
},
{
"path": "templates/app/callback-stub-src.zapt",
"name": "ZCL callback-stub source",

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading