Skip to content

Commit 2d339f2

Browse files
Jett RinkCommit Bot
Jett Rink
authored and
Commit Bot
committed
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 <[email protected]> Change-Id: Idd039e686697ee88419e0e44aa3dc96d554b997d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2424895 Commit-Queue: Jack Rosenthal <[email protected]> Reviewed-by: Jack Rosenthal <[email protected]>
1 parent c5ec264 commit 2d339f2

File tree

2 files changed

+88
-2
lines changed

2 files changed

+88
-2
lines changed

Makefile.rules

+5-2
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,13 @@ build_boards: | $(FAILED_BOARDS_DIR)
198198
@rm -f $(FAILED_BOARDS_DIR)/*
199199
$(MAKE) try_build_boards
200200

201-
.PHONY: buildall
202-
buildall: build_boards build_cros_ec_commands
201+
.PHONY: buildall_only
202+
buildall_only: build_boards build_cros_ec_commands
203203
$(MAKE) build_cts
204204
$(MAKE) buildfuzztests
205+
206+
.PHONY: buildall
207+
buildall: buildall_only
205208
$(MAKE) runtests
206209
@touch .tests-passed
207210
@echo "$@ completed successfully!"

firmware_builder.py

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
# Copyright 2020 The Chromium OS Authors. All rights reserved.
4+
# Use of this source code is governed by a BSD-style license that can be
5+
# found in the LICENSE file.
6+
"""Build and test all of the EC boards.
7+
8+
This is the entry point for the custom firmware builder workflow recipe.
9+
"""
10+
11+
import argparse
12+
import multiprocessing
13+
import os
14+
import subprocess
15+
import sys
16+
17+
from google.protobuf import json_format
18+
19+
from chromite.api.gen.chromite.api import firmware_pb2
20+
21+
def build(opts):
22+
"""Builds all EC firmware targets"""
23+
# TODO(b/169178847): Add appropriate metric information
24+
metrics = firmware_pb2.FwBuildMetricList()
25+
with open(opts.metrics, 'w') as f:
26+
f.write(json_format.MessageToJson(metrics))
27+
return subprocess.run(['make', 'buildall_only', '-j{}'.format(opts.cpus)],
28+
cwd=os.path.dirname(__file__)).returncode
29+
30+
31+
def test(opts):
32+
"""Runs all of the unit tests for EC firmware"""
33+
# TODO(b/169178847): Add appropriate metric information
34+
metrics = firmware_pb2.FwTestMetricList()
35+
with open(opts.metrics, 'w') as f:
36+
f.write(json_format.MessageToJson(metrics))
37+
return subprocess.run(['make', 'runtests', '-j{}'.format(opts.cpus)],
38+
cwd=os.path.dirname(__file__)).returncode
39+
40+
41+
def main(args):
42+
"""Builds and tests all of the EC targets and reports build metrics"""
43+
opts = parse_args(args)
44+
45+
if not hasattr(opts, 'func'):
46+
print("Must select a valid sub command!")
47+
return -1
48+
49+
# Run selected sub command function
50+
return opts.func(opts)
51+
52+
53+
def parse_args(args):
54+
parser = argparse.ArgumentParser(description=__doc__)
55+
56+
parser.add_argument(
57+
'--cpus',
58+
default=multiprocessing.cpu_count(),
59+
help='The number of cores to use.',
60+
)
61+
62+
parser.add_argument(
63+
'--metrics',
64+
dest='metrics',
65+
required=True,
66+
help='File to write the json-encoded MetricsList proto message.',
67+
)
68+
69+
# Would make this required=True, but not available until 3.7
70+
sub_cmds = parser.add_subparsers()
71+
72+
build_cmd = sub_cmds.add_parser('build',
73+
help='Builds all firmware targets')
74+
build_cmd.set_defaults(func=build)
75+
76+
test_cmd = sub_cmds.add_parser('test', help='Runs all firmware unit tests')
77+
test_cmd.set_defaults(func=test)
78+
79+
return parser.parse_args(args)
80+
81+
82+
if __name__ == '__main__':
83+
sys.exit(main(sys.argv[1:]))

0 commit comments

Comments
 (0)