build_python.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (c) 2021 Project CHIP Authors
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. set -e
  18. _normpath() {
  19. python -c "import os.path; print(os.path.normpath('$@'))"
  20. }
  21. echo_green() {
  22. echo -e "\033[0;32m$*\033[0m"
  23. }
  24. echo_blue() {
  25. echo -e "\033[1;34m$*\033[0m"
  26. }
  27. echo_bold_white() {
  28. echo -e "\033[1;37m$*\033[0m"
  29. }
  30. CHIP_ROOT=$(_normpath "$(dirname "$0")/..")
  31. OUTPUT_ROOT="$CHIP_ROOT/out/python_lib"
  32. ENVIRONMENT_ROOT="$CHIP_ROOT/out/python_env"
  33. declare chip_detail_logging=false
  34. declare chip_mdns="minimal"
  35. declare clusters=true
  36. help() {
  37. echo "Usage: $file_name [ options ... ] [ -chip_detail_logging ChipDetailLoggingValue ] [ -chip_mdns ChipMDNSValue ]"
  38. echo "General Options:
  39. -h, --help Display this information.
  40. Input Options:
  41. -d, --chip_detail_logging ChipDetailLoggingValue Specify ChipDetailLoggingValue as true or false.
  42. By default it is false.
  43. -m, --chip_mdns ChipMDNSValue Specify ChipMDNSValue as platform or minimal.
  44. By default it is minimal.
  45. -c, --clusters_for_ip_commissioning true/false Specify whether to use clusters for IP commissioning.
  46. By default it is true.
  47. "
  48. }
  49. file_name=${0##*/}
  50. while (($#)); do
  51. case $1 in
  52. --help | -h)
  53. help
  54. exit 1
  55. ;;
  56. --chip_detail_logging | -d)
  57. chip_detail_logging=$2
  58. shift
  59. ;;
  60. --chip_mdns | -m)
  61. chip_mdns=$2
  62. shift
  63. ;;
  64. --clusters_for_ip_commissioning | -c)
  65. clusters=$2
  66. shift
  67. ;;
  68. -*)
  69. help
  70. echo "Unknown Option \"$1\""
  71. exit 1
  72. ;;
  73. esac
  74. shift
  75. done
  76. # Print input values
  77. echo "Input values: chip_detail_logging = $chip_detail_logging , chip_mdns = \"$chip_mdns\""
  78. # Ensure we have a compilation environment
  79. source "$CHIP_ROOT/scripts/activate.sh"
  80. # Generates ninja files
  81. gn --root="$CHIP_ROOT" gen "$OUTPUT_ROOT" --args="chip_detail_logging=$chip_detail_logging chip_mdns=\"$chip_mdns\" chip_use_clusters_for_ip_commissioning=$clusters"
  82. # Compiles python files
  83. ninja -C "$OUTPUT_ROOT" python
  84. # Create a virtual environment that has access to the built python tools
  85. virtualenv --clear "$ENVIRONMENT_ROOT"
  86. # Activate the new enviroment to register the python WHL
  87. source "$ENVIRONMENT_ROOT"/bin/activate
  88. "$ENVIRONMENT_ROOT"/bin/python -m pip install --upgrade pip
  89. "$ENVIRONMENT_ROOT"/bin/pip install "$OUTPUT_ROOT"/controller/python/chip-*.whl
  90. echo ""
  91. echo_green "Compilation completed and WHL package installed in: "
  92. echo_blue " $ENVIRONMENT_ROOT"
  93. echo ""
  94. echo_green "To use please run:"
  95. echo_bold_white " source $ENVIRONMENT_ROOT/bin/activate"