8c42fb16d5a8849d7f6e7a7e64505eb55ec6c485
[platform/upstream/connectedhomeip.git] / src / controller / python / BUILD.gn
1 # Copyright (c) 2020 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/build.gni")
16 import("//build_overrides/chip.gni")
17 import("//build_overrides/pigweed.gni")
18
19 import("$dir_pw_build/python.gni")
20
21 import("${chip_root}/build/chip/tools.gni")
22 import("${chip_root}/src/platform/device.gni")
23 import("${dir_pw_unit_test}/test.gni")
24
25 if (current_os == "mac") {
26   import("${build_root}/config/mac/mac_sdk.gni")
27 }
28
29 config("controller_wno_deprecate") {
30   cflags = [ "-Wno-deprecated-declarations" ]
31 }
32
33 config("includes") {
34   include_dirs =
35       [ "${chip_root}/src/controller/CHIPDeviceController_deprecated.h" ]
36 }
37
38 shared_library("ChipDeviceCtrl") {
39   output_name = "_ChipDeviceCtrl"
40   output_dir = "${target_out_dir}/chip"
41   include_dirs = [ "." ]
42
43   sources = [
44     "ChipDeviceController-ClusterCommands.cpp",
45     "ChipDeviceController-ScriptBinding.cpp",
46     "ChipDeviceController-ScriptDeviceAddressUpdateDelegate.cpp",
47     "ChipDeviceController-ScriptDeviceAddressUpdateDelegate.h",
48     "ChipDeviceController-ScriptDevicePairingDelegate.cpp",
49     "ChipDeviceController-ScriptDevicePairingDelegate.h",
50     "ChipDeviceController-StorageDelegate.cpp",
51     "ChipDeviceController-StorageDelegate.h",
52     "chip/internal/ChipThreadWork.cpp",
53     "chip/internal/ChipThreadWork.h",
54     "chip/internal/CommissionerImpl.cpp",
55     "chip/logging/LoggingRedirect.cpp",
56     "chip/native/StackInit.cpp",
57   ]
58
59   if (chip_enable_ble) {
60     if (current_os == "linux") {
61       sources += [ "chip/ble/LinuxImpl.cpp" ]
62     } else if (current_os == "mac") {
63       sources += [
64         "chip/ble/darwin/AdapterListing.mm",
65         "chip/ble/darwin/Scanning.mm",
66       ]
67     } else {
68       assert(false, "No BLE implementation available for the current OS.")
69     }
70   }
71
72   public_deps = [
73     "${chip_root}/src/app",
74     "${chip_root}/src/controller",
75     "${chip_root}/src/lib",
76     "${chip_root}/src/lib/core",
77     "${chip_root}/src/lib/support",
78     "${chip_root}/src/platform",
79     "${chip_root}/src/transport",
80   ]
81   allow_circular_includes_from = [ "${chip_root}/src/controller" ]
82   configs += [ ":controller_wno_deprecate" ]
83 }
84
85 pw_python_action("python") {
86   script = "build-chip-wheel.py"
87
88   _py_manifest_files = [
89     {
90       src_dir = "."
91       sources = [
92         "chip-device-ctrl.py",
93         "chip-repl.py",
94         "chip/ChipBleBase.py",
95         "chip/ChipBleUtility.py",
96         "chip/ChipBluezMgr.py",
97         "chip/ChipCluster.py",
98         "chip/ChipCoreBluetoothMgr.py",
99         "chip/ChipDeviceCtrl.py",
100         "chip/ChipStack.py",
101         "chip/ChipUtility.py",
102         "chip/__init__.py",
103         "chip/configuration/__init__.py",
104         "chip/exceptions/__init__.py",
105         "chip/internal/__init__.py",
106         "chip/internal/commissioner.py",
107         "chip/internal/thread.py",
108         "chip/internal/types.py",
109         "chip/logging/__init__.py",
110         "chip/logging/library_handle.py",
111         "chip/logging/types.py",
112         "chip/native/__init__.py",
113         "chip/tlv/__init__.py",
114       ]
115     },
116     {
117       src_dir = target_out_dir
118       sources = [ "${target_out_dir}/chip/_ChipDeviceCtrl.so" ]
119     },
120     {
121       src_dir = "//"
122       sources = [ "//LICENSE" ]
123     },
124   ]
125
126   if (chip_enable_ble) {
127     _py_manifest_files += [
128       {
129         src_dir = "."
130         sources = [
131           "chip/ble/__init__.py",
132           "chip/ble/commissioning/__init__.py",
133           "chip/ble/get_adapters.py",
134           "chip/ble/library_handle.py",
135           "chip/ble/scan_devices.py",
136           "chip/ble/types.py",
137         ]
138       },
139     ]
140   }
141
142   _py_manifest_file = "${target_gen_dir}/${target_name}.py_manifest.json"
143
144   inputs = []
145   _py_manifest_files_rebased = []
146   foreach(_manifest_entry, _py_manifest_files) {
147     inputs += _manifest_entry.sources
148     _py_manifest_files_rebased += [
149       {
150         src_dir = rebase_path(_manifest_entry.src_dir,
151                               get_path_info(_py_manifest_file, "dir"))
152         sources = rebase_path(_manifest_entry.sources, _manifest_entry.src_dir)
153       },
154     ]
155   }
156
157   _py_manifest = {
158     files = _py_manifest_files_rebased
159   }
160
161   write_file(_py_manifest_file, _py_manifest, "json")
162
163   _dist_dir = "${root_out_dir}/controller/python"
164
165   if (current_cpu == "x64") {
166     cpu_tag = "x86_64"
167   } else if (current_cpu == "arm64") {
168     cpu_tag = "aarch64"
169   } else {
170     cpu_tag = current_cpu
171   }
172
173   if (current_os == "mac") {
174     platform_tag = "macosx_" + string_replace(mac_deployment_target, ".", "_")
175   } else {
176     platform_tag = current_os
177   }
178
179   platform_tag = platform_tag + "_" + cpu_tag
180
181   tags = "cp37-abi3-" + platform_tag
182
183   args = [
184     "--package_name",
185     "chip",
186     "--build_number",
187     "0.0",
188     "--build_dir",
189     rebase_path("${target_gen_dir}/${target_name}.py_build", root_build_dir),
190     "--dist_dir",
191     rebase_path(_dist_dir, root_build_dir),
192     "--manifest",
193     rebase_path(_py_manifest_file, root_build_dir),
194     "--plat-name",
195     platform_tag,
196   ]
197
198   public_deps = [ ":ChipDeviceCtrl" ]
199
200   output_name = "chip-0.0-${tags}.whl"
201   outputs = [ "${_dist_dir}/$output_name" ]
202 }