Skip to content

Commit 1f4a2da

Browse files
committed
[scripts] leave running ZAP bootstrap as optional and non-default
Also added support for clean bootstrap which installs all ZAP dependency packages from scratch. Signed-off-by: Marcin Kajor <marcin.kajor@nordicsemi.no>
1 parent 5b7c9a6 commit 1f4a2da

5 files changed

Lines changed: 54 additions & 20 deletions

File tree

scripts/tools/zap/convert.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ def runArgumentsParser():
6060
parser = argparse.ArgumentParser(
6161
description='Convert .zap files to the current zap version')
6262
parser.add_argument('zap', help='Path to the application .zap file')
63-
parser.add_argument('--no-bootstrap', default=None, action='store_true',
64-
help='Prevent automatic ZAP bootstrap. By default the bootstrap is triggered')
63+
parser.add_argument('--run-bootstrap', default=None, action='store_true',
64+
help='Automatically run ZAP bootstrap. By default the bootstrap is not triggered')
6565
args = parser.parse_args()
6666

6767
zap_file = getFilePath(args.zap)
6868

69-
return zap_file, args.no_bootstrap
69+
return zap_file, args.run_bootstrap
7070

7171

7272
def detectZclFile(zapFile):
@@ -104,8 +104,8 @@ def runBootstrap():
104104

105105
def main():
106106
checkPythonVersion()
107-
zap_file, no_bootstrap = runArgumentsParser()
108-
if not no_bootstrap:
107+
zap_file, run_bootstrap = runArgumentsParser()
108+
if run_bootstrap:
109109
runBootstrap()
110110
os.chdir(CHIP_ROOT_DIR)
111111

scripts/tools/zap/generate.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ def runArgumentsParser():
9090
help='Path to the zcl templates records to use for generating artifacts (default: autodetect read from zap file)')
9191
parser.add_argument('-o', '--output-dir', default=None,
9292
help='Output directory for the generated files (default: automatically selected)')
93-
parser.add_argument('--no-bootstrap', default=None, action='store_true',
94-
help='Prevent automatic ZAP bootstrap. By default the bootstrap is triggered')
93+
parser.add_argument('--run-bootstrap', default=None, action='store_true',
94+
help='Automatically run ZAP bootstrap. By default the bootstrap is not triggered')
9595
args = parser.parse_args()
9696

9797
# By default, this script assumes that the global CHIP template is used with
@@ -115,7 +115,7 @@ def runArgumentsParser():
115115
templates_file = getFilePath(args.templates)
116116
output_dir = getDirPath(output_dir)
117117

118-
return (zap_file, zcl_file, templates_file, output_dir, args.no_bootstrap)
118+
return (zap_file, zcl_file, templates_file, output_dir, args.run_bootstrap)
119119

120120

121121
def extractGeneratedIdl(output_dir, zap_config_path):
@@ -217,8 +217,8 @@ def runBootstrap():
217217

218218
def main():
219219
checkPythonVersion()
220-
zap_file, zcl_file, templates_file, output_dir, no_bootstrap = runArgumentsParser()
221-
if not no_bootstrap:
220+
zap_file, zcl_file, templates_file, output_dir, run_bootstrap = runArgumentsParser()
221+
if run_bootstrap:
222222
runBootstrap()
223223
# The maximum memory usage is over 4GB (#15620)
224224
os.environ["NODE_OPTIONS"] = "--max-old-space-size=8192"

scripts/tools/zap/zap_bootstrap.sh

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ function _get_fullpath() {
2020
cd "$(dirname "$1")" && echo "$PWD/$(basename "$1")"
2121
}
2222

23-
echo "ZAP bootstrap started..."
23+
function _usage() {
24+
cat <<EOF
25+
Invalid arguments passed.
26+
Usage:
27+
zap_bootstrap.sh -> install and update required packages
28+
zap_bootstrap.sh -c -> run a clean bootstrap, install packages from scratch
29+
EOF
30+
exit 1
31+
}
2432

