run_zaptool.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/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. function _get_fullpath() {
  18. cd "$(dirname "$1")" && echo "$PWD/$(basename "$1")"
  19. }
  20. set -e
  21. [[ "$1" == "--help" ]] && {
  22. echo "Usage: $0 [ZAP-file-path]" >&2
  23. exit 0
  24. }
  25. SCRIPT_PATH="$(_get_fullpath "$0")"
  26. CHIP_ROOT="${SCRIPT_PATH%/scripts/tools/zap/run_zaptool.sh}"
  27. [[ -n "$1" ]] && ZAP_ARGS="-i \"$(_get_fullpath "$1")\"" || ZAP_ARGS=""
  28. if [ ! -z "$ZAP_DEVELOPMENT_PATH" ]; then
  29. WORKING_DIR=$ZAP_DEVELOPMENT_PATH
  30. ZAP_CMD="node src-script/zap-start.js"
  31. # Make sure we don't try to munge the package.json in the ZAP repo.
  32. export ZAP_SKIP_REAL_VERSION=1
  33. "$CHIP_ROOT"/scripts/tools/zap/zap_bootstrap.sh
  34. elif [ ! -z "$ZAP_INSTALL_PATH" ]; then
  35. if [[ "$OSTYPE" == "darwin"* ]]; then
  36. ZAP_CMD="$ZAP_INSTALL_PATH/zap.app/Contents/MacOS/zap"
  37. else
  38. ZAP_CMD="$ZAP_INSTALL_PATH/zap"
  39. fi
  40. WORKING_DIR="$CHIP_ROOT"
  41. else
  42. ZAP_CMD="zap"
  43. WORKING_DIR="$CHIP_ROOT"
  44. fi
  45. (
  46. cd "$WORKING_DIR"
  47. echo "ARGS: $ZAP_ARGS"
  48. if [[ "${ZAP_ARGS[@]}" == *"/all-clusters-app.zap"* ]]; then
  49. ZCL_FILE="$CHIP_ROOT/src/app/zap-templates/zcl/zcl-with-test-extensions.json"
  50. else
  51. ZCL_FILE="$CHIP_ROOT/src/app/zap-templates/zcl/zcl.json"
  52. fi
  53. bash -c " \
  54. $ZAP_CMD \
  55. --logToStdout \
  56. --gen \"$CHIP_ROOT/src/app/zap-templates/app-templates.json\" \
  57. --zcl \"$ZCL_FILE\" \
  58. $ZAP_ARGS \
  59. "
  60. )