Apply Upstream code (2021-03-15)
[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/ble/__init__.py",
104         "chip/ble/commissioning/__init__.py",
105         "chip/ble/get_adapters.py",
106         "chip/ble/library_handle.py",
107         "chip/ble/scan_devices.py",
108         "chip/ble/types.py",
109         "chip/configuration/__init__.py",
110         "chip/exceptions/__init__.py",
111         "chip/internal/__init__.py",
112         "chip/internal/commissioner.py",
113         "chip/internal/thread.py",
114         "chip/internal/types.py",
115         "chip/logging/__init__.py",
116         "chip/logging/library_handle.py",
117         "chip/logging/types.py",
118         "chip/native/__init__.py",
119         "chip/tlv/__init__.py",
120       ]
121     },
122     {
123       src_dir = target_out_dir
124       sources = [ "${target_out_dir}/chip/_ChipDeviceCtrl.so" ]
125     },
126     {
127       src_dir = "//"
128       sources = [ "//LICENSE" ]
129     },
130   ]
131
132   _py_manifest_file = "${target_gen_dir}/${target_name}.py_manifest.json"
133
134   inputs = []
135   _py_manifest_files_rebased = []
136   foreach(_manifest_entry, _py_manifest_files) {
137     inputs += _manifest_entry.sources
138     _py_manifest_files_rebased += [
139       {
140         src_dir = rebase_path(_manifest_entry.src_dir,
141                               get_path_info(_py_manifest_file, "dir"))
142         sources = rebase_path(_manifest_entry.sources, _manifest_entry.src_dir)
143       },
144     ]
145   }
146
147   _py_manifest = {
148     files = _py_manifest_files_rebased
149   }
150
151   write_file(_py_manifest_file, _py_manifest, "json")
152
153   _dist_dir = "${root_out_dir}/controller/python"
154
155   if (current_cpu == "x64") {
156     cpu_tag = "x86_64"
157   } else if (current_cpu == "arm64") {
158     cpu_tag = "aarch64"
159   } else {
160     cpu_tag = current_cpu
161   }
162
163   if (current_os == "mac") {
164     platform_tag = "macosx_" + string_replace(mac_deployment_target, ".", "_")
165   } else {
166     platform_tag = current_os
167   }
168
169   platform_tag = platform_tag + "_" + cpu_tag
170
171   tags = "cp37-abi3-" + platform_tag
172
173   args = [
174     "--package_name",
175     "chip",
176     "--build_number",
177     "0.0",
178     "--build_dir",
179     rebase_path("${target_gen_dir}/${target_name}.py_build", root_build_dir),
180     "--dist_dir",
181     rebase_path(_dist_dir, root_build_dir),
182     "--manifest",
183     rebase_path(_py_manifest_file, root_build_dir),
184     "--plat-name",
185     platform_tag,
186   ]
187
188   public_deps = [ ":ChipDeviceCtrl" ]
189
190   output_name = "chip-0.0-${tags}.whl"
191   outputs = [ "${_dist_dir}/$output_name" ]
192 }