|  | # Copyright 2020 The Pigweed 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 | 
|  | # | 
|  | #     https://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. | 
|  |  | 
|  | import("//build_overrides/pigweed.gni") | 
|  |  | 
|  | import("$dir_pw_arduino_build/arduino.gni") | 
|  | import("$dir_pw_build/python.gni") | 
|  | import("$dir_pw_build/python_dist.gni") | 
|  | import("$dir_pw_build/python_venv.gni") | 
|  | import("$dir_pw_tokenizer/database.gni") | 
|  | import("$dir_pw_unit_test/test.gni") | 
|  |  | 
|  | # NOTE: All the `deps` listed in `//BUILD.gn` must either be instantiated with a | 
|  | # toolchain, e.g. `":my_host_target(//path/to/host:toolchain)"`, or listed | 
|  | # within an `if (current_toolchain != default_toolchain)` statement. | 
|  | # It also prevents the default toolchain from parsing any unnecessary BUILD.gn | 
|  | # files. | 
|  |  | 
|  | # Lists all the targets build by default with e.g. `ninja -C out`. | 
|  | group("default") { | 
|  | deps = [ | 
|  | ":arduino", | 
|  | ":docs", | 
|  | ":examples", | 
|  | ":host", | 
|  | ":python.lint", | 
|  | ":python.tests", | 
|  | ] | 
|  | } | 
|  |  | 
|  | group("docs") { | 
|  | deps = [ "//docs($dir_pigweed/targets/docs)" ] | 
|  | } | 
|  |  | 
|  | # Group all targets that run on host only, e.g. tests, utils. | 
|  | group("host") { | 
|  | deps = [ ":run_tests(//targets/host:host_debug_tests)" ] | 
|  | } | 
|  |  | 
|  | # Arduino specific targets. | 
|  | group("arduino") { | 
|  | # If the 'pw_arduino_build_CORE_PATH' build arg is defined assume an arduino | 
|  | # core is available for building. | 
|  | # | 
|  | # For example: | 
|  | #   pw_arduino_build_CORE_PATH="//third_party/pigweed/third_party/arduino/cores" | 
|  |  | 
|  | if (pw_arduino_build_CORE_PATH != "") { | 
|  | deps = [ ":run_tests(//targets/arduino:arduino_debug_tests)" ] | 
|  | } | 
|  | } | 
|  |  | 
|  | # stm32f429i_disc1 specific targets | 
|  | group("stm32f429i_disc1") { | 
|  | _default_toolchain = | 
|  | "//targets/stm32f429i_disc1_stm32cube:stm32f429i_disc1_debug" | 
|  | _testing_toolchain = "${_default_toolchain}_tests" | 
|  | deps = [ ":run_tests(${_testing_toolchain})" ] | 
|  | } | 
|  |  | 
|  | # In-tree Python packages | 
|  | _sample_project_python_packages = [ "//tools:tools" ] | 
|  |  | 
|  | # This group contains all the python packages that should be tested and linted. | 
|  | pw_python_group("python") { | 
|  | python_deps = _sample_project_python_packages | 
|  | } | 
|  |  | 
|  | # Pigweed Python packages to include | 
|  | _pigweed_python_packages = [ | 
|  | "$dir_pw_env_setup:core_pigweed_python_packages", | 
|  | "$dir_pigweed/targets/lm3s6965evb_qemu/py", | 
|  | "$dir_pigweed/targets/stm32f429i_disc1/py", | 
|  | ] | 
|  |  | 
|  | _all_python_packages = | 
|  | _sample_project_python_packages + _pigweed_python_packages | 
|  |  | 
|  | # The default venv for Python actions in GN | 
|  | # Set this gn arg in a declare_args block in this file 'BUILD.gn' or in '.gn' to | 
|  | # use this venv. | 
|  | # | 
|  | #   pw_build_PYTHON_BUILD_VENV = "//:sample_project_build_venv" | 
|  | # | 
|  | pw_python_venv("sample_project_build_venv") { | 
|  | path = "$root_build_dir/python-venv" | 
|  | constraints = pw_build_PIP_CONSTRAINTS | 
|  | requirements = pw_build_PIP_REQUIREMENTS | 
|  |  | 
|  | # Ensure all third party Python dependencies are installed into this venv. | 
|  | # This works by checking the setup.cfg files for all packages listed here and | 
|  | # installing the packages listed in the [options].install_requires field. | 
|  | source_packages = _all_python_packages | 
|  | } | 
|  |  | 
|  | # This template collects all python packages and their dependencies into a | 
|  | # single super Python package for installation into the bootstrapped virtual | 
|  | # environment. | 
|  | pw_python_distribution("sample_project_python_distribution") { | 
|  | packages = _all_python_packages | 
|  | generate_setup_cfg = { | 
|  | name = "sample-project-tools" | 
|  | version = "0.0.1" | 
|  | append_date_to_version = true | 
|  | include_default_pyproject_file = true | 
|  | } | 
|  | } | 
|  |  | 
|  | # Install the sample-project-tools super Python package into the bootstrapped | 
|  | # Python venv. | 
|  | pw_python_pip_install("pip_install_sample_project_tools") { | 
|  | packages = [ ":sample_project_python_distribution" ] | 
|  | } | 
|  |  | 
|  | group("examples") { | 
|  | deps = [] | 
|  |  | 
|  | # STMicroelectronics STM32F429I-DISC1 examples. | 
|  | deps += [ | 
|  | "//examples/01_blinky:blinky(//targets/stm32f429i_disc1_stm32cube:stm32f429i_disc1_stm32cube.size_optimized)", | 
|  | "//examples/02_unit_testing:test_runner_app(//targets/stm32f429i_disc1_stm32cube:stm32f429i_disc1_stm32cube.size_optimized)", | 
|  | "//examples/03_rpc:rpc_main(//targets/stm32f429i_disc1_stm32cube:stm32f429i_disc1_stm32cube.size_optimized)", | 
|  | ] | 
|  |  | 
|  | # Raspberry Pi Pico RP2040 examples. | 
|  | deps += [ | 
|  | "//examples/01_blinky:blinky(//targets/rp2040:rp2040.size_optimized)", | 
|  | "//examples/02_unit_testing:test_runner_app(//targets/rp2040:rp2040.size_optimized)", | 
|  | "//examples/03_rpc:rpc_main(//targets/rp2040:rp2040.size_optimized)", | 
|  | ] | 
|  |  | 
|  | # Host examples. | 
|  | deps += [ | 
|  | "//examples/01_blinky:blinky(//targets/host:host_device_simulator.speed_optimized)", | 
|  | "//examples/02_unit_testing:test_runner_app(//targets/host:host_device_simulator.speed_optimized)", | 
|  | "//examples/03_rpc:rpc_main(//targets/host:host_device_simulator.speed_optimized)", | 
|  | ] | 
|  | } | 
|  |  | 
|  | # TODO: b/301306292 - Removing this causes a duplicate toolchain to be | 
|  | # generated if any tests are present in the test group. Figure out why, and set | 
|  | # up a more scalable solution. | 
|  | if (current_toolchain != default_toolchain) { | 
|  | # All the tests that should run as part of the build. | 
|  | pw_test_group("tests") { | 
|  | group_deps = [ | 
|  | # Uncomment this to automatically run the example unit test. | 
|  | # "//examples/02_unit_testing:tests", | 
|  | ] | 
|  | } | 
|  |  | 
|  | group("run_tests") { | 
|  | if (pw_unit_test_AUTOMATIC_RUNNER == "") { | 
|  | # Without a test runner defined, build the tests but don't run them. | 
|  | deps = [ ":tests" ] | 
|  | } else { | 
|  | # With a test runner, build and run tests. | 
|  | deps = [ ":tests.run" ] | 
|  | } | 
|  | } | 
|  | } |