1# Copyright 2020 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14 15import("//build_overrides/pigweed.gni") 16 17import("$dir_pw_build/python.gni") 18import("$dir_pw_build/python_dist.gni") 19import("$dir_pw_build/python_gn_args.gni") 20import("$dir_pw_build/python_venv.gni") 21import("$dir_pw_docgen/docs.gni") 22import("$dir_pw_unit_test/test.gni") 23 24pw_doc_group("docs") { 25 sources = [ "docs.rst" ] 26} 27 28pw_python_group("core_pigweed_python_packages") { 29 python_deps = [ 30 "$dir_pw_allocator/py", 31 "$dir_pw_arduino_build/py", 32 "$dir_pw_bloat/py", 33 "$dir_pw_build/py", 34 "$dir_pw_build_info/py", 35 "$dir_pw_build_mcuxpresso/py", 36 "$dir_pw_chrono/py", 37 "$dir_pw_cli/py", 38 "$dir_pw_cli_analytics/py", 39 "$dir_pw_compilation_testing/py", 40 "$dir_pw_console/py", 41 "$dir_pw_containers/py", 42 "$dir_pw_cpu_exception_cortex_m/py", 43 "$dir_pw_cpu_exception_risc_v/py", 44 "$dir_pw_digital_io:protos.python", 45 "$dir_pw_docgen/py", 46 "$dir_pw_doctor/py", 47 "$dir_pw_emu/py", 48 "$dir_pw_env_setup/py", 49 "$dir_pw_env_setup_zephyr/py", 50 "$dir_pw_hdlc/py", 51 "$dir_pw_i2c:protos.python", 52 "$dir_pw_ide/py", 53 "$dir_pw_log:protos.python", 54 "$dir_pw_log/py", 55 "$dir_pw_log_rpc/py", 56 "$dir_pw_log_tokenized/py", 57 "$dir_pw_metric/py", 58 "$dir_pw_module/py", 59 "$dir_pw_package/py", 60 "$dir_pw_presubmit/py", 61 "$dir_pw_presubmit/py:pigweed_format", 62 "$dir_pw_protobuf/py", 63 "$dir_pw_protobuf_compiler/py", 64 "$dir_pw_rpc/py", 65 "$dir_pw_sensor/py", 66 "$dir_pw_snapshot/py:pw_snapshot", 67 "$dir_pw_snapshot/py:pw_snapshot_metadata", 68 "$dir_pw_software_update/py", 69 "$dir_pw_status/py", 70 "$dir_pw_stm32cube_build/py", 71 "$dir_pw_symbolizer/py", 72 "$dir_pw_system/py", 73 "$dir_pw_thread/py", 74 "$dir_pw_thread_freertos/py", 75 "$dir_pw_tls_client/py", 76 "$dir_pw_tokenizer/py", 77 "$dir_pw_toolchain/py", 78 "$dir_pw_trace/py", 79 "$dir_pw_trace_tokenized/py", 80 "$dir_pw_transfer/py", 81 "$dir_pw_unit_test/py", 82 "$dir_pw_watch/py", 83 ] 84} 85 86# Python packages for supporting specific targets. This includes flashing tools 87# and unit test runners. 88pw_python_group("pigweed_target_support_packages") { 89 python_deps = [ 90 "$dir_pigweed/targets/lm3s6965evb_qemu/py", 91 "$dir_pigweed/targets/rp2040/py", 92 "$dir_pigweed/targets/stm32f429i_disc1/py", 93 ] 94} 95 96pw_python_group("python") { 97 python_deps = [ 98 ":core_pigweed_python_packages", 99 100 # This target creates and installs Python package named 'pigweed' including 101 # every package listed in :core_pigweed_python_packages 102 ":pip_install_pigweed_package", 103 104 # Standalone scripts 105 # These targets are included here in order to ensure they are linted. 106 "$dir_pw_emu/py:mock_emu", 107 "$dir_pw_emu/py:mock_emu_frontend", 108 "$dir_pw_preprocessor/py:generate_apply_macros", 109 "$dir_pw_third_party/fuchsia:generate_fuchsia_patch", 110 "$dir_pw_third_party/nanopb:generate_nanopb_proto", 111 ] 112} 113 114# Default Python build venv to use if pw_build_PYTHON_BUILD_VENV is 115# not specified. 116pw_python_venv("pigweed_build_venv") { 117 path = "$root_build_dir/python-venv" 118 source_packages = [ ":core_pigweed_python_packages" ] 119} 120 121# Upstream only Python build venv that includes the target support 122# package dependencies. 123pw_python_venv("upstream_pigweed_build_venv") { 124 path = "$root_build_dir/python-venv" 125 source_packages = [ 126 ":core_pigweed_python_packages", 127 ":pigweed_target_support_packages", 128 ] 129} 130 131pw_python_group("target_support_packages") { 132 python_deps = [ ":pip_install_target_support_packages" ] 133} 134 135pw_python_pip_install("pip_install_target_support_packages") { 136 packages = [ ":target_support_package_distribution" ] 137} 138 139pw_python_distribution("target_support_package_distribution") { 140 packages = [ ":pigweed_target_support_packages" ] 141 generate_setup_cfg = { 142 name = "pigweed_target_support" 143 version = "0.0.1" 144 include_default_pyproject_file = true 145 append_date_to_version = true 146 } 147} 148 149# This target is responsible for building the Python source uploaded to PyPI: 150# https://pypi.org/project/pigweed/ 151pw_python_distribution("pypi_pigweed_python_source_tree") { 152 packages = [ ":core_pigweed_python_packages" ] 153 generate_setup_cfg = { 154 common_config_file = "pypi_common_setup.cfg" 155 } 156 extra_files = [ 157 "$dir_pigweed/LICENSE > LICENSE", 158 "$dir_pigweed/README.md > README.md", 159 "pypi_pyproject.toml > pyproject.toml", 160 ] 161} 162 163# This target is creates the 'pigweed' Python package installed to the user's 164# dev environment. It's similar to the source tree for PyPI but it appends the 165# current date to the version so pip will consider it more up to date than the 166# one in PyPI. 167# 168# To create this wheel run: 169# ninja -C out pigweed_pypi_distribution 170# The resulting wheel is available in 171# out/python/obj/pw_env_setup/generate_pigweed_python_package._build_wheel/ 172pw_python_distribution("generate_pigweed_python_package") { 173 packages = [ ":core_pigweed_python_packages" ] 174 175 generate_setup_cfg = { 176 common_config_file = "pypi_common_setup.cfg" 177 append_date_to_version = true 178 include_default_pyproject_file = true 179 } 180 extra_files = [ 181 "$dir_pigweed/LICENSE > LICENSE", 182 "$dir_pigweed/README.md > README.md", 183 ] 184} 185 186# This pip installs the generate_pigweed_python_package into the user venv. 187pw_python_pip_install("pip_install_pigweed_package") { 188 packages = [ ":generate_pigweed_python_package" ] 189} 190 191pw_python_group("hdlc_proto_rpc_python_packages") { 192 python_deps = [ 193 "$dir_pw_hdlc/py", 194 "$dir_pw_protobuf_compiler/py", 195 "$dir_pw_rpc/py", 196 "$dir_pw_tokenizer/py", 197 ] 198} 199 200# This target is not built by default but demonstrate how to generate 201# Python distributions with only a subset of Python packages 202# included. The result could be bundled into PyOxidizer or distributed 203# as a standalone Python wheel. 204# 205# To create this wheel run: 206# ninja -C out pigweed_pypi_distribution 207# The resulting wheel is available in 208# out/python/obj/pw_env_setup/generate_hdlc_proto_rpc_tokenizer_distribution._build_wheel/ 209pw_python_distribution("generate_hdlc_proto_rpc_tokenizer_distribution") { 210 packages = [ ":hdlc_proto_rpc_python_packages" ] 211 212 generate_setup_cfg = { 213 common_config_file = "pypi_common_setup.cfg" 214 append_date_to_version = true 215 include_default_pyproject_file = true 216 } 217 extra_files = [ 218 "$dir_pigweed/LICENSE > LICENSE", 219 "$dir_pigweed/README.md > README.md", 220 ] 221} 222 223if (current_toolchain != default_toolchain) { 224 pw_test_group("tests") { 225 } 226} 227 228pw_python_script("sample_project_action") { 229 sources = [ "sample_project_action/__init__.py" ] 230} 231