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