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_protobuf/py", 62 "$dir_pw_protobuf_compiler/py", 63 "$dir_pw_rpc/py", 64 "$dir_pw_sensor/py", 65 "$dir_pw_snapshot/py:pw_snapshot", 66 "$dir_pw_snapshot/py:pw_snapshot_metadata", 67 "$dir_pw_software_update/py", 68 "$dir_pw_status/py", 69 "$dir_pw_stm32cube_build/py", 70 "$dir_pw_symbolizer/py", 71 "$dir_pw_system/py", 72 "$dir_pw_thread/py", 73 "$dir_pw_thread_freertos/py", 74 "$dir_pw_tls_client/py", 75 "$dir_pw_tokenizer/py", 76 "$dir_pw_toolchain/py", 77 "$dir_pw_trace/py", 78 "$dir_pw_trace_tokenized/py", 79 "$dir_pw_transfer/py", 80 "$dir_pw_unit_test/py", 81 "$dir_pw_watch/py", 82 ] 83} 84 85# Python packages for supporting specific targets. This includes flashing tools 86# and unit test runners. 87pw_python_group("pigweed_target_support_packages") { 88 python_deps = [ 89 "$dir_pigweed/targets/lm3s6965evb_qemu/py", 90 "$dir_pigweed/targets/rp2040/py", 91 "$dir_pigweed/targets/stm32f429i_disc1/py", 92 ] 93} 94 95pw_python_group("python") { 96 python_deps = [ 97 ":core_pigweed_python_packages", 98 99 # This target creates and installs Python package named 'pigweed' including 100 # every package listed in :core_pigweed_python_packages 101 ":pip_install_pigweed_package", 102 103 # Standalone scripts 104 # These targets are included here in order to ensure they are linted. 105 "$dir_pw_emu/py:mock_emu", 106 "$dir_pw_emu/py:mock_emu_frontend", 107 "$dir_pw_preprocessor/py:generate_apply_macros", 108 "$dir_pw_third_party/fuchsia:generate_fuchsia_patch", 109 "$dir_pw_third_party/nanopb:generate_nanopb_proto", 110 ] 111} 112 113pw_python_venv("pigweed_build_venv") { 114 path = "$root_build_dir/python-venv" 115 source_packages = [ ":core_pigweed_python_packages" ] 116} 117 118pw_python_group("target_support_packages") { 119 python_deps = [ ":pip_install_target_support_packages" ] 120} 121 122pw_python_pip_install("pip_install_target_support_packages") { 123 packages = [ ":target_support_package_distribution" ] 124} 125 126pw_python_distribution("target_support_package_distribution") { 127 packages = [ ":pigweed_target_support_packages" ] 128 generate_setup_cfg = { 129 name = "pigweed_target_support" 130 version = "0.0.1" 131 include_default_pyproject_file = true 132 append_date_to_version = true 133 } 134} 135 136# This target is responsible for building the Python source uploaded to PyPI: 137# https://pypi.org/project/pigweed/ 138pw_python_distribution("pypi_pigweed_python_source_tree") { 139 packages = [ ":core_pigweed_python_packages" ] 140 generate_setup_cfg = { 141 common_config_file = "pypi_common_setup.cfg" 142 } 143 extra_files = [ 144 "$dir_pigweed/LICENSE > LICENSE", 145 "$dir_pigweed/README.md > README.md", 146 "pypi_pyproject.toml > pyproject.toml", 147 ] 148} 149 150# This target is creates the 'pigweed' Python package installed to the user's 151# dev environment. It's similar to the source tree for PyPI but it appends the 152# current date to the version so pip will consider it more up to date than the 153# one in PyPI. 154# 155# To create this wheel run: 156# ninja -C out pigweed_pypi_distribution 157# The resulting wheel is available in 158# out/python/obj/pw_env_setup/generate_pigweed_python_package._build_wheel/ 159pw_python_distribution("generate_pigweed_python_package") { 160 packages = [ ":core_pigweed_python_packages" ] 161 162 generate_setup_cfg = { 163 common_config_file = "pypi_common_setup.cfg" 164 append_date_to_version = true 165 include_default_pyproject_file = true 166 } 167 extra_files = [ 168 "$dir_pigweed/LICENSE > LICENSE", 169 "$dir_pigweed/README.md > README.md", 170 ] 171} 172 173# This pip installs the generate_pigweed_python_package into the user venv. 174pw_python_pip_install("pip_install_pigweed_package") { 175 packages = [ ":generate_pigweed_python_package" ] 176} 177 178pw_python_group("hdlc_proto_rpc_python_packages") { 179 python_deps = [ 180 "$dir_pw_hdlc/py", 181 "$dir_pw_protobuf_compiler/py", 182 "$dir_pw_rpc/py", 183 "$dir_pw_tokenizer/py", 184 ] 185} 186 187# This target is not built by default but demonstrate how to generate 188# Python distributions with only a subset of Python packages 189# included. The result could be bundled into PyOxidizer or distributed 190# as a standalone Python wheel. 191# 192# To create this wheel run: 193# ninja -C out pigweed_pypi_distribution 194# The resulting wheel is available in 195# out/python/obj/pw_env_setup/generate_hdlc_proto_rpc_tokenizer_distribution._build_wheel/ 196pw_python_distribution("generate_hdlc_proto_rpc_tokenizer_distribution") { 197 packages = [ ":hdlc_proto_rpc_python_packages" ] 198 199 generate_setup_cfg = { 200 common_config_file = "pypi_common_setup.cfg" 201 append_date_to_version = true 202 include_default_pyproject_file = true 203 } 204 extra_files = [ 205 "$dir_pigweed/LICENSE > LICENSE", 206 "$dir_pigweed/README.md > README.md", 207 ] 208} 209 210if (current_toolchain != default_toolchain) { 211 pw_test_group("tests") { 212 } 213} 214 215pw_python_script("sample_project_action") { 216 sources = [ "sample_project_action/__init__.py" ] 217} 218