diff --git a/examples/lighting-app/silabs/BUILD.gn b/examples/lighting-app/silabs/BUILD.gn index d6bd2144b7..8606a07d07 100644 --- a/examples/lighting-app/silabs/BUILD.gn +++ b/examples/lighting-app/silabs/BUILD.gn @@ -131,7 +131,6 @@ silabs_executable("lighting_app") { sources = [ "${examples_common_plat_dir}/main.cpp", "src/AppTask.cpp", - "src/CustomAppTask.cpp", "src/DataModelCallbacks.cpp", ] diff --git a/third_party/silabs/BUILD.gn b/third_party/silabs/BUILD.gn index 60621c8673..f24d9e9f13 100644 --- a/third_party/silabs/BUILD.gn +++ b/third_party/silabs/BUILD.gn @@ -54,6 +54,24 @@ group("silabs_sdk") { public_configs = [ ":silabs_config" ] } +# copy CustomAppTask template into build directory +_silabs_platform_dir = "${chip_root}/examples/platform/silabs" +action("ensure_custom_app_task") { + script = "ensure_local_custom_app_task.py" + args = [ + rebase_path(_silabs_platform_dir, root_build_dir), + rebase_path(root_build_dir, root_build_dir), + ] + inputs = [ + "${_silabs_platform_dir}/CustomAppTask.cpp", + "${_silabs_platform_dir}/CustomAppTask.h", + ] + outputs = [ + "${root_build_dir}/config/CustomAppTask.cpp", + "${root_build_dir}/config/CustomAppTask.h", + ] +} + if (chip_with_lwip) { group("lwip") { public_deps = [ "silabs_lwip:lwip" ] diff --git a/third_party/silabs/ensure_local_custom_app_task.py b/third_party/silabs/ensure_local_custom_app_task.py new file mode 100644 index 0000000000..4e1baabf78 --- /dev/null +++ b/third_party/silabs/ensure_local_custom_app_task.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2020 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use it 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. +# +# Copies CustomAppTask.cpp and CustomAppTask.h from the template + +import os +import shutil +import sys + + +def main(): + if len(sys.argv) != 3: + sys.stderr.write( + "usage: ensure_local_custom_app_task.py \n" + ) + sys.exit(1) + + base = os.getcwd() + platform_dir = os.path.normpath(os.path.abspath(os.path.join(base, sys.argv[1]))) + root_build_dir = os.path.normpath(os.path.abspath(os.path.join(base, sys.argv[2]))) + + template_cpp = os.path.join(platform_dir, "CustomAppTask.cpp") + template_h = os.path.join(platform_dir, "CustomAppTask.h") + build_config_dir = os.path.join(root_build_dir, "config") + dest_cpp = os.path.join(build_config_dir, "CustomAppTask.cpp") + dest_h = os.path.join(build_config_dir, "CustomAppTask.h") + + for path in (template_cpp, template_h): + if not os.path.isfile(path): + sys.stderr.write("template not found: %s\n" % path) + sys.exit(1) + + # Only copy when build dir does not have a copy + if os.path.isfile(dest_cpp): + return + + os.makedirs(build_config_dir, exist_ok=True) + shutil.copy2(template_cpp, dest_cpp) + shutil.copy2(template_h, dest_h) + + +if __name__ == "__main__": + main() diff --git a/third_party/silabs/silabs_executable.gni b/third_party/silabs/silabs_executable.gni index 37b853c5df..aeafe2cb25 100644 --- a/third_party/silabs/silabs_executable.gni +++ b/third_party/silabs/silabs_executable.gni @@ -14,9 +14,12 @@ import("//build_overrides/build.gni") import("//build_overrides/chip.gni") +import("//build_overrides/efr32_sdk.gni") import("${build_root}/toolchain/flashable_executable.gni") import("silabs_board.gni") +_custom_app_task_dep = "${silabs_sdk_build_root}:ensure_custom_app_task" + template("generate_rps_file") { forward_variables_from(invoker, [ @@ -103,10 +106,17 @@ template("silabs_executable") { ] flashbundle_name = "" # Stop flashable_executable from making flashbundle. + # copy CustomAppTask from template into build directory + _custom_app_task_gen_dir = "${root_build_dir}/config" + # Target to generate the s37 file, flashing script, and flashbundle. flash_target_name = target_name + ".flash_executable" flashable_executable(flash_target_name) { forward_variables_from(invoker, "*") + + sources += [ "${_custom_app_task_gen_dir}/CustomAppTask.cpp" ] + include_dirs += [ _custom_app_task_gen_dir ] + deps += [ _custom_app_task_dep ] } # Target to generate the hex file.