-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
run_zaptool.sh
executable file
·151 lines (123 loc) · 4.35 KB
/
run_zaptool.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env bash
#
# Copyright (c) 2021-2024 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
readonly ZAP_CMD_DEFAULT="zap"
ZAP_CMD="$ZAP_CMD_DEFAULT"
ZAP_FILE=""
function _get_fullpath() {
cd "$(dirname "$1")" >/dev/null && echo "$PWD/$(basename "$1")"
}
function _print_usage() {
local name="$(basename "${0}")"
local status="${1}"
echo "Usage: $name [ option ... ] [ <ZAP file path> ]"
if [ "$status" -ne 0 ]; then
echo "Try '$name -h' for more information."
fi
if [ "$status" -ne 1 ]; then
echo ""
echo "ZAP Tool Wrapper"
echo ""
echo " General Options:"
echo ""
echo " -h, --help Display this help, then exit."
echo " --zap ZAP Use the zap program ZAP as the zap executable "
echo " to run (default: $ZAP_CMD_DEFAULT)."
echo ""
echo " Some influential environment variables:"
echo ""
echo " ZAP_DEVELOPMENT_PATH The path to a zap development environment. This "
echo " is likely a zap checkout, used for local "
echo " development (current: \"${ZAP_DEVELOPMENT_PATH:-<null>}\")."
echo ""
echo " If set, this overrides both the '--zap' option "
echo " and the 'ZAP_INTALL_PATH' environment variable."
echo " ZAP_INSTALL_PATH The path where the 'zap' executable exists. "
echo " This may be used if 'zap' is NOT in the current "
echo " PATH (current: \"${ZAP_INSTALL_PATH:-<null>}\")."
echo ""
echo " If set, this overrides the '--zap' option."
echo ""
fi
exit "$status"
}
# Main
set -e
# Command Line Option Parsing
while [ "${#}" -gt 0 ]; do
case "${1}" in
-h | --help)
_print_usage 0
;;
--zap)
ZAP_CMD="${2}"
shift 2
;;
-*)
echo "ERROR: Unknown or invalid option: '${1}'" >&2
_print_usage 1
;;
*)
if [ -z "$ZAP_FILE" ]; then
ZAP_FILE="${1}"
shift 1
else
echo "ERROR: Unexpected argument: '${1}'" >&2
_print_usage 1
fi
;;
esac
done
SCRIPT_PATH="$(_get_fullpath "$0")"
CHIP_ROOT="${SCRIPT_PATH%/scripts/tools/zap/run_zaptool.sh}"
[[ -n "${ZAP_FILE}" ]] && ZAP_ARGS="-i \"$(_get_fullpath "$ZAP_FILE")\"" || ZAP_ARGS=""
if [[ -z "$ZAP_INSTALL_PATH" && -n "$PW_ZAP_CIPD_INSTALL_DIR" ]]; then
ZAP_INSTALL_PATH="$PW_ZAP_CIPD_INSTALL_DIR"
fi
if [ -n "$ZAP_DEVELOPMENT_PATH" ]; then
WORKING_DIR=$ZAP_DEVELOPMENT_PATH
ZAP_CMD="node src-script/zap-start.js"
# Make sure we don't try to munge the package.json in the ZAP repo.
export ZAP_SKIP_REAL_VERSION=1
"$CHIP_ROOT"/scripts/tools/zap/zap_bootstrap.sh
elif [ -n "$ZAP_INSTALL_PATH" ]; then
if [[ "$OSTYPE" == "darwin"* ]]; then
ZAP_CMD="$ZAP_INSTALL_PATH/zap.app/Contents/MacOS/zap"
else
ZAP_CMD="$ZAP_INSTALL_PATH/zap"
fi
WORKING_DIR="$CHIP_ROOT"
else
[ -z "$ZAP_CMD" ] && ZAP_CMD="$ZAP_CMD_DEFAULT"
WORKING_DIR="$CHIP_ROOT"
fi
(
cd "$WORKING_DIR"
echo "CMD: $ZAP_CMD"
echo "ARGS: $ZAP_ARGS"
if [[ "${ZAP_ARGS[*]}" == *"/all-clusters-app.zap"* ]]; then
ZCL_FILE="$CHIP_ROOT/src/app/zap-templates/zcl/zcl-with-test-extensions.json"
else
ZCL_FILE="$CHIP_ROOT/src/app/zap-templates/zcl/zcl.json"
fi
bash -c " \
$ZAP_CMD \
--logToStdout \
--gen \"$CHIP_ROOT/src/app/zap-templates/app-templates.json\" \
--zcl \"$ZCL_FILE\" \
$ZAP_ARGS \
"
)