blob: 7949f04644ca6fc9ce352981bc7ea4c2a7fc8137 [file] [log] [blame]
Andrei Litvine8377572021-02-04 15:22:46 -05001#!/usr/bin/env bash
2
3#
4# Copyright (c) 2021 Project CHIP Authors
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19set -e
20
Michael Spang98f72f82021-03-08 09:24:37 -050021_normpath() {
22 python -c "import os.path; print(os.path.normpath('$@'))"
23}
24
Andrei Litvine8377572021-02-04 15:22:46 -050025echo_green() {
26 echo -e "\033[0;32m$*\033[0m"
27}
28
29echo_blue() {
30 echo -e "\033[1;34m$*\033[0m"
31}
32
33echo_bold_white() {
34 echo -e "\033[1;37m$*\033[0m"
35}
36
Michael Spang98f72f82021-03-08 09:24:37 -050037CHIP_ROOT=$(_normpath "$(dirname "$0")/..")
Andrei Litvine8377572021-02-04 15:22:46 -050038OUTPUT_ROOT="$CHIP_ROOT/out/python_lib"
39ENVIRONMENT_ROOT="$CHIP_ROOT/out/python_env"
40
PSONALl1a21a3f2021-05-25 00:03:51 +053041declare chip_detail_logging=false
Josh V [Apple]1ec61612021-08-18 12:52:27 -070042declare enable_pybindings=false
PSONALlc0345082021-06-07 22:11:12 +053043declare chip_mdns
mkardous-silabsf0d4c422021-11-05 19:51:04 -040044declare case_retry_delta
PSONALl1a21a3f2021-05-25 00:03:51 +053045
46help() {
47
Josh V [Apple]1ec61612021-08-18 12:52:27 -070048 echo "Usage: $file_name [ options ... ] [ -chip_detail_logging ChipDetailLoggingValue ] [ -chip_mdns ChipMDNSValue ] [-enable_pybindings EnableValue]"
PSONALl1a21a3f2021-05-25 00:03:51 +053049
50 echo "General Options:
51 -h, --help Display this information.
52Input Options:
53 -d, --chip_detail_logging ChipDetailLoggingValue Specify ChipDetailLoggingValue as true or false.
54 By default it is false.
55 -m, --chip_mdns ChipMDNSValue Specify ChipMDNSValue as platform or minimal.
56 By default it is minimal.
Josh V [Apple]1ec61612021-08-18 12:52:27 -070057 -p, --enable_pybindings EnableValue Specify whether to enable pybindings as python controller.
mkardous-silabsf0d4c422021-11-05 19:51:04 -040058
59 -t --time_between_case_retries MRPActiveRetryInterval Specify MRPActiveRetryInterval value
60 Default is 300 ms
PSONALl1a21a3f2021-05-25 00:03:51 +053061"
62}
63
64file_name=${0##*/}
65
66while (($#)); do
67 case $1 in
68 --help | -h)
69 help
70 exit 1
71 ;;
72 --chip_detail_logging | -d)
73 chip_detail_logging=$2
74 shift
75 ;;
76 --chip_mdns | -m)
77 chip_mdns=$2
78 shift
79 ;;
Josh V [Apple]1ec61612021-08-18 12:52:27 -070080 --enable_pybindings | -p)
81 enable_pybindings=$2
82 shift
83 ;;
mkardous-silabsf0d4c422021-11-05 19:51:04 -040084 --time_between_case_retries | -t)
85 chip_case_retry_delta=$2
86 shift
87 ;;
PSONALl1a21a3f2021-05-25 00:03:51 +053088 -*)
89 help
90 echo "Unknown Option \"$1\""
91 exit 1
92 ;;
93 esac
94 shift
95done
96
97# Print input values
mkardous-silabsf0d4c422021-11-05 19:51:04 -040098echo "Input values: chip_detail_logging = $chip_detail_logging , chip_mdns = \"$chip_mdns\", enable_pybindings = $enable_pybindings, chip_case_retry_delta=\"$chip_case_retry_delta\""
PSONALl1a21a3f2021-05-25 00:03:51 +053099
Andrei Litvine8377572021-02-04 15:22:46 -0500100# Ensure we have a compilation environment
101source "$CHIP_ROOT/scripts/activate.sh"
102
103# Generates ninja files
PSONALlc0345082021-06-07 22:11:12 +0530104[[ -n "$chip_mdns" ]] && chip_mdns_arg="chip_mdns=\"$chip_mdns\"" || chip_mdns_arg=""
mkardous-silabsf0d4c422021-11-05 19:51:04 -0400105[[ -n "$chip_case_retry_delta" ]] && chip_case_retry_arg="chip_case_retry_delta=$chip_case_retry_delta" || chip_case_retry_arg=""
Josh V [Apple]1ec61612021-08-18 12:52:27 -0700106
C Freeman3a466492021-11-12 14:15:00 -0500107gn --root="$CHIP_ROOT" gen "$OUTPUT_ROOT" --args="chip_detail_logging=$chip_detail_logging enable_pylib=$enable_pybindings enable_rtti=$enable_pybindings chip_project_config_include_dirs=[\"//config/python\"] $chip_mdns_arg $chip_case_retry_arg"
Andrei Litvine8377572021-02-04 15:22:46 -0500108
109# Compiles python files
Josh V [Apple]1ec61612021-08-18 12:52:27 -0700110# Check pybindings was requested
111if [ "$enable_pybindings" == true ]; then
Jerry Johnsf0fc7492021-11-15 13:54:24 -0800112 ninja -C "$OUTPUT_ROOT" pycontroller
Josh V [Apple]1ec61612021-08-18 12:52:27 -0700113else
Jerry Johnsf0fc7492021-11-15 13:54:24 -0800114 ninja -C "$OUTPUT_ROOT" python
Josh V [Apple]1ec61612021-08-18 12:52:27 -0700115fi
Andrei Litvine8377572021-02-04 15:22:46 -0500116
117# Create a virtual environment that has access to the built python tools
118virtualenv --clear "$ENVIRONMENT_ROOT"
119
Markus Beckereddf2b42021-12-02 08:16:46 +0100120# Activate the new environment to register the python WHL
Josh V [Apple]1ec61612021-08-18 12:52:27 -0700121
122if [ "$enable_pybindings" == true ]; then
123 WHEEL=$(ls "$OUTPUT_ROOT"/pybindings/pycontroller/pychip-*.whl | head -n 1)
124else
125 WHEEL=$(ls "$OUTPUT_ROOT"/controller/python/chip-*.whl | head -n 1)
126fi
127
Andrei Litvine8377572021-02-04 15:22:46 -0500128source "$ENVIRONMENT_ROOT"/bin/activate
129"$ENVIRONMENT_ROOT"/bin/python -m pip install --upgrade pip
Josh V [Apple]1ec61612021-08-18 12:52:27 -0700130"$ENVIRONMENT_ROOT"/bin/pip install --upgrade --force-reinstall --no-cache-dir "$WHEEL"
Andrei Litvine8377572021-02-04 15:22:46 -0500131
Andrei Litvine8377572021-02-04 15:22:46 -0500132echo ""
133echo_green "Compilation completed and WHL package installed in: "
Michael Spang98f72f82021-03-08 09:24:37 -0500134echo_blue " $ENVIRONMENT_ROOT"
Andrei Litvine8377572021-02-04 15:22:46 -0500135echo ""
136echo_green "To use please run:"
Michael Spang98f72f82021-03-08 09:24:37 -0500137echo_bold_white " source $ENVIRONMENT_ROOT/bin/activate"