Skip to content

Commit 4ec2035

Browse files
authored
Python wheels: move template into its own gni (#33739)
This will let us re-use the template later for wheels not in src/controller/python. Nothing within the template has been changed - this is just a move. Test: ran build_python.sh, it's fine still.
1 parent e445e8a commit 4ec2035

File tree

2 files changed

+89
-69
lines changed

2 files changed

+89
-69
lines changed

build/chip/python_wheel.gni

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Copyright (c) 2024 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://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,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/chip.gni")
16+
import("//build_overrides/pigweed.gni")
17+
18+
import("$dir_pw_build/python.gni")
19+
import("${chip_root}/src/system/system.gni")
20+
21+
declare_args() {
22+
chip_python_version = "0.0"
23+
chip_python_package_prefix = "chip"
24+
chip_python_supports_stack_locking = chip_system_config_locking != "none"
25+
}
26+
27+
template("chip_python_wheel_action") {
28+
_dist_dir = "${root_out_dir}/controller/python"
29+
30+
_py_manifest_file = "${target_gen_dir}/${target_name}.py_manifest.json"
31+
32+
pw_python_action(target_name) {
33+
script = "build-chip-wheel.py"
34+
forward_variables_from(invoker, "*")
35+
36+
_py_manifest_files_rebased = []
37+
foreach(_manifest_entry, py_manifest_files) {
38+
inputs += _manifest_entry.sources
39+
_py_manifest_files_rebased += [
40+
{
41+
src_dir = rebase_path(_manifest_entry.src_dir,
42+
get_path_info(_py_manifest_file, "dir"))
43+
sources =
44+
rebase_path(_manifest_entry.sources, _manifest_entry.src_dir)
45+
},
46+
]
47+
}
48+
49+
if (defined(invoker.py_scripts)) {
50+
_py_scripts = invoker.py_scripts
51+
} else {
52+
_py_scripts = []
53+
}
54+
55+
_py_manifest = {
56+
files = _py_manifest_files_rebased
57+
packages = py_packages
58+
scripts = _py_scripts
59+
package_reqs = py_package_reqs
60+
}
61+
62+
write_file(_py_manifest_file, _py_manifest, "json")
63+
64+
args = [
65+
"--package_name",
66+
py_package_name,
67+
"--build_number",
68+
chip_python_version,
69+
"--build_dir",
70+
rebase_path("${target_gen_dir}/${target_name}.py_build", root_build_dir),
71+
"--dist_dir",
72+
rebase_path(_dist_dir, root_build_dir),
73+
"--manifest",
74+
rebase_path(_py_manifest_file, root_build_dir),
75+
"--plat-name",
76+
py_platform_tag,
77+
]
78+
79+
if (defined(invoker.lib_name)) {
80+
args += [
81+
"--lib-name",
82+
lib_name,
83+
]
84+
}
85+
86+
outputs = [ "${_dist_dir}/$output_name" ]
87+
}
88+
}

src/controller/python/BUILD.gn

+1-69
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import("//build_overrides/pigweed.gni")
1818

1919
import("$dir_pw_build/python.gni")
2020

21+
import("${chip_root}/build/chip/python_wheel.gni")
2122
import("${chip_root}/build/chip/tools.gni")
2223
import("${chip_root}/src/platform/python.gni")
2324
import("${chip_root}/src/system/system.gni")
@@ -31,12 +32,6 @@ config("controller_wno_deprecate") {
3132
cflags = [ "-Wno-deprecated-declarations" ]
3233
}
3334

34-
declare_args() {
35-
chip_python_version = "0.0"
36-
chip_python_package_prefix = "chip"
37-
chip_python_supports_stack_locking = chip_system_config_locking != "none"
38-
}
39-
4035
shared_library("ChipDeviceCtrl") {
4136
if (chip_controller) {
4237
output_name = "_ChipDeviceCtrl"
@@ -157,69 +152,6 @@ shared_library("ChipDeviceCtrl") {
157152
configs += [ ":controller_wno_deprecate" ]
158153
}
159154

160-
template("chip_python_wheel_action") {
161-
_dist_dir = "${root_out_dir}/controller/python"
162-
163-
_py_manifest_file = "${target_gen_dir}/${target_name}.py_manifest.json"
164-
165-
pw_python_action(target_name) {
166-
script = "build-chip-wheel.py"
167-
forward_variables_from(invoker, "*")
168-
169-
_py_manifest_files_rebased = []
170-
foreach(_manifest_entry, py_manifest_files) {
171-
inputs += _manifest_entry.sources
172-
_py_manifest_files_rebased += [
173-
{
174-
src_dir = rebase_path(_manifest_entry.src_dir,
175-
get_path_info(_py_manifest_file, "dir"))
176-
sources =
177-
rebase_path(_manifest_entry.sources, _manifest_entry.src_dir)
178-
},
179-
]
180-
}
181-
182-
if (defined(invoker.py_scripts)) {
183-
_py_scripts = invoker.py_scripts
184-
} else {
185-
_py_scripts = []
186-
}
187-
188-
_py_manifest = {
189-
files = _py_manifest_files_rebased
190-
packages = py_packages
191-
scripts = _py_scripts
192-
package_reqs = py_package_reqs
193-
}
194-
195-
write_file(_py_manifest_file, _py_manifest, "json")
196-
197-
args = [
198-
"--package_name",
199-
py_package_name,
200-
"--build_number",
201-
chip_python_version,
202-
"--build_dir",
203-
rebase_path("${target_gen_dir}/${target_name}.py_build", root_build_dir),
204-
"--dist_dir",
205-
rebase_path(_dist_dir, root_build_dir),
206-
"--manifest",
207-
rebase_path(_py_manifest_file, root_build_dir),
208-
"--plat-name",
209-
py_platform_tag,
210-
]
211-
212-
if (defined(invoker.lib_name)) {
213-
args += [
214-
"--lib-name",
215-
lib_name,
216-
]
217-
}
218-
219-
outputs = [ "${_dist_dir}/$output_name" ]
220-
}
221-
}
222-
223155
chip_python_wheel_action("chip-core") {
224156
py_manifest_files = [
225157
{

0 commit comments

Comments
 (0)