Skip to content

Commit

Permalink
Initial pybind11 Controller Wrapper
Browse files Browse the repository at this point in the history
CHIP_ERROR update from Kevin

Fixes small errors in create_error_wrapper based off the new CHIPError class

Fixing darin workflow to install python3.9

Adding full path to gitmodules
  • Loading branch information
krypton36 committed Aug 18, 2021
1 parent 49222e4 commit f0d8760
Show file tree
Hide file tree
Showing 13 changed files with 696 additions and 51 deletions.
26 changes: 15 additions & 11 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
timeout-minutes: 20
run: scripts/build/gn_build.sh
build_linux:
name: Build on Linux (gcc_release, clang, mbedtls)
name: Build on Linux (gcc_release, clang, mbedtls, python_lib)
timeout-minutes: 60

runs-on: ubuntu-latest
Expand Down Expand Up @@ -138,11 +138,12 @@ jobs:
- name: Setup Build, Run Build and Run Tests
timeout-minutes: 50
run: |
for BUILD_TYPE in gcc_release clang mbedtls; do
for BUILD_TYPE in gcc_release clang mbedtls python_lib; do
case $BUILD_TYPE in
"gcc_release") GN_ARGS='is_debug=false';;
"clang") GN_ARGS='is_clang=true';;
"mbedtls") GN_ARGS='chip_crypto="mbedtls"';;
"python_lib") GN_ARGS='enable_rtti=true enable_pylib=true';;
esac
scripts/build/gn_gen.sh --args="$GN_ARGS"
Expand All @@ -167,7 +168,7 @@ jobs:
if: ${{ github.event_name == 'push' && github.event.ref == 'refs/heads/master' }}
uses: github/codeql-action/analyze@v1
build_darwin:
name: Build on Darwin
name: Build on Darwin (clang, python_lib)
timeout-minutes: 60

