diff options
author | Jett Rink <jettrink@chromium.org> | 2020-09-22 15:03:04 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-10-01 01:14:51 +0000 |
commit | 2d339f222962c312eddc27aecd09e56964fff95c (patch) | |
tree | da2a09c9a3635ea595859174c61f1cedc8bcd903 /firmware_builder.py | |
parent | c5ec264d26024e0d63550d5aaaa645495fcc5744 (diff) | |
download | chrome-ec-2d339f222962c312eddc27aecd09e56964fff95c.tar.gz |
build: add firmware_builder.py entry point
New ToT firmware builder will call firmware_builder.py to start the build
process for FW. For EC, we need to call into out existing build system.
To break up the build and test phases, we need to break out all of the
build only steps out into a separate build target (buildall_only).
BRANCH=none
BUG=b:169178847
TEST=run `firmware_builder.py build` locally and see that it builds all
EC images and also redirects stdout and stderror from sub command.
TEST=chromite/api/contrib/call_scripts/firmware__build_all_tot_firmware
run this script correctly. End-to-End tests.
Signed-off-by: Jett Rink <jettrink@chromium.org>
Change-Id: Idd039e686697ee88419e0e44aa3dc96d554b997d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2424895
Commit-Queue: Jack Rosenthal <jrosenth@chromium.org>
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'firmware_builder.py')
-rwxr-xr-x | firmware_builder.py | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/firmware_builder.py b/firmware_builder.py new file mode 100755 index 0000000000..a55eba6c9a --- /dev/null +++ b/firmware_builder.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright 2020 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 EC boards. + +This is the entry point for the custom firmware builder workflow recipe. +""" + +import argparse +import multiprocessing +import os +import subprocess +import sys + +from google.protobuf import json_format + +from chromite.api.gen.chromite.api import firmware_pb2 + +def build(opts): + """Builds all EC 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)) + return subprocess.run(['make', 'buildall_only', '-j{}'.format(opts.cpus)], + cwd=os.path.dirname(__file__)).returncode + + +def test(opts): + """Runs all of the unit tests for EC 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(['make', 'runtests', '-j{}'.format(opts.cpus)], + cwd=os.path.dirname(__file__)).returncode + + +def main(args): + """Builds and tests all of the EC 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:])) |