Andrei Litvin | e837757 | 2021-02-04 15:22:46 -0500 | [diff] [blame] | 1 | #!/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 | |
| 19 | set -e |
| 20 | |
Michael Spang | 98f72f8 | 2021-03-08 09:24:37 -0500 | [diff] [blame] | 21 | _normpath() { |
| 22 | python -c "import os.path; print(os.path.normpath('$@'))" |
| 23 | } |
| 24 | |
Andrei Litvin | e837757 | 2021-02-04 15:22:46 -0500 | [diff] [blame] | 25 | echo_green() { |
| 26 | echo -e "\033[0;32m$*\033[0m" |
| 27 | } |
| 28 | |
| 29 | echo_blue() { |
| 30 | echo -e "\033[1;34m$*\033[0m" |
| 31 | } |
| 32 | |
| 33 | echo_bold_white() { |
| 34 | echo -e "\033[1;37m$*\033[0m" |
| 35 | } |
| 36 | |
Michael Spang | 98f72f8 | 2021-03-08 09:24:37 -0500 | [diff] [blame] | 37 | CHIP_ROOT=$(_normpath "$(dirname "$0")/..") |
Andrei Litvin | e837757 | 2021-02-04 15:22:46 -0500 | [diff] [blame] | 38 | OUTPUT_ROOT="$CHIP_ROOT/out/python_lib" |
| 39 | ENVIRONMENT_ROOT="$CHIP_ROOT/out/python_env" |
| 40 | |
PSONALl | 1a21a3f | 2021-05-25 00:03:51 +0530 | [diff] [blame] | 41 | declare chip_detail_logging=false |
Josh V [Apple] | 1ec6161 | 2021-08-18 12:52:27 -0700 | [diff] [blame] | 42 | declare enable_pybindings=false |
PSONALl | c034508 | 2021-06-07 22:11:12 +0530 | [diff] [blame] | 43 | declare chip_mdns |
mkardous-silabs | f0d4c42 | 2021-11-05 19:51:04 -0400 | [diff] [blame] | 44 | declare case_retry_delta |
PSONALl | 1a21a3f | 2021-05-25 00:03:51 +0530 | [diff] [blame] | 45 | |
| 46 | help() { |
| 47 | |
Josh V [Apple] | 1ec6161 | 2021-08-18 12:52:27 -0700 | [diff] [blame] | 48 | echo "Usage: $file_name [ options ... ] [ -chip_detail_logging ChipDetailLoggingValue ] [ -chip_mdns ChipMDNSValue ] [-enable_pybindings EnableValue]" |
PSONALl | 1a21a3f | 2021-05-25 00:03:51 +0530 | [diff] [blame] | 49 | |
| 50 | echo "General Options: |
| 51 | -h, --help Display this information. |
| 52 | Input 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] | 1ec6161 | 2021-08-18 12:52:27 -0700 | [diff] [blame] | 57 | -p, --enable_pybindings EnableValue Specify whether to enable pybindings as python controller. |
mkardous-silabs | f0d4c42 | 2021-11-05 19:51:04 -0400 | [diff] [blame] | 58 | |
| 59 | -t --time_between_case_retries MRPActiveRetryInterval Specify MRPActiveRetryInterval value |
| 60 | Default is 300 ms |
PSONALl | 1a21a3f | 2021-05-25 00:03:51 +0530 | [diff] [blame] | 61 | " |
| 62 | } |
| 63 | |
| 64 | file_name=${0##*/} |
| 65 | |
| 66 | while (($#)); 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] | 1ec6161 | 2021-08-18 12:52:27 -0700 | [diff] [blame] | 80 | --enable_pybindings | -p) |
| 81 | enable_pybindings=$2 |
| 82 | shift |
| 83 | ;; |
mkardous-silabs | f0d4c42 | 2021-11-05 19:51:04 -0400 | [diff] [blame] | 84 | --time_between_case_retries | -t) |
| 85 | chip_case_retry_delta=$2 |
| 86 | shift |
| 87 | ;; |
PSONALl | 1a21a3f | 2021-05-25 00:03:51 +0530 | [diff] [blame] | 88 | -*) |
| 89 | help |
| 90 | echo "Unknown Option \"$1\"" |
| 91 | exit 1 |
| 92 | ;; |
| 93 | esac |
| 94 | shift |
| 95 | done |
| 96 | |
| 97 | # Print input values |
mkardous-silabs | f0d4c42 | 2021-11-05 19:51:04 -0400 | [diff] [blame] | 98 | echo "Input values: chip_detail_logging = $chip_detail_logging , chip_mdns = \"$chip_mdns\", enable_pybindings = $enable_pybindings, chip_case_retry_delta=\"$chip_case_retry_delta\"" |
PSONALl | 1a21a3f | 2021-05-25 00:03:51 +0530 | [diff] [blame] | 99 | |
Andrei Litvin | e837757 | 2021-02-04 15:22:46 -0500 | [diff] [blame] | 100 | # Ensure we have a compilation environment |
| 101 | source "$CHIP_ROOT/scripts/activate.sh" |
| 102 | |
| 103 | # Generates ninja files |
PSONALl | c034508 | 2021-06-07 22:11:12 +0530 | [diff] [blame] | 104 | [[ -n "$chip_mdns" ]] && chip_mdns_arg="chip_mdns=\"$chip_mdns\"" || chip_mdns_arg="" |
mkardous-silabs | f0d4c42 | 2021-11-05 19:51:04 -0400 | [diff] [blame] | 105 | [[ -n "$chip_case_retry_delta" ]] && chip_case_retry_arg="chip_case_retry_delta=$chip_case_retry_delta" || chip_case_retry_arg="" |
Josh V [Apple] | 1ec6161 | 2021-08-18 12:52:27 -0700 | [diff] [blame] | 106 | |
C Freeman | 3a46649 | 2021-11-12 14:15:00 -0500 | [diff] [blame] | 107 | gn --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 Litvin | e837757 | 2021-02-04 15:22:46 -0500 | [diff] [blame] | 108 | |
| 109 | # Compiles python files |
Josh V [Apple] | 1ec6161 | 2021-08-18 12:52:27 -0700 | [diff] [blame] | 110 | # Check pybindings was requested |
| 111 | if [ "$enable_pybindings" == true ]; then |
Jerry Johns | f0fc749 | 2021-11-15 13:54:24 -0800 | [diff] [blame] | 112 | ninja -C "$OUTPUT_ROOT" pycontroller |
Josh V [Apple] | 1ec6161 | 2021-08-18 12:52:27 -0700 | [diff] [blame] | 113 | else |
Jerry Johns | f0fc749 | 2021-11-15 13:54:24 -0800 | [diff] [blame] | 114 | ninja -C "$OUTPUT_ROOT" python |
Josh V [Apple] | 1ec6161 | 2021-08-18 12:52:27 -0700 | [diff] [blame] | 115 | fi |
Andrei Litvin | e837757 | 2021-02-04 15:22:46 -0500 | [diff] [blame] | 116 | |
| 117 | # Create a virtual environment that has access to the built python tools |
| 118 | virtualenv --clear "$ENVIRONMENT_ROOT" |
| 119 | |
Markus Becker | eddf2b4 | 2021-12-02 08:16:46 +0100 | [diff] [blame] | 120 | # Activate the new environment to register the python WHL |
Josh V [Apple] | 1ec6161 | 2021-08-18 12:52:27 -0700 | [diff] [blame] | 121 | |
| 122 | if [ "$enable_pybindings" == true ]; then |
| 123 | WHEEL=$(ls "$OUTPUT_ROOT"/pybindings/pycontroller/pychip-*.whl | head -n 1) |
| 124 | else |
| 125 | WHEEL=$(ls "$OUTPUT_ROOT"/controller/python/chip-*.whl | head -n 1) |
| 126 | fi |
| 127 | |
Andrei Litvin | e837757 | 2021-02-04 15:22:46 -0500 | [diff] [blame] | 128 | source "$ENVIRONMENT_ROOT"/bin/activate |
| 129 | "$ENVIRONMENT_ROOT"/bin/python -m pip install --upgrade pip |
Josh V [Apple] | 1ec6161 | 2021-08-18 12:52:27 -0700 | [diff] [blame] | 130 | "$ENVIRONMENT_ROOT"/bin/pip install --upgrade --force-reinstall --no-cache-dir "$WHEEL" |
Andrei Litvin | e837757 | 2021-02-04 15:22:46 -0500 | [diff] [blame] | 131 | |
Andrei Litvin | e837757 | 2021-02-04 15:22:46 -0500 | [diff] [blame] | 132 | echo "" |
| 133 | echo_green "Compilation completed and WHL package installed in: " |
Michael Spang | 98f72f8 | 2021-03-08 09:24:37 -0500 | [diff] [blame] | 134 | echo_blue " $ENVIRONMENT_ROOT" |
Andrei Litvin | e837757 | 2021-02-04 15:22:46 -0500 | [diff] [blame] | 135 | echo "" |
| 136 | echo_green "To use please run:" |
Michael Spang | 98f72f8 | 2021-03-08 09:24:37 -0500 | [diff] [blame] | 137 | echo_bold_white " source $ENVIRONMENT_ROOT/bin/activate" |