blob: 894ea1bad61c8b58a26fd8b13ea3030937559482 [file] [log] [blame]
Markus Beckereddf2b42021-12-02 08:16:46 +01001#!/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
21_normpath() {
22 python -c "import os.path; print(os.path.normpath('$@'))"
23}
24
25echo_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
37CHIP_ROOT=$(_normpath "$(dirname "$0")/..")
38OUTPUT_ROOT="$CHIP_ROOT/out/python_lib"
39ENVIRONMENT_ROOT="$CHIP_ROOT/out/python_env"
40
41declare chip_detail_logging=false
42declare enable_pybindings=false
43declare chip_mdns
Markus Beckereddf2b42021-12-02 08:16:46 +010044
45help() {
46
47 echo "Usage: $file_name [ options ... ] [ -chip_detail_logging ChipDetailLoggingValue ] [ -chip_mdns ChipMDNSValue ] [-enable_pybindings EnableValue]"
48
49 echo "General Options:
50 -h, --help Display this information.
51Input Options:
52 -d, --chip_detail_logging ChipDetailLoggingValue Specify ChipDetailLoggingValue as true or false.
53 By default it is false.
54 -m, --chip_mdns ChipMDNSValue Specify ChipMDNSValue as platform or minimal.
55 By default it is minimal.
Markus Beckereddf2b42021-12-02 08:16:46 +010056 -p, --enable_pybindings EnableValue Specify whether to enable pybindings as python controller.
57"
58}
59
60file_name=${0##*/}
61
62while (($#)); do
63 case $1 in
64 --help | -h)
65 help
66 exit 1
67 ;;
68 --chip_detail_logging | -d)
69 chip_detail_logging=$2
70 shift
71 ;;
72 --chip_mdns | -m)
73 chip_mdns=$2
74 shift
75 ;;
Markus Beckereddf2b42021-12-02 08:16:46 +010076 --enable_pybindings | -p)
77 enable_pybindings=$2
78 shift
79 ;;
80 -*)
81 help
82 echo "Unknown Option \"$1\""
83 exit 1
84 ;;
85 esac
86 shift
87done
88
89# Print input values
90echo "Input values: chip_detail_logging = $chip_detail_logging , chip_mdns = \"$chip_mdns\", enable_pybindings = $enable_pybindings"
91
92# Ensure we have a compilation environment
93source "$CHIP_ROOT/scripts/activate.sh"
94
95# Generates ninja files
96[[ -n "$chip_mdns" ]] && chip_mdns_arg="chip_mdns=\"$chip_mdns\"" || chip_mdns_arg=""
97
98chip_data_model_arg="chip_data_model=\"///examples/lighting-app/lighting-common\""
99
Stefan Agner41e474d2022-06-28 19:55:47 +0200100gn --root="$CHIP_ROOT" gen "$OUTPUT_ROOT" --args="chip_detail_logging=$chip_detail_logging enable_pylib=$enable_pybindings enable_rtti=$enable_pybindings $chip_mdns_arg chip_controller=false $chip_data_model_arg"
Markus Beckereddf2b42021-12-02 08:16:46 +0100101
102# Compiles python files
103# Check pybindings was requested
104if [ "$enable_pybindings" == true ]; then
105 ninja -v -C "$OUTPUT_ROOT" pycontroller
106else
Sandeep Mistry2ed6dcb2022-09-14 16:16:20 -0400107 ninja -v -C "$OUTPUT_ROOT" chip-core
Markus Beckereddf2b42021-12-02 08:16:46 +0100108fi
109
110# Create a virtual environment that has access to the built python tools
111virtualenv --clear "$ENVIRONMENT_ROOT"
112
113# Activate the new environment to register the python WHL
114
115if [ "$enable_pybindings" == true ]; then
Stefan Agner61dd4d02022-07-13 23:57:03 +0200116 WHEEL=("$OUTPUT_ROOT"/pybindings/pycontroller/pychip-*.whl)
Markus Beckereddf2b42021-12-02 08:16:46 +0100117else
Sandeep Mistry2ed6dcb2022-09-14 16:16:20 -0400118 WHEEL=("$OUTPUT_ROOT"/controller/python/chip_core*.whl)
Markus Beckereddf2b42021-12-02 08:16:46 +0100119fi
120
121source "$ENVIRONMENT_ROOT"/bin/activate
122"$ENVIRONMENT_ROOT"/bin/python -m pip install --upgrade pip
Stefan Agner61dd4d02022-07-13 23:57:03 +0200123"$ENVIRONMENT_ROOT"/bin/pip install --upgrade --force-reinstall --no-cache-dir "${WHEEL[@]}"
Markus Beckereddf2b42021-12-02 08:16:46 +0100124
125echo ""
126echo_green "Compilation completed and WHL package installed in: "
127echo_blue " $ENVIRONMENT_ROOT"
128echo ""
129echo_green "To use please run:"
130echo_bold_white " source $ENVIRONMENT_ROOT/bin/activate"