blob: af1bcd7fb2a8fd68d4e8b3d93b61e72bca015ebc [file] [log] [blame]
# Copyright (c) 2020 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")
import("//build_overrides/pigweed.gni")
import("$dir_pw_build/python.gni")
import("${chip_root}/build/chip/tools.gni")
import("${chip_root}/src/platform/python.gni")
import("${dir_pw_unit_test}/test.gni")
if (current_os == "mac") {
import("${build_root}/config/mac/mac_sdk.gni")
}
config("controller_wno_deprecate") {
cflags = [ "-Wno-deprecated-declarations" ]
}
chip_python_version = "0.0"
shared_library("ChipDeviceCtrl") {
if (chip_controller) {
output_name = "_ChipDeviceCtrl"
} else {
output_name = "_ChipServer"
}
output_dir = "${target_out_dir}/chip"
include_dirs = [ "." ]
sources = [
"chip/setup_payload/Generator.cpp",
"chip/setup_payload/Parser.cpp",
]
sources += [ "chip/native/CommonStackInit.cpp" ]
if (chip_controller) {
sources += [
"ChipCommissionableNodeController-ScriptBinding.cpp",
"ChipDeviceController-Discovery.cpp",
"ChipDeviceController-IssueNocChain.cpp",
"ChipDeviceController-ScriptBinding.cpp",
"ChipDeviceController-ScriptDevicePairingDelegate.cpp",
"ChipDeviceController-ScriptDevicePairingDelegate.h",
"ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.cpp",
"ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.h",
"ChipDeviceController-StorageDelegate.cpp",
"ChipDeviceController-StorageDelegate.h",
"OpCredsBinding.cpp",
"chip/clusters/attribute.cpp",
"chip/clusters/command.cpp",
"chip/discovery/NodeResolution.cpp",
"chip/interaction_model/Delegate.cpp",
"chip/interaction_model/Delegate.h",
"chip/internal/ChipThreadWork.cpp",
"chip/internal/ChipThreadWork.h",
"chip/internal/CommissionerImpl.cpp",
"chip/logging/LoggingRedirect.cpp",
"chip/native/PyChipError.cpp",
"chip/utils/DeviceProxyUtils.cpp",
]
} else {
sources += [
"chip/server/Options.cpp",
"chip/server/ServerInit.cpp",
]
}
if (chip_enable_ble) {
if (current_os == "linux") {
sources += [ "chip/ble/LinuxImpl.cpp" ]
} else if (current_os == "mac") {
sources += [
"chip/ble/darwin/AdapterListing.mm",
"chip/ble/darwin/Scanning.mm",
]
cflags = [ "-fobjc-arc" ]
} else {
assert(false, "No BLE implementation available for the current OS.")
}
}
public_deps = [
"${chip_root}/src/app",
"${chip_root}/src/app/server",
"${chip_root}/src/credentials:default_attestation_verifier",
"${chip_root}/src/lib",
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/dnssd",
"${chip_root}/src/lib/support",
"${chip_root}/src/platform",
"${chip_root}/src/setup_payload",
"${chip_root}/src/transport",
]
if (chip_controller) {
public_deps += [
"${chip_root}/src/controller/data_model",
"${chip_root}/src/credentials:file_attestation_trust_store",
"${chip_root}/third_party/jsoncpp",
]
} else {
public_deps += [ "$chip_data_model" ]
}
configs += [ ":controller_wno_deprecate" ]
}
template("chip_python_wheel_action") {
_dist_dir = "${root_out_dir}/controller/python"
_py_manifest_file = "${target_gen_dir}/${target_name}.py_manifest.json"
pw_python_action(target_name) {
script = "build-chip-wheel.py"
forward_variables_from(invoker, "*")
_py_manifest_files_rebased = []
foreach(_manifest_entry, py_manifest_files) {
inputs += _manifest_entry.sources
_py_manifest_files_rebased += [
{
src_dir = rebase_path(_manifest_entry.src_dir,
get_path_info(_py_manifest_file, "dir"))
sources =
rebase_path(_manifest_entry.sources, _manifest_entry.src_dir)
},
]
}
if (defined(invoker.py_scripts)) {
_py_scripts = invoker.py_scripts
} else {
_py_scripts = []
}
_py_manifest = {
files = _py_manifest_files_rebased
packages = py_packages
scripts = _py_scripts
package_reqs = py_package_reqs
}
write_file(_py_manifest_file, _py_manifest, "json")
args = [
"--package_name",
py_package_name,
"--build_number",
chip_python_version,
"--build_dir",
rebase_path("${target_gen_dir}/${target_name}.py_build", root_build_dir),
"--dist_dir",
rebase_path(_dist_dir, root_build_dir),
"--manifest",
rebase_path(_py_manifest_file, root_build_dir),
"--plat-name",
py_platform_tag,
]
if (defined(invoker.lib_name)) {
args += [
"--lib-name",
lib_name,
]
}
outputs = [ "${_dist_dir}/$output_name" ]
}
}
chip_python_wheel_action("chip-core") {
py_manifest_files = [
{
src_dir = "."
sources = [
"chip/CertificateAuthority.py",
"chip/ChipBleBase.py",
"chip/ChipBleUtility.py",
"chip/ChipBluezMgr.py",
"chip/ChipCommissionableNodeCtrl.py",
"chip/ChipCoreBluetoothMgr.py",
"chip/ChipStack.py",
"chip/FabricAdmin.py",
"chip/__init__.py",
"chip/ble/__init__.py",
"chip/ble/commissioning/__init__.py",
"chip/ble/get_adapters.py",
"chip/ble/library_handle.py",
"chip/ble/scan_devices.py",
"chip/ble/types.py",
"chip/clusters/Attribute.py",
"chip/clusters/Command.py",
"chip/clusters/__init__.py",
"chip/configuration/__init__.py",
"chip/discovery/__init__.py",
"chip/discovery/library_handle.py",
"chip/discovery/types.py",
"chip/exceptions/__init__.py",
"chip/interaction_model/__init__.py",
"chip/interaction_model/delegate.py",
"chip/internal/__init__.py",
"chip/internal/commissioner.py",
"chip/internal/thread.py",
"chip/internal/types.py",
"chip/logging/__init__.py",
"chip/logging/library_handle.py",
"chip/logging/types.py",
"chip/native/__init__.py",
"chip/setup_payload/__init__.py",
"chip/setup_payload/setup_payload.py",
"chip/storage/__init__.py",
"chip/utils/CommissioningBuildingBlocks.py",
"chip/utils/__init__.py",
"chip/yaml/__init__.py",
"chip/yaml/data_model_lookup.py",
"chip/yaml/errors.py",
"chip/yaml/format_converter.py",
"chip/yaml/parser.py",
]
if (chip_controller) {
sources += [
"chip-device-ctrl.py",
"chip-repl.py",
"chip/ChipDeviceCtrl.py",
]
} else {
sources += [
"chip/server/__init__.py",
"chip/server/types.py",
]
}
},
{
src_dir = target_out_dir
if (chip_controller) {
sources = [ "${target_out_dir}/chip/_ChipDeviceCtrl.so" ]
} else {
sources = [ "${target_out_dir}/chip/_ChipServer.so" ]
}
},
{
src_dir = "//"
sources = [ "//LICENSE" ]
},
]
inputs = []
py_packages = [
"chip",
"chip.ble",
"chip.ble.commissioning",
"chip.configuration",
"chip.clusters",
"chip.utils",
"chip.discovery",
"chip.exceptions",
"chip.internal",
"chip.interaction_model",
"chip.logging",
"chip.yaml",
"chip.native",
"chip.clusters",
"chip.setup_payload",
"chip.storage",
]
if (!chip_controller) {
py_packages += [ "chip.server" ]
}
py_package_reqs = [
"coloredlogs",
"construct",
"dacite",
"rich",
"pyyaml",
"ipdb",
"deprecation",
"mobly",
# Crypto libraries for complex tests and internal Python controller usage
"cryptography",
"pycrypto",
"ecdsa",
]
if (current_os == "mac") {
py_package_reqs += [ "pyobjc-framework-corebluetooth" ]
} else if (current_os == "linux") {
py_package_reqs += [ "pygobject" ]
}
if (current_cpu == "x64") {
cpu_tag = "x86_64"
} else if (current_cpu == "arm64" && current_os == "linux") {
cpu_tag = "aarch64"
} else if (current_cpu == "arm" && current_os == "linux") {
cpu_tag = "armv7l"
} else {
cpu_tag = current_cpu
}
if (current_os == "mac") {
py_platform_tag = string_replace(
string_replace(mac_deployment_target, "macos", "macosx."),
".",
"_")
} else {
py_platform_tag = current_os
}
py_platform_tag = py_platform_tag + "_" + cpu_tag
tags = "cp37-abi3-" + py_platform_tag
if (chip_controller) {
lib_name = "_ChipDeviceCtrl.so"
} else {
lib_name = "_ChipServer.so"
}
py_package_name = "chip-core"
public_deps = [ ":ChipDeviceCtrl" ]
output_name = "chip_core-${chip_python_version}-${tags}.whl"
}
chip_python_wheel_action("chip-clusters") {
py_manifest_files = [
{
src_dir = "."
sources = [
"chip/ChipUtility.py",
"chip/clusters/CHIPClusters.py",
"chip/clusters/ClusterObjects.py",
"chip/clusters/Objects.py",
"chip/clusters/TestObjects.py",
"chip/clusters/Types.py",
"chip/tlv/__init__.py",
]
},
{
src_dir = "//"
sources = [ "//LICENSE" ]
},
]
inputs = []
py_packages = [
"chip",
"chip.clusters",
"chip.tlv",
]
py_package_reqs = [ "dacite" ]
py_package_name = "chip-clusters"
py_platform_tag = "any"
output_name = "chip_clusters-${chip_python_version}-py3-none-any.whl"
}
chip_python_wheel_action("chip-repl") {
py_scripts = [
"chip-device-ctrl.py",
"chip-repl.py",
]
py_manifest_files = [
{
src_dir = "."
sources = [ "chip/ChipReplStartup.py" ]
sources += py_scripts
},
{
src_dir = "//"
sources = [ "//LICENSE" ]
},
]
inputs = []
py_packages = [ "chip" ]
py_package_reqs = [
"coloredlogs",
#
# IPython 7.30.0 has a bug which results in the use of await ... failing on some platforms (see https://github.com/ipython/ipython/pull/13269)
# For now, let's just avoid that version.
#
# IPython 8.1.0 has a bug which causes issues: https://github.com/ipython/ipython/issues/13554
#
#
"ipython!=8.1.0",
"rich",
"ipykernel",
"mobly",
]
py_package_name = "chip-repl"
py_platform_tag = "any"
data_deps = [
":chip-clusters",
":chip-core",
]
output_name = "chip_repl-${chip_python_version}-py3-none-any.whl"
}