summaryrefslogtreecommitdiff
path: root/firmware_builder.py
diff options
context:
space:
mode:
authorKevin Shelton <kmshelton@chromium.org>2021-01-07 00:04:25 +0000
committerCommit Bot <commit-bot@chromium.org>2021-02-05 04:33:22 +0000
commitd26a40c17385d3abd95e503a8af6fb3cf88ed123 (patch)
treef4280febc7876f7a44b99c37e78adbdb61f1a342 /firmware_builder.py
parent93b8c74b6f20bf67e96b68270932d27f8d4c263d (diff)
downloadchrome-ec-d26a40c17385d3abd95e503a8af6fb3cf88ed123.tar.gz
firmware_builder: add artifact bundling
Add a new command to bundle artifacts into an (optionally specified) directory and write associated metadata to an (optionally specified) file. BUG=b:176926834 BRANCH=none TEST=./firmware_builder.py --metrics=/tmp/metrics bundle, ./firmware_builder.py --output-dir=/tmp/testbundle --metrics=/tmp/metrics --metadata=/tmp/testmetadata bundle, inspected that the file utility reports a sample resultant artifact as bzip2 compressed data Signed-off-by: Kevin Shelton <kmshelton@chromium.org> Change-Id: Ic58fecd3e3d572acfa1798c0ab15a4c8c558f908 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2643803 Reviewed-by: LaMont Jones <lamontjones@chromium.org> Commit-Queue: LaMont Jones <lamontjones@chromium.org> Tested-by: LaMont Jones <lamontjones@chromium.org>
Diffstat (limited to 'firmware_builder.py')
-rwxr-xr-xfirmware_builder.py52
1 files changed, 49 insertions, 3 deletions
diff --git a/firmware_builder.py b/firmware_builder.py
index 940412af06..243534230a 100755
--- a/firmware_builder.py
+++ b/firmware_builder.py
@@ -3,9 +3,10 @@
# 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.
+"""Build, bundle, or test all of the EC boards.
-This is the entry point for the custom firmware builder workflow recipe.
+This is the entry point for the custom firmware builder workflow recipe. It
+gets invoked by chromite/api/controller/firmware.py.
"""
import argparse
@@ -18,6 +19,9 @@ from google.protobuf import json_format
from chromite.api.gen.chromite.api import firmware_pb2
+DEFAULT_BUNDLE_DIRECTORY = '/tmp/artifact_bundles'
+DEFAULT_BUNDLE_METADATA_FILE = '/tmp/artifact_bundle_metadata'
+
def build(opts):
"""Builds all EC firmware targets"""
@@ -30,6 +34,29 @@ def build(opts):
check=True)
+def bundle(opts):
+ """Bundles the artifacts from each target into its own tarball."""
+ bundle_dir = opts.output_dir if opts.output_dir else DEFAULT_BUNDLE_DIRECTORY
+ if not os.path.isdir(bundle_dir):
+ os.mkdir(bundle_dir)
+ for build_target in os.listdir(
+ os.path.join(os.path.dirname(__file__), 'build')):
+ subprocess.run([
+ 'tar', 'cvfj',
+ os.path.join(
+ bundle_dir, ''.join([
+ build_target, '.firmware_from_source.tar.bz2'
+ ])), '--exclude=\'*.o\'', '.'
+ ],
+ cwd=os.path.join(os.path.dirname(__file__), 'build',
+ build_target),
+ check=True)
+ bundle_metadata_file = opts.metadata if opts.metadata else DEFAULT_BUNDLE_METADATA_FILE
+ # TODO(kmshelton): Populate the metatadata contents when it is defined in
+ # infra/proto/src/chromite/api/firmware.proto.
+ os.mknod(bundle_metadata_file)
+
+
def test(opts):
"""Runs all of the unit tests for EC firmware"""
# TODO(b/169178847): Add appropriate metric information
@@ -52,7 +79,7 @@ def test(opts):
def main(args):
- """Builds and tests all of the EC targets and reports build metrics."""
+ """Builds, bundles, or tests all of the EC targets and reports build metrics."""
opts = parse_args(args)
if not hasattr(opts, 'func'):
@@ -84,6 +111,20 @@ def parse_args(args):
help='File to write the json-encoded MetricsList proto message.',
)
+ parser.add_argument(
+ '--metadata',
+ required=False,
+ help=
+ 'Full pathname for the file in which to write build artifact metadata.',
+ )
+
+ parser.add_argument(
+ '--output-dir',
+ required=False,
+ help=
+ 'Full pathanme for the directory in which to bundle build artifacts.',
+ )
+
# Would make this required=True, but not available until 3.7
sub_cmds = parser.add_subparsers()
@@ -91,6 +132,11 @@ def parse_args(args):
help='Builds all firmware targets')
build_cmd.set_defaults(func=build)
+ build_cmd = sub_cmds.add_parser('bundle',
+ help='Creates a tarball containing build '
+ 'artifacts from all firmware targets')
+ build_cmd.set_defaults(func=bundle)
+
test_cmd = sub_cmds.add_parser('test', help='Runs all firmware unit tests')
test_cmd.set_defaults(func=test)