diff options
author | Jack Rosenthal <jrosenth@chromium.org> | 2021-03-25 15:07:07 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-03-29 15:40:58 +0000 |
commit | 823cb66025a9ce28dbc083ce4294dcb4753467aa (patch) | |
tree | 6a5c6fa7fb77ac841d48815a78378b5b28c6a558 /zephyr/firmware_builder.py | |
parent | 9d8f28dd760f4f0e68ed3746bb9e50dc31687859 (diff) | |
download | chrome-ec-823cb66025a9ce28dbc083ce4294dcb4753467aa.tar.gz |
zephyr: Import firmware_builder.py from zephyr-chrome repo
Bring in firmware_builder.py from zephyr-chrome.
Had to make a few changes to file paths.
Still has to be enabled in Chromite.
BUG=b:177003034
BRANCH=none
TEST=firmware_builder.py --metics=$(mktemp -d) build && \
firmware_builder.py --metrics=$(mktemp -d) test
Signed-off-by: Jack Rosenthal <jrosenth@chromium.org>
Change-Id: Ia7ad5bac2b0daab4c5eec17963cd49fe507587c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2787482
Reviewed-by: LaMont Jones <lamontjones@chromium.org>
Diffstat (limited to 'zephyr/firmware_builder.py')
-rwxr-xr-x | zephyr/firmware_builder.py | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/zephyr/firmware_builder.py b/zephyr/firmware_builder.py new file mode 100755 index 0000000000..a1a6844527 --- /dev/null +++ b/zephyr/firmware_builder.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +"""Build and test all of the Zephyr boards. + +This is the entry point for the custom firmware builder workflow recipe. +""" + +import argparse +import multiprocessing +import os +import shutil +import subprocess +import sys + +# TODO(crbug/1181505): Code outside of chromite should not be importing from +# chromite.api.gen. Import json_format after that so we get the matching one. +from chromite.api.gen.chromite.api import firmware_pb2 +from google.protobuf import json_format + + +def build(opts): + """Builds all Zephyr firmware targets""" + # TODO(b/169178847): Add appropriate metric information + metrics = firmware_pb2.FwBuildMetricList() + with open(opts.metrics, 'w') as f: + f.write(json_format.MessageToJson(metrics)) + + temp_build_dir = os.path.join('/tmp', 'zbuild') + + targets = [ + 'projects/kohaku', + 'projects/posix-ec', + 'projects/volteer', + ] + for target in targets: + if os.path.exists(temp_build_dir): + shutil.rmtree(temp_build_dir) + + print('Building {}'.format(target)) + rv = subprocess.run( + ['zmake', 'configure', '-b', '-B', temp_build_dir, target], + cwd=os.path.dirname(__file__)).returncode + if rv != 0: + return rv + return 0 + + +def test(opts): + """Runs all of the unit tests for Zephyr firmware""" + # TODO(b/169178847): Add appropriate metric information + metrics = firmware_pb2.FwTestMetricList() + with open(opts.metrics, 'w') as f: + f.write(json_format.MessageToJson(metrics)) + + return subprocess.run(['zmake', 'testall', '--fail-fast']).returncode + + +def main(args): + """Builds and tests all of the Zephyr targets and reports build metrics""" + opts = parse_args(args) + + if not hasattr(opts, 'func'): + print("Must select a valid sub command!") + return -1 + + # Run selected sub command function + return opts.func(opts) + + +def parse_args(args): + parser = argparse.ArgumentParser(description=__doc__) + + parser.add_argument( + '--cpus', + default=multiprocessing.cpu_count(), + help='The number of cores to use.', + ) + + parser.add_argument( + '--metrics', + dest='metrics', + required=True, + help='File to write the json-encoded MetricsList proto message.', + ) + + # Would make this required=True, but not available until 3.7 + sub_cmds = parser.add_subparsers() + + build_cmd = sub_cmds.add_parser('build', + help='Builds all firmware targets') + build_cmd.set_defaults(func=build) + + test_cmd = sub_cmds.add_parser('test', help='Runs all firmware unit tests') + test_cmd.set_defaults(func=test) + + return parser.parse_args(args) + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) |