env:
Expand Down Expand Up @@ -202,19 +203,22 @@ jobs:
path: |
.environment/gn_out/.ninja_log
.environment/pigweed-venv/*.log
- name: Setup Build
- name: Setup Build, Run Build and Run Tests
timeout-minutes: 50
# Just go ahead and do the "all" build; on Darwin that's fairly
# fast. If this ever becomes slow, we can think about ways to do
# the examples-linux-standalone.yaml tests on darwin without too
# much code duplication.
run: |
scripts/build/gn_gen.sh --args='is_clang=true target_os="all"'
- name: Run Build
timeout-minutes: 30
run: scripts/build/gn_build.sh
- name: Run Tests
timeout-minutes: 10
run: scripts/tests/gn_tests.sh
for BUILD_TYPE in clang python_lib; do
case $BUILD_TYPE in
"clang") GN_ARGS='is_clang=true target_os="all"';;
"python_lib") GN_ARGS='enable_rtti=true enable_pylib=true';;
esac
scripts/build/gn_gen.sh --args="$GN_ARGS"
scripts/build/gn_build.sh
scripts/tests/gn_tests.sh
done
# TODO Log Upload https://github.com/project-chip/connectedhomeip/issues/2227
# TODO https://github.com/project-chip/connectedhomeip/issues/1512
# - name: Run Code Coverage
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/darwin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
with:
submodules: true
- name: Setup Environment
run: brew install openssl pkg-config
run: brew install openssl pkg-config python@3.9
- name: Fix pkgconfig link
working-directory: /usr/local/lib/pkgconfig
run: |
Expand Down
50 changes: 27 additions & 23 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,79 +1,79 @@
[submodule "nlassert"]
path = third_party/nlassert/repo
url = https://github.com/nestlabs/nlassert.git
branch = master
branch = master
[submodule "nlfaultinjection"]
path = third_party/nlfaultinjection/repo
url = https://github.com/nestlabs/nlfaultinjection.git
branch = master
branch = master
[submodule "nlio"]
path = third_party/nlio/repo
url = https://github.com/nestlabs/nlio.git
branch = master
branch = master
[submodule "nlunit-test"]
path = third_party/nlunit-test/repo
url = https://github.com/nestlabs/nlunit-test.git
branch = master
branch = master
[submodule "mbedtls"]
path = third_party/mbedtls/repo
url = https://github.com/ARMmbed/mbedtls.git
branch = mbedtls-2.25
branch = mbedtls-2.25
[submodule "qrcode"]
path = examples/common/QRCode/repo
url = https://github.com/nayuki/QR-Code-generator.git
branch = master
branch = master
[submodule "m5stack-tft"]
path = examples/common/m5stack-tft/repo
url = https://github.com/jeremyjh/ESP32_TFT_library.git
branch = master
branch = master
[submodule "pigweed"]
path = third_party/pigweed/repo
url = https://github.com/google/pigweed.git
branch = main
branch = main
[submodule "openthread"]
path = third_party/openthread/repo
url = https://github.com/openthread/openthread.git
branch = main
branch = main
[submodule "ot-br-posix"]
path = third_party/ot-br-posix/repo
url = https://github.com/openthread/ot-br-posix.git
branch = main
branch = main
[submodule "bluez"]
path = third_party/bluez/repo
url = https://github.com/bluez/bluez.git
branch = master
branch = master
[submodule "cirque"]
path = third_party/cirque/repo
url = https://github.com/openweave/cirque.git
branch = master
branch = master
[submodule "happy"]
path = third_party/happy/repo
url = https://github.com/openweave/happy.git
branch = master
branch = master
[submodule "nanopb"]
path = third_party/nanopb/repo
url = https://github.com/nanopb/nanopb.git
branch = master
branch = master
[submodule "qpg_sdk"]
path = third_party/qpg_sdk/repo
url = https://github.com/Qorvo/qpg-connectedhomeip
branch = master
branch = master
[submodule "zap"]
path = third_party/zap/repo
url = https://github.com/project-chip/zap.git
branch = master
branch = master
[submodule "freertos"]
path = third_party/freertos/repo
url = https://github.com/FreeRTOS/FreeRTOS-Kernel.git
branch = V10.3.1-kernel-only
branch = V10.3.1-kernel-only
[submodule "efr32_sdk"]
path = third_party/efr32_sdk/repo
url = https://github.com/SiliconLabs/sdk_support.git
branch = master
branch = master
[submodule "simw-top-mini"]
path = third_party/simw-top-mini/repo
url = https://github.com/NXP/plug-and-trust.git
branch = int/CHIPSE_Release
branch = int/CHIPSE_Release
[submodule "third_party/openthread/ot-nxp"]
path = third_party/openthread/ot-nxp
url = https://github.com/openthread/ot-nxp.git
Expand All @@ -86,22 +86,22 @@
[submodule "third_party/mbed-os/repo"]
path = third_party/mbed-os/repo
url = https://github.com/ARMmbed/mbed-os.git
branch = feature-chip
branch = feature-chip
[submodule "third_party/wifi-ism43362/repo"]
path = third_party/wifi-ism43362/repo
url = https://github.com/ATmobica/wifi-ism43362.git
branch = master
branch = master
[submodule "third_party/mbed-os-posix-socket/repo"]
path = third_party/mbed-os-posix-socket/repo
url = https://github.com/ARMmbed/mbed-os-posix-socket.git
branch = main
branch = main
[submodule "p6/abstraction-rtos"]
path = third_party/p6/p6_sdk/libs/abstraction-rtos
url = https://github.com/Infineon/abstraction-rtos
[submodule "p6/bluetooth-freertos"]
path = third_party/p6/p6_sdk/libs/bluetooth-freertos
url = https://github.com/Infineon/bluetooth-freertos
branch = v2.X
branch = v2.X
[submodule "p6/btstack"]
path = third_party/p6/p6_sdk/libs/btstack
url = https://github.com/Infineon/btstack
Expand Down Expand Up @@ -159,3 +159,7 @@
[submodule "p6/recipe-make-cat1a"]
path = third_party/p6/p6_sdk/libs/recipe-make-cat1a
url = https://github.com/Infineon/recipe-make-cat1a
[submodule "third_party/pybind11/repo"]
path = third_party/pybind11/repo
url = https://github.com/pybind/pybind11
branch = stable
7 changes: 7 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
chip_enable_python_modules =
(current_os == "mac" || current_os == "linux") &&
(host_cpu == "x64" || host_cpu == "arm64")
enable_pylib = false
}

# Python packages for supporting specific targets.
Expand Down Expand Up @@ -112,6 +113,9 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
deps += [ "${chip_root}/src/tools/chip-cert" ]
}
if (chip_enable_python_modules) {
if (enable_pylib) {
deps += [ "${chip_root}/src/pybindings/pycontroller" ]
}
deps += [ "${chip_root}/src/controller/python" ]
}
}
Expand All @@ -129,6 +133,9 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
data_deps = [ "${chip_root}/examples/chip-tool" ]

if (chip_enable_python_modules) {
if (enable_pylib) {
data_deps += [ "${chip_root}/src/pybindings/pycontroller" ]
}
data_deps += [ "${chip_root}/src/controller/python" ]
}

Expand Down
11 changes: 10 additions & 1 deletion build/config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ config("sanitize_default") {
config("fuzzing_default") {
}

declare_args() {
# Enable Runtime Type Information (RTTI)
enable_rtti = false
}

config("no_rtti") {
cflags_cc = [ "-fno-rtti" ]
}
Expand All @@ -365,7 +370,11 @@ config("rtti") {
}

config("rtti_default") {
configs = [ ":no_rtti" ]
if (enable_rtti) {
configs = [ ":rtti" ]
} else {
configs = [ ":no_rtti" ]
}
}

config("no_exceptions") {
Expand Down
18 changes: 9 additions & 9 deletions integrations/docker/images/chip-build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ RUN set -x \
ninja-build \
openjdk-8-jdk \
pkg-config \
python3 \
python3-dev \
python3-pip \
python3-venv \
python3.9 \
python3.9-dev \
python3.9-venv \
rsync \
shellcheck \
strace \
Expand All @@ -74,14 +73,15 @@ RUN set -x \
&& exec bash \
&& : # last line

# Python 2 and PIP
# Python 3.9 and PIP
RUN set -x \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y libgirepository1.0-dev \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common \
&& add-apt-repository universe \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y python python2 \
&& curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py \
&& python2 get-pip.py \
&& curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py \
&& python3.9 get-pip.py \
&& update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1 \
&& rm -rf /var/lib/apt/lists/ \
&& : # last line

Expand Down
2 changes: 1 addition & 1 deletion integrations/docker/images/chip-build/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.37
0.5.0
29 changes: 24 additions & 5 deletions scripts/build_python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ OUTPUT_ROOT="$CHIP_ROOT/out/python_lib"
ENVIRONMENT_ROOT="$CHIP_ROOT/out/python_env"

declare chip_detail_logging=false
declare enable_pybindings=false
declare chip_mdns
declare clusters=true

help() {

echo "Usage: $file_name [ options ... ] [ -chip_detail_logging ChipDetailLoggingValue ] [ -chip_mdns ChipMDNSValue ]"
echo "Usage: $file_name [ options ... ] [ -chip_detail_logging ChipDetailLoggingValue ] [ -chip_mdns ChipMDNSValue ] [-enable_pybindings EnableValue]"

echo "General Options:
-h, --help Display this information.
Expand All @@ -55,6 +56,7 @@ Input Options:
By default it is minimal.
-c, --clusters_for_ip_commissioning true/false Specify whether to use clusters for IP commissioning.
By default it is true.
-p, --enable_pybindings EnableValue Specify whether to enable pybindings as python controller.
"
}

Expand All @@ -78,6 +80,10 @@ while (($#)); do
clusters=$2
shift
;;
--enable_pybindings | -p)
enable_pybindings=$2
shift
;;
-*)
help
echo "Unknown Option \"$1\""
Expand All @@ -88,25 +94,38 @@ while (($#)); do
done

# Print input values
echo "Input values: chip_detail_logging = $chip_detail_logging , chip_mdns = \"$chip_mdns\""
echo "Input values: chip_detail_logging = $chip_detail_logging , chip_mdns = \"$chip_mdns\", enable_pybindings = $enable_pybindings"

# Ensure we have a compilation environment
source "$CHIP_ROOT/scripts/activate.sh"

# Generates ninja files
[[ -n "$chip_mdns" ]] && chip_mdns_arg="chip_mdns=\"$chip_mdns\"" || chip_mdns_arg=""
gn --root="$CHIP_ROOT" gen "$OUTPUT_ROOT" --args="chip_detail_logging=$chip_detail_logging chip_use_clusters_for_ip_commissioning=$clusters $chip_mdns_arg"

gn --root="$CHIP_ROOT" gen "$OUTPUT_ROOT" --args="chip_detail_logging=$chip_detail_logging enable_pylib=$enable_pybindings enable_rtti=$enable_pybindings chip_use_clusters_for_ip_commissioning=$clusters $chip_mdns_arg"

# Compiles python files
ninja -C "$OUTPUT_ROOT" python
# Check pybindings was requested
if [ "$enable_pybindings" == true ]; then
ninja -v -C "$OUTPUT_ROOT" pycontroller
else
ninja -v -C "$OUTPUT_ROOT" python
fi

# Create a virtual environment that has access to the built python tools
virtualenv --clear "$ENVIRONMENT_ROOT"

# Activate the new enviroment to register the python WHL

if [ "$enable_pybindings" == true ]; then
WHEEL=$(ls "$OUTPUT_ROOT"/pybindings/pycontroller/pychip-*.whl | head -n 1)
else
WHEEL=$(ls "$OUTPUT_ROOT"/controller/python/chip-*.whl | head -n 1)
fi

source "$ENVIRONMENT_ROOT"/bin/activate
"$ENVIRONMENT_ROOT"/bin/python -m pip install --upgrade pip
"$ENVIRONMENT_ROOT"/bin/pip install --upgrade --force-reinstall --no-cache-dir "$OUTPUT_ROOT"/controller/python/chip-*.whl
"$ENVIRONMENT_ROOT"/bin/pip install --upgrade --force-reinstall --no-cache-dir "$WHEEL"

echo ""
echo_green "Compilation completed and WHL package installed in: "
Expand Down
Loading

0 comments on commit f0d8760

Please sign in to comment.