| # 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("$dir_pw_build/python_dist.gni") | |
| import("${chip_root}/build/chip/tools.gni") | |
| import("${chip_root}/src/app/common_flags.gni") | |
| import("${chip_root}/src/controller/flags.gni") | |
| import("${chip_root}/src/data-model-providers/codegen/model.gni") | |
| import("${chip_root}/src/platform/python.gni") | |
| import("${chip_root}/src/system/system.gni") | |
| import("${dir_pw_unit_test}/test.gni") | |
| if (current_os == "mac") { | |
| import("${build_root}/config/mac/mac_sdk.gni") | |
| } | |
| declare_args() { | |
| chip_python_version = "1.0.0" | |
| chip_python_requires = ">=3.11" | |
| chip_python_package_prefix = "matter" | |
| chip_python_package_description = "Python-base APIs and tools for Matter SDK" | |
| chip_python_package_url = "https://github.com/project-chip/connectedhomeip" | |
| chip_python_package_classifiers = [ | |
| "Intended Audience :: Developers", | |
| "License :: OSI Approved :: Apache Software License", | |
| "Programming Language :: Python :: 3", | |
| ] | |
| chip_python_supports_stack_locking = chip_system_config_locking != "none" | |
| } | |
| config("controller_wno_deprecate") { | |
| cflags = [ "-Wno-deprecated-declarations" ] | |
| } | |
| if (chip_support_commissioning_in_controller) { | |
| _chip_device_ctrl_output_name = "_ChipDeviceCtrl" | |
| } else { | |
| _chip_device_ctrl_output_name = "_ChipServer" | |
| } | |
| shared_library("ChipDeviceCtrl") { | |
| output_name = _chip_device_ctrl_output_name | |
| output_dir = "${target_out_dir}/matter" | |
| include_dirs = [ "." ] | |
| sources = [ | |
| "matter/setup_payload/Generator.cpp", | |
| "matter/setup_payload/Parser.cpp", | |
| ] | |
| sources += [ "matter/native/CommonStackInit.cpp" ] | |
| defines = [] | |
| if (chip_support_commissioning_in_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", | |
| "JsonTlv.cpp", | |
| "OpCredsBinding.cpp", | |
| "matter/bdx/bdx.cpp", | |
| "matter/bdx/test-bdx-transfer-server.cpp", | |
| "matter/bdx/test-bdx-transfer-server.h", | |
| "matter/case_capture/CASECapture.cpp", | |
| "matter/case_capture/CASECapture.h", | |
| "matter/case_capture/CASEHandshakeMetrics.cpp", | |
| "matter/case_capture/CASEHandshakeMetrics.h", | |
| "matter/case_capture/CASEHandshakeMetricsBackend.cpp", | |
| "matter/clusters/attribute.cpp", | |
| "matter/clusters/command.cpp", | |
| "matter/commissioning/PlaceholderOperationalCredentialsIssuer.h", | |
| "matter/credentials/cert.cpp", | |
| "matter/credentials/cert.h", | |
| "matter/crypto/p256keypair.cpp", | |
| "matter/crypto/p256keypair.h", | |
| "matter/discovery/NodeResolution.cpp", | |
| "matter/fault_injection/FaultInjection.cpp", | |
| "matter/icd/PyChipCheckInDelegate.cpp", | |
| "matter/icd/PyChipCheckInDelegate.h", | |
| "matter/im_capture/IMCapture.cpp", | |
| "matter/im_capture/IMCapture.h", | |
| "matter/interaction_model/Delegate.cpp", | |
| "matter/interaction_model/Delegate.h", | |
| "matter/internal/ChipThreadWork.cpp", | |
| "matter/internal/ChipThreadWork.h", | |
| "matter/internal/CommissionerImpl.cpp", | |
| "matter/logging/LoggingFilter.cpp", | |
| "matter/logging/LoggingRedirect.cpp", | |
| "matter/native/ChipMainLoopWork.h", | |
| "matter/native/PyChipError.cpp", | |
| "matter/native/PyChipError.h", | |
| "matter/tracing/TracingSetup.cpp", | |
| "matter/utils/DeviceProxyUtils.cpp", | |
| ] | |
| if (chip_support_webrtc_python_bindings) { | |
| sources += [ | |
| "matter/webrtc/RTCClient.cpp", | |
| "matter/webrtc/WebRTC.cpp", | |
| "matter/webrtc/WebRTC.h", | |
| "matter/webrtc/WebRTCTransportCluster.cpp", | |
| ] | |
| } | |
| defines += [ "CHIP_CONFIG_MAX_ACTIVE_TCP_CONNECTIONS=20" ] | |
| defines += [ "CHIP_CONFIG_MAX_GROUP_KEYS_PER_FABRIC=50" ] | |
| defines += [ "CHIP_CONFIG_MAX_GROUPCAST_MEMBERSHIP_COUNT=100" ] | |
| if (chip_python_supports_stack_locking) { | |
| sources += [ "matter/native/ChipMainLoopWork_StackLock.cpp" ] | |
| } else { | |
| sources += [ "matter/native/ChipMainLoopWork_WorkSchedule.cpp" ] | |
| } | |
| } else { | |
| sources += [ | |
| "matter/server/Options.cpp", | |
| "matter/server/Options.h", | |
| "matter/server/ServerInit.cpp", | |
| ] | |
| } | |
| if (chip_enable_ble) { | |
| if (current_os == "linux") { | |
| sources += [ "matter/ble/LinuxImpl.cpp" ] | |
| } else if (current_os == "mac") { | |
| sources += [ | |
| "matter/ble/darwin/AdapterListing.mm", | |
| "matter/ble/darwin/Scanning.mm", | |
| ] | |
| cflags = [ "-fobjc-arc" ] | |
| } else if (current_os == "all") { | |
| # current_os="all" is a synthetic aggregation used at generation time. | |
| # Skip selecting a concrete BLE backend in this configuration. | |
| } else { | |
| assert(false, "No BLE implementation available for the current OS.") | |
| } | |
| } | |
| public_deps = [ | |
| "${chip_root}/src/app", | |
| "${chip_root}/src/app/icd/client:handler", | |
| "${chip_root}/src/app/server", | |
| "${chip_root}/src/controller", | |
| "${chip_root}/src/credentials:default_attestation_verifier", | |
| "${chip_root}/src/credentials:test_dac_revocation_delegate", | |
| "${chip_root}/src/lib", | |
| "${chip_root}/src/lib/core", | |
| "${chip_root}/src/lib/dnssd", | |
| "${chip_root}/src/lib/support", | |
| "${chip_root}/src/lib/support:arg_parser", | |
| "${chip_root}/src/lib/support/jsontlv", | |
| "${chip_root}/src/platform", | |
| "${chip_root}/src/platform/logging:default", | |
| "${chip_root}/src/setup_payload", | |
| "${chip_root}/src/transport", | |
| "matter/case_capture:case_handshake_metrics", | |
| ] | |
| if (chip_support_webrtc_python_bindings) { | |
| public_deps += [ | |
| "${chip_root}/src/controller/webrtc:chip_webrtc", | |
| "${chip_root}/third_party/libdatachannel:libdatachannel", | |
| ] | |
| include_dirs += [ | |
| "${chip_root}/src/controller/webrtc/", | |
| "${chip_root}/third_party/libdatachannel/repo/include", | |
| ] | |
| } | |
| if (chip_support_commissioning_in_controller) { | |
| public_deps += [ | |
| "${chip_root}/src/credentials:file_attestation_trust_store", | |
| "${chip_root}/src/lib/support:testing", | |
| "${chip_root}/src/tracing/json", | |
| "${chip_root}/src/tracing/perfetto", | |
| "${chip_root}/src/tracing/perfetto:file_output", | |
| "${chip_root}/third_party/jsoncpp", | |
| "matter/bdx:bdx-transfer", | |
| ] | |
| deps = [ | |
| "${chip_root}/src/tracing/perfetto:event_storage", | |
| "${chip_root}/src/tracing/perfetto:simple_initialization", | |
| ] | |
| if (chip_build_controller_dynamic_server) { | |
| defines += [ "CHIP_CONFIG_SKIP_APP_SPECIFIC_GENERATED_HEADER_INCLUDES=1" ] | |
| deps += [ "${chip_root}/src/controller:nodatamodel" ] | |
| # Temporary dependency: InteractionModelEngine NEEDS a codegen data model instance | |
| # defined and application is supposed to provide it. This adds the sources | |
| # in the same way "data_model" implementations do | |
| # | |
| # DynamicDispatcher in src/app:interaction-model implements the actual required | |
| # ember callbacks in this case... | |
| sources += codegen_data_model_SOURCES | |
| public_deps += codegen_data_model_PUBLIC_DEPS | |
| } else { | |
| public_deps += [ "${chip_root}/src/controller/data_model" ] | |
| } | |
| } else { | |
| public_deps += [ "$chip_data_model" ] | |
| } | |
| configs += [ ":controller_wno_deprecate" ] | |
| } | |
| pw_python_package("matter-core-module") { | |
| sources = [ | |
| "matter/CertificateAuthority.py", | |
| "matter/ChipBleBase.py", | |
| "matter/ChipBleUtility.py", | |
| "matter/ChipBluezMgr.py", | |
| "matter/ChipCommissionableNodeCtrl.py", | |
| "matter/ChipStack.py", | |
| "matter/FabricAdmin.py", | |
| "matter/MatterTlvJson.py", | |
| "matter/__init__.py", | |
| "matter/bdx/Bdx.py", | |
| "matter/bdx/BdxProtocol.py", | |
| "matter/bdx/BdxTransfer.py", | |
| "matter/bdx/__init__.py", | |
| "matter/ble/__init__.py", | |
| "matter/ble/commissioning/__init__.py", | |
| "matter/ble/get_adapters.py", | |
| "matter/ble/library_handle.py", | |
| "matter/ble/scan_devices.py", | |
| "matter/ble/types.py", | |
| "matter/case_capture/__init__.py", | |
| "matter/commissioning/__init__.py", | |
| "matter/commissioning/commissioning_flow_blocks.py", | |
| "matter/commissioning/pase.py", | |
| "matter/configuration/__init__.py", | |
| "matter/credentials/__init__.py", | |
| "matter/credentials/cert.py", | |
| "matter/crypto/__init__.py", | |
| "matter/crypto/fabric.py", | |
| "matter/crypto/p256keypair.py", | |
| "matter/discovery/__init__.py", | |
| "matter/discovery/library_handle.py", | |
| "matter/discovery/types.py", | |
| "matter/exceptions/__init__.py", | |
| "matter/fault_injection/__init__.py", | |
| "matter/im_capture/__init__.py", | |
| "matter/interaction_model/__init__.py", | |
| "matter/interaction_model/delegate.py", | |
| "matter/internal/__init__.py", | |
| "matter/internal/commissioner.py", | |
| "matter/internal/thread.py", | |
| "matter/internal/types.py", | |
| "matter/logging/__init__.py", | |
| "matter/logging/library_handle.py", | |
| "matter/logging/types.py", | |
| "matter/native/__init__.py", | |
| "matter/setup_payload/__init__.py", | |
| "matter/setup_payload/setup_payload.py", | |
| "matter/storage/__init__.py", | |
| "matter/tracing/__init__.py", | |
| "matter/utils/CommissioningBuildingBlocks.py", | |
| "matter/utils/__init__.py", | |
| ] | |
| if (chip_support_webrtc_python_bindings) { | |
| sources += [ | |
| "matter/webrtc/__init__.py", | |
| "matter/webrtc/async_websocket_client.py", | |
| "matter/webrtc/browser_peer_connection.py", | |
| "matter/webrtc/browser_webrtc_client.py", | |
| "matter/webrtc/command.py", | |
| "matter/webrtc/libdatachannel_peer_connection.py", | |
| "matter/webrtc/libdatachannel_webrtc_client.py", | |
| "matter/webrtc/library_handle.py", | |
| "matter/webrtc/types.py", | |
| "matter/webrtc/utils.py", | |
| "matter/webrtc/webrtc_manager.py", | |
| ] | |
| } | |
| if (chip_support_commissioning_in_controller) { | |
| sources += [ "matter/ChipDeviceCtrl.py" ] | |
| } else { | |
| sources += [ "matter/server/__init__.py" ] | |
| } | |
| generate_setup = { | |
| metadata = { | |
| name = "${chip_python_package_prefix}-core-module" | |
| version = chip_python_version | |
| description = chip_python_package_description | |
| url = chip_python_package_url | |
| classifiers = chip_python_package_classifiers | |
| } | |
| options = { | |
| python_requires = chip_python_requires | |
| install_requires = [ | |
| "coloredlogs", | |
| "construct", | |
| "cryptography", | |
| "dacite", | |
| "deprecation", | |
| "ecdsa", | |
| "ipdb", | |
| "matter-clusters", | |
| "pyyaml", | |
| "rich", | |
| ] | |
| } | |
| } | |
| } | |
| pw_python_distribution("matter-core") { | |
| packages = [ ":matter-core-module" ] | |
| 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 | |
| generate_setup_cfg = { | |
| name = "${chip_python_package_prefix}-core" | |
| version = chip_python_version | |
| include_default_pyproject_file = true | |
| include_extra_files_in_package_data = true | |
| } | |
| extra_files = [ "//LICENSE > matter/LICENSE" ] | |
| _matter_core_wheel_cfg = | |
| "$root_gen_dir/src/controller/python/matter-core-wheel.cfg" | |
| write_file(_matter_core_wheel_cfg, | |
| [ | |
| "[options]", | |
| "python_requires = ${chip_python_requires}", | |
| "", | |
| "[bdist_wheel]", | |
| "universal = false", | |
| "py_limited_api = cp311", | |
| "plat_name = ${py_platform_tag}", | |
| "root_is_pure = false", | |
| ], | |
| "list lines") | |
| generate_setup_cfg.common_config_file = _matter_core_wheel_cfg | |
| _chip_device_ctrl_out_dir = | |
| get_label_info(":ChipDeviceCtrl", "target_out_dir") | |
| public_deps = [ ":ChipDeviceCtrl" ] | |
| extra_files += [ "${_chip_device_ctrl_out_dir}/matter/${_chip_device_ctrl_output_name}.so > matter/${_chip_device_ctrl_output_name}.so" ] | |
| } | |
| pw_python_package("matter-clusters-module") { | |
| sources = [ | |
| "matter/ChipUtility.py", | |
| "matter/clusters/Attribute.py", | |
| "matter/clusters/CHIPClusters.py", | |
| "matter/clusters/ClusterObjects.py", | |
| "matter/clusters/Command.py", | |
| "matter/clusters/Objects.py", | |
| "matter/clusters/TestObjects.py", | |
| "matter/clusters/Types.py", | |
| "matter/clusters/__init__.py", | |
| "matter/clusters/enum.py", | |
| "matter/tlv/__init__.py", | |
| "matter/tlv/tlvlist.py", | |
| ] | |
| generate_setup = { | |
| metadata = { | |
| name = "${chip_python_package_prefix}-clusters-module" | |
| version = chip_python_version | |
| description = chip_python_package_description | |
| url = chip_python_package_url | |
| classifiers = chip_python_package_classifiers | |
| } | |
| options = { | |
| python_requires = chip_python_requires | |
| install_requires = [ | |
| "aenum", | |
| "construct", | |
| "dacite", | |
| "rich", | |
| ] | |
| } | |
| } | |
| python_deps = [ ":matter-core-module" ] | |
| } | |
| pw_python_distribution("matter-clusters") { | |
| packages = [ ":matter-clusters-module" ] | |
| generate_setup_cfg = { | |
| name = "${chip_python_package_prefix}-clusters" | |
| version = chip_python_version | |
| include_default_pyproject_file = true | |
| include_extra_files_in_package_data = true | |
| } | |
| extra_files = [ "//LICENSE > matter/LICENSE" ] | |
| } | |
| pw_python_package("matter-repl-module") { | |
| python_deps = [ ":matter-core-module" ] | |
| sources = [ | |
| "matter/ChipCoreBluetoothMgr.py", | |
| "matter/ReplStartup.py", | |
| "matter/repl_main.py", | |
| ] | |
| generate_setup = { | |
| options = { | |
| python_requires = chip_python_requires | |
| install_requires = [ | |
| "coloredlogs", | |
| # IPython 8.1.0 has a bug which causes issues: https://github.com/ipython/ipython/issues/13554 | |
| "ipython>8.1.0", | |
| "rich", | |
| "ipykernel", | |
| "pyobjc-framework-corebluetooth ; sys_platform==\"darwin\"", | |
| "dbus-python==1.2.18 ; sys_platform==\"linux\"", | |
| "pygobject==3.50.0 ; sys_platform==\"linux\"", | |
| "matter-core", | |
| ] | |
| entry_points = { | |
| console_scripts = [ "matter-repl = matter.repl_main:main" ] | |
| } | |
| } | |
| metadata = { | |
| name = "${chip_python_package_prefix}-repl-module" | |
| version = chip_python_version | |
| description = chip_python_package_description | |
| url = chip_python_package_url | |
| classifiers = chip_python_package_classifiers | |
| } | |
| } | |
| } | |
| pw_python_distribution("matter-repl") { | |
| packages = [ ":matter-repl-module" ] | |
| generate_setup_cfg = { | |
| name = "${chip_python_package_prefix}-repl" | |
| version = chip_python_version | |
| include_default_pyproject_file = true | |
| include_extra_files_in_package_data = true | |
| } | |
| public_deps = [ | |
| ":matter-clusters", | |
| ":matter-core", | |
| ] | |
| extra_files = [ "//LICENSE > matter/LICENSE" ] | |
| } | |
| if (chip_support_commissioning_in_controller) { | |
| pw_python_package("matter-controller-tests") { | |
| generate_setup = { | |
| metadata = { | |
| name = "matter-controller-tests" | |
| version = chip_python_version | |
| } | |
| } | |
| tests = [ "tests/test_commissioning_flow_blocks.py" ] | |
| python_deps = [ | |
| ":matter-clusters-module", | |
| ":matter-core-module", | |
| ] | |
| } | |
| } | |
| # Python wheels collection for core Matter controller packages | |
| pw_python_wheels("matter-controller-wheels") { | |
| packages = [ | |
| ":matter-clusters", | |
| ":matter-core", | |
| ":matter-repl", | |
| ] | |
| } |