Skip to content

Commit

Permalink
[scripts] leave running ZAP bootstrap as optional and non-default
Browse files Browse the repository at this point in the history
Also added support for clean bootstrap which installs all ZAP
dependency packages from scratch.

Signed-off-by: Marcin Kajor <marcin.kajor@nordicsemi.no>
  • Loading branch information
markaj-nordic committed Sep 29, 2022
1 parent 5b7c9a6 commit 1f4a2da
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 20 deletions.
10 changes: 5 additions & 5 deletions scripts/tools/zap/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ def runArgumentsParser():
parser = argparse.ArgumentParser(
description='Convert .zap files to the current zap version')
parser.add_argument('zap', help='Path to the application .zap file')
parser.add_argument('--no-bootstrap', default=None, action='store_true',
help='Prevent automatic ZAP bootstrap. By default the bootstrap is triggered')
parser.add_argument('--run-bootstrap', default=None, action='store_true',
help='Automatically run ZAP bootstrap. By default the bootstrap is not triggered')
args = parser.parse_args()

zap_file = getFilePath(args.zap)

return zap_file, args.no_bootstrap
return zap_file, args.run_bootstrap


def detectZclFile(zapFile):
Expand Down Expand Up @@ -104,8 +104,8 @@ def runBootstrap():

def main():
checkPythonVersion()
zap_file, no_bootstrap = runArgumentsParser()
if not no_bootstrap:
zap_file, run_bootstrap = runArgumentsParser()
if run_bootstrap:
runBootstrap()
os.chdir(CHIP_ROOT_DIR)

Expand Down
10 changes: 5 additions & 5 deletions scripts/tools/zap/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def runArgumentsParser():
help='Path to the zcl templates records to use for generating artifacts (default: autodetect read from zap file)')
parser.add_argument('-o', '--output-dir', default=None,
help='Output directory for the generated files (default: automatically selected)')
parser.add_argument('--no-bootstrap', default=None, action='store_true',
help='Prevent automatic ZAP bootstrap. By default the bootstrap is triggered')
parser.add_argument('--run-bootstrap', default=None, action='store_true',
help='Automatically run ZAP bootstrap. By default the bootstrap is not triggered')
args = parser.parse_args()

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

return (zap_file, zcl_file, templates_file, output_dir, args.no_bootstrap)
return (zap_file, zcl_file, templates_file, output_dir, args.run_bootstrap)


def extractGeneratedIdl(output_dir, zap_config_path):
Expand Down Expand Up @@ -217,8 +217,8 @@ def runBootstrap():

def main():
checkPythonVersion()
zap_file, zcl_file, templates_file, output_dir, no_bootstrap = runArgumentsParser()
if not no_bootstrap:
zap_file, zcl_file, templates_file, output_dir, run_bootstrap = runArgumentsParser()
if run_bootstrap:
runBootstrap()
# The maximum memory usage is over 4GB (#15620)
os.environ["NODE_OPTIONS"] = "--max-old-space-size=8192"
Expand Down
32 changes: 26 additions & 6 deletions scripts/tools/zap/zap_bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ function _get_fullpath() {
cd "$(dirname "$1")" && echo "$PWD/$(basename "$1")"
}

echo "ZAP bootstrap started..."
function _usage() {
cat <<EOF
Invalid arguments passed.
Usage:
zap_bootstrap.sh -> install and update required packages
zap_bootstrap.sh -c -> run a clean bootstrap, install packages from scratch
EOF
exit 1
}

set -e

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

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

if ! ./node_modules/.bin/installed-check -c &>/dev/null; then
npm install
if [ $# -eq 0 ]; then
echo "Running ZAP bootstrap"
if ! npm list installed-check &>/dev/null; then
npm install installed-check
fi

if ! ./node_modules/.bin/installed-check -c &>/dev/null; then
npm install
fi
elif [ $# -eq 1 ] && [ "$1" = "-c" ]; then
echo "Running clean ZAP bootstrap"
npm ci
npm run version-stamp
npm rebuild canvas --update-binary
npm run build-spa
else
_usage
fi
)

Expand Down
15 changes: 13 additions & 2 deletions scripts/tools/zap_convert_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from pathlib import Path
import sys
import subprocess
import argparse

CHIP_ROOT_DIR = os.path.realpath(
os.path.join(os.path.dirname(__file__), '../..'))
Expand Down Expand Up @@ -53,18 +54,28 @@ def getTargets():
return targets


def runArgumentsParser():
parser = argparse.ArgumentParser(
description='Convert all .zap files to the current zap version')
parser.add_argument('--run-bootstrap', default=None, action='store_true',
help='Automatically run ZAP bootstrap. By default the bootstrap is not triggered')
return parser.parse_args()


def runBootstrap():
subprocess.check_call(os.path.join(CHIP_ROOT_DIR, "scripts/tools/zap/zap_bootstrap.sh"), shell=True)


def main():
args = runArgumentsParser()
checkPythonVersion()
runBootstrap()
if args.run_bootstrap:
runBootstrap()
os.chdir(CHIP_ROOT_DIR)

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


if __name__ == '__main__':
Expand Down
7 changes: 5 additions & 2 deletions scripts/tools/zap_regen_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def log_command(self):
def build_cmd(self):
"""Builds the command line we would run to generate this target.
"""
cmd = [self.script, '--no-bootstrap', self.zap_config]
cmd = [self.script, self.zap_config]

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


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

if (not args.dry_run):
runBootstrap()
if (args.run_bootstrap):
runBootstrap()
for target in targets:
target.generate()

Expand Down

0 comments on commit 1f4a2da

Please sign in to comment.