2533
set -e
2634

@@ -32,12 +40,24 @@ CHIP_ROOT="${SCRIPT_PATH%/scripts/tools/zap/zap_bootstrap.sh}"
3240
git submodule update --init third_party/zap/repo
3341

3442
cd "third_party/zap/repo"
35-
if ! npm list installed-check &>/dev/null; then
36-
npm install installed-check
37-
fi
3843

39-
if ! ./node_modules/.bin/installed-check -c &>/dev/null; then
40-
npm install
44+
if [ $# -eq 0 ]; then
45+
echo "Running ZAP bootstrap"
46+
if ! npm list installed-check &>/dev/null; then
47+
npm install installed-check
48+
fi
49+
50+
if ! ./node_modules/.bin/installed-check -c &>/dev/null; then
51+
npm install
52+
fi
53+
elif [ $# -eq 1 ] && [ "$1" = "-c" ]; then
54+
echo "Running clean ZAP bootstrap"
55+
npm ci
56+
npm run version-stamp
57+
npm rebuild canvas --update-binary
58+
npm run build-spa
59+
else
60+
_usage
4161
fi
4262
)
4363

scripts/tools/zap_convert_all.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from pathlib import Path
2020
import sys
2121
import subprocess
22+
import argparse
2223

2324
CHIP_ROOT_DIR = os.path.realpath(
2425
os.path.join(os.path.dirname(__file__), '../..'))
@@ -53,18 +54,28 @@ def getTargets():
5354
return targets
5455

5556

57+
def runArgumentsParser():
58+
parser = argparse.ArgumentParser(
59+
description='Convert all .zap files to the current zap version')
60+
parser.add_argument('--run-bootstrap', default=None, action='store_true',
61+
help='Automatically run ZAP bootstrap. By default the bootstrap is not triggered')
62+
return parser.parse_args()
63+
64+
5665
def runBootstrap():
5766
subprocess.check_call(os.path.join(CHIP_ROOT_DIR, "scripts/tools/zap/zap_bootstrap.sh"), shell=True)
5867

5968

6069
def main():
70+
args = runArgumentsParser()
6171
checkPythonVersion()
62-
runBootstrap()
72+
if args.run_bootstrap:
73+
runBootstrap()
6374
os.chdir(CHIP_ROOT_DIR)
6475

6576
targets = getTargets()
6677
for target in targets:
67-
subprocess.check_call(['./scripts/tools/zap/convert.py'] + ['--no-bootstrap'] + target)
78+
subprocess.check_call(['./scripts/tools/zap/convert.py'] + target)
6879

6980

7081
if __name__ == '__main__':

scripts/tools/zap_regen_all.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def log_command(self):
4646
def build_cmd(self):
4747
"""Builds the command line we would run to generate this target.
4848
"""
49-
cmd = [self.script, '--no-bootstrap', self.zap_config]
49+
cmd = [self.script, self.zap_config]
5050

5151
if self.template:
5252
cmd.append('-t')
@@ -94,6 +94,8 @@ def setupArgumentsParser():
9494
help='When generating tests only target, Choose which tests to generate (default: all)')
9595
parser.add_argument('--dry-run', default=False, action='store_true',
9696
help="Don't do any generation, just log what targets would be generated (default: False)")
97+
parser.add_argument('--run-bootstrap', default=None, action='store_true',
98+
help='Automatically run ZAP bootstrap. By default the bootstrap is not triggered')
9799
return parser.parse_args()
98100

99101

@@ -240,7 +242,8 @@ def main():
240242
targets = getTargets(args.type, args.tests)
241243

242244
if (not args.dry_run):
243-
runBootstrap()
245+
if (args.run_bootstrap):
246+
runBootstrap()
244247
for target in targets:
245248
target.generate()
246249

0 commit comments

Comments
 (0)