Skip to content

Commit

Permalink
Roll up third_party/pigweed/repo to ToT (project-chip#4044)
Browse files Browse the repository at this point in the history
  • Loading branch information
szatmz authored Dec 4, 2020
1 parent d708a13 commit 2244db6
Show file tree
Hide file tree
Showing 17 changed files with 179 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
out/
/src/test_driver/nrfconnect/build/

# Environment directory
.environment/

# Temporary Directories
.tmp/

Expand Down
9 changes: 9 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import("//build_overrides/nlassert.gni")
import("//build_overrides/nlio.gni")
import("//build_overrides/nlunit_test.gni")
import("//build_overrides/pigweed.gni")
import("$dir_pw_build/python.gni")

# This build file should not be used in superproject builds.
assert(chip_root == "//")
Expand All @@ -32,6 +33,14 @@ if (current_toolchain != "${dir_pw_toolchain}/dummy:dummy") {
(host_cpu == "x64" || host_cpu == "arm64")
}

# Python packages for supporting specific targets.
pw_python_group("python_packages") {
python_deps = [
"integrations/mobly:chip_mobly",
"third_party/happy",
]
}

# This is a real toolchain. Build CHIP.
group("default") {
deps = [
Expand Down
3 changes: 2 additions & 1 deletion build/chip/chip_test.gni
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import("//build_overrides/chip.gni")
import("//build_overrides/pigweed.gni")
import("$dir_pw_build/python_action.gni")

import("${chip_root}/build/chip/tests.gni")
import("${chip_root}/src/platform/device.gni")
Expand All @@ -35,7 +36,7 @@ if (chip_link_tests) {
output_dir = _test_output_dir
}

pw_python_script(_test_name + "_run") {
pw_python_action(_test_name + "_run") {
deps = [ ":${_test_name}" ]
inputs = [ pw_unit_test_AUTOMATIC_RUNNER ]
script = "$dir_pw_unit_test/py/pw_unit_test/test_runner.py"
Expand Down
21 changes: 21 additions & 0 deletions integrations/mobly/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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/pigweed.gni")

import("$dir_pw_build/python.gni")

pw_python_package("chip_mobly") {
setup = [ "setup.py" ]
}
13 changes: 13 additions & 0 deletions integrations/mobly/build/lib/chip_mobly/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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.
89 changes: 89 additions & 0 deletions integrations/mobly/build/lib/chip_mobly/pigweed_device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# 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 os
from pathlib import Path
import serial # type: ignore
import importlib

from pw_hdlc_lite.rpc import HdlcRpcClient

# Point the script to the .proto file with our RPC services.
PROTO = Path(os.environ["PW_ROOT"], "pw_rpc/pw_rpc_protos/echo.proto")

MOBLY_CONTROLLER_CONFIG_NAME = "PigweedDevice"


class Error(Exception):
"""This is the Exception class defined for all errors."""


class PigweedDevice:
def __init__(self, device_tty, baud, platform_module=None, platform_args=None):
self.pw_rpc_client = HdlcRpcClient(serial.Serial(device_tty, baud), [PROTO])
self._platform = None
print("Platform args: %s" % platform_args)
print("Platform module: %s" % platform_module)
if platform_module:
m = importlib.import_module(platform_module)
create_platform_method = getattr(m, "create_platform")
self._platform = create_platform_method(platform_args)

def rpcs(self):
return self.pw_rpc_client.rpcs().pw.rpc

@property
def platform(self):
return self._platform


def create(configs):
"""Initializes the CHIP devices based on the testbed configuration.
Args:
configs: a list of testbed configs.
Returns:
a list of device objects
"""
objs = []
for config in configs:
_validate_config(config)
device = PigweedDevice(**config)
objs.append(device)
return objs


def destroy(unused_objs):
"""Destroys the wearable objects.
Args:
unused_objs: a list of device objects.
"""
pass


def _validate_config(config):
"""Verifies that a config dict for a CHIP device is valid.
Args:
config: A dict that is the configuration for a CHIP device.
Raises:
chip_device.Error: Config file is not valid.
"""
required_keys = ["device_tty", "baud"] # A placeholder.
for key in required_keys:
if key not in config:
raise Error("Required key %s missing from config %s" % (key, config))
2 changes: 1 addition & 1 deletion integrations/mobly/chip_mobly/pigweed_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import os
from pathlib import Path
import serial
import serial # type: ignore
import importlib

from pw_hdlc_lite.rpc import HdlcRpcClient
Expand Down
2 changes: 1 addition & 1 deletion integrations/mobly/hello_world_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

from chip_mobly import pigweed_device
from mobly import asserts
from mobly import asserts # type: ignore
from mobly import base_test
from mobly import test_runner

Expand Down
7 changes: 1 addition & 6 deletions integrations/mobly/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@

"""chip_mobly"""

import setuptools
import setuptools # type: ignore

setuptools.setup(
name='chip_mobly',
version='0.0.1',
author='CHIP Authors',
# author_email='?',
description='Integration of Mobly with CHIP devices',
packages=setuptools.find_packages(),
#TODO - uncomment this once native python building is solved for
# psutil (one of mobly's dependencies which CHIP does
# not actually need)
# install_requires=['mobly'],
)
8 changes: 6 additions & 2 deletions scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ _bootstrap_or_activate() {
EOF
)"

PW_PROJECT_ROOT="$_CHIP_ROOT"
export PW_PROJECT_ROOT

PW_ROOT="$_CHIP_ROOT/third_party/pigweed/repo"
export PW_ROOT

Expand All @@ -65,8 +68,9 @@ EOF
--install-dir "$_PW_ACTUAL_ENVIRONMENT_ROOT" \
--virtualenv-requirements "$_CHIP_ROOT/scripts/requirements.txt" \
--cipd-package-file "$_CHIP_ROOT/scripts/pigweed.json" \
--virtualenv-setup-py-root "$_CHIP_ROOT/third_party/pigweed" \
--virtualenv-setup-py-root "$_CHIP_ROOT/integrations/mobly"
--virtualenv-gn-target "$PW_ROOT#:target_support_packages.install" \
--virtualenv-gn-target "$PW_ROOT#:python.install" \
--virtualenv-gn-target "$_CHIP_ROOT#:python_packages.install"
pw_finalize bootstrap "$_SETUP_SH"
else
pw_activate
Expand Down
3 changes: 3 additions & 0 deletions scripts/examples/nrfconnect_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
# limitations under the License.
#

# Run bootstrap to set up e.g. Pigweed correctly
source "$(dirname "$0")/../../scripts/bootstrap.sh"

cd "$(dirname "$0")/../../examples"

APP="$1"
Expand Down
4 changes: 4 additions & 0 deletions scripts/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ mobly

# zephyr
west>=0.8.0

# happy tests
lockfile
psutil >= 5.7.3
3 changes: 2 additions & 1 deletion scripts/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ cryptography==3.2.1 # via -r requirements.in
docopt==0.6.2 # via pykwalify
future==0.18.2 # via -r requirements.in, mobly
idna==2.10 # via requests
lockfile==0.12.2 # via -r requirements.in
mobly==1.10 # via -r requirements.in
packaging==20.4 # via west
pip-tools==5.3.1 # via -r requirements.in
portpicker==1.3.1 # via -r requirements.in, mobly
psutil==5.7.2 # via mobly
psutil==5.7.3 # via -r requirements.in, mobly
pycparser==2.20 # via cffi
pyelftools==0.26 # via -r requirements.in
pykwalify==1.7.0 # via west
Expand Down
4 changes: 0 additions & 4 deletions scripts/tests/happy_test_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@
args = parser.parse_args()
# GN will run Python in venv, which will break happy test
if args.ci:
if test_environ.get("VIRTUAL_ENV", None) != None:
del test_environ["VIRTUAL_ENV"]
test_environ["PATH"] = ":".join([s for s in test_environ.get(
"PATH", "").split(":") if not os.path.realpath(s).startswith(os.path.realpath(os.path.join(CHIP_PATH, "third_party/pigweed/repo")))])
test_environ["HAPPY_LOG_DIR"] = "/tmp/happy_test_logs"
test_environ["TEST_BIN_DIR"] = args.bin_dir
test_environ["HAPPY_MAIN_CONFIG_FILE"] = os.path.realpath(
Expand Down
3 changes: 2 additions & 1 deletion src/controller/python/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import("//build_overrides/chip.gni")
import("//build_overrides/pigweed.gni")
import("$dir_pw_build/python.gni")

import("${chip_root}/build/chip/tools.gni")
import("${dir_pw_unit_test}/test.gni")
Expand Down Expand Up @@ -54,7 +55,7 @@ shared_library("ChipDeviceCtrl") {
configs += [ ":controller_wno_deprecate" ]
}

pw_python_script("python") {
pw_python_action("python") {
script = "build-chip-wheel.py"

_py_manifest_files = [
Expand Down
21 changes: 21 additions & 0 deletions third_party/happy/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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/pigweed.gni")
import("$dir_pw_build/python.gni")

pw_python_package("happy") {
setup = [ "repo/setup.py" ]
lint = false
}
2 changes: 1 addition & 1 deletion third_party/pigweed/repo
Submodule repo updated from fa1fc6 to e65ddc

0 comments on commit 2244db6

Please sign in to comment.