new_variant: add support for the BRANCH field
Allow specifying a value for the BRANCH field in commit messages
for those repos (coreboot and EC) that use it.
Update the commit message for coreboot to add the "mb/google" path
prefix.
BUG=b:172936732, b:171427763
TEST=Test the individual scripts and new_variant.py to ensure that
the BREANCH field is handled correctly.
```
CB_SRC_DIR=/mnt/host/source/src/third_party/coreboot \
./create_coreboot_variant.sh hatch hatch tiamat
pushd /mnt/host/source/src/third_party/coreboot
git show
```
Check the commit message for BRANCH=None
```
repo abandon coreboot_tiamat_20201119 .
popd
CB_SRC_DIR=/mnt/host/source/src/third_party/coreboot \
NEW_VARIANT_BRANCH=firmware ./create_coreboot_variant.sh hatch hatch tiamat
pushd /mnt/host/source/src/third_party/coreboot
git show
```
Check the commit message for BRANCH=Firmware
```
repo abandon coreboot_tiamat_20201119 .
popd
./create_initial_ec_image.sh hatch tiamat
pushd /mnt/host/source/src/platform/ec
git show
```
Check the commit message for BRANCH=None
```
repo abandon create_tiamat_20201119 .
popd
NEW_VARIANT_BRANCH=firmware ./create_initial_ec_image.sh hatch tiamat
pushd /mnt/host/source/src/platform/ec
git show
```
Check the commit message for BRANCH=Firmware
```
repo abandon create_tiamat_20201119 .
popd
./new_variant.py --board=hatch --variant=tiamat --branch=firmware
```
Generate the fitimage when prompted
```
./new_variant.py --continue
```
new_variant stops and asks you to push to coreboot. Don't. Instead,
```
pushd /mnt/host/source/src/third_party/coreboot
git show
```
Check the commit message for BRANCH=Firmware
```
popd
pushd /mnt/host/source/src/platform/ec
git show
```
Check the commit message for BRANCH=Firmware
```
popd
./new_variant.py --abort
```
Change-Id: I6ad70f4d1d0cef5a1f73e879f0cb4d3bb62918c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/2549435
Commit-Queue: Paul Fagerburg <pfagerburg@chromium.org>
Tested-by: Paul Fagerburg <pfagerburg@chromium.org>
Reviewed-by: Martin Roth <martinroth@google.com>
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
diff --git a/contrib/variant/create_coreboot_variant.sh b/contrib/variant/create_coreboot_variant.sh
index 70231bc..e40e169 100755
--- a/contrib/variant/create_coreboot_variant.sh
+++ b/contrib/variant/create_coreboot_variant.sh
@@ -3,7 +3,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-VERSION="4.2.0"
+VERSION="4.3.1"
SCRIPT="$(basename -- "$0")"
set -e
@@ -52,6 +52,9 @@
# Assign BUG= text, or "None" if that parameter wasn't specified.
BUG="${4:-None}"
+# Assign the value for BRANCH= in the commit message, or use None if unspecified
+COMMIT_MSG_BRANCH="${NEW_VARIANT_BRANCH:-None}"
+
# Get the directory where this script is located; it is also where
# kconfig.py is located.
pushd "${BASH_SOURCE%/*}"
@@ -130,14 +133,14 @@
board by copying the template files to a new directory named for the
variant." | fmt -w 70)
-git commit -sm "${BASE}: Create ${VARIANT} variant
+git commit -sm "mb/google/${BASE}: Create ${VARIANT} variant
${MSG}
(Auto-Generated by ${SCRIPT} version ${VERSION}).
BUG=${BUG}
-BRANCH=None
+BRANCH=${COMMIT_MSG_BRANCH}
TEST=util/abuild/abuild -p none -t google/${BASE} -x -a
make sure the build includes GOOGLE_${VARIANT_UPPER}"
# TODO(b/149702214): verify that it builds correctly
diff --git a/contrib/variant/create_initial_ec_image.sh b/contrib/variant/create_initial_ec_image.sh
index 964d22b..7277b45 100755
--- a/contrib/variant/create_initial_ec_image.sh
+++ b/contrib/variant/create_initial_ec_image.sh
@@ -3,7 +3,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-VERSION="1.2.0"
+VERSION="1.3.0"
SCRIPT=$(basename -- "${0}")
set -e
@@ -34,6 +34,9 @@
# Assign BUG= text, or "None" if that parameter wasn't specified.
BUG=${3:-None}
+# Assign the value for BRANCH= in the commit message, or use None if unspecified
+COMMIT_MSG_BRANCH="${NEW_VARIANT_BRANCH:-None}"
+
# All of the necessary files are in platform/ec/board
cd "${HOME}/trunk/src/platform/ec/board"
@@ -97,7 +100,7 @@
(Auto-Generated by ${SCRIPT} version ${VERSION}).
BUG=${BUG}
-BRANCH=none
+BRANCH=${COMMIT_MSG_BRANCH}
TEST=make BOARD=${VARIANT}"
check_standalone "$(pwd)" "${BRANCH}"
diff --git a/contrib/variant/new_variant.py b/contrib/variant/new_variant.py
index 5092164..8553027 100755
--- a/contrib/variant/new_variant.py
+++ b/contrib/variant/new_variant.py
@@ -66,12 +66,12 @@
* --continue
* --board=BOARD --variant=VARIANT [--bug=BUG]
"""
- board, variant, bug, continue_flag, abort_flag = get_args()
+ board, variant, bug, branch, continue_flag, abort_flag = get_args()
if not check_flags(board, variant, bug, continue_flag, abort_flag):
return False
- status = get_status(board, variant, bug, continue_flag, abort_flag)
+ status = get_status(board, variant, bug, branch, continue_flag, abort_flag)
if status is None:
return False
@@ -118,6 +118,8 @@
'--variant', type=str, help='Name of the new variant to create')
parser.add_argument(
'--bug', type=str, help='Bug number to reference in commits')
+ parser.add_argument(
+ '--branch', type=str, help='Value for BRANCH= in commit messages')
# Use a group so that we can enforce mutually-exclusive arguments.
# argparse does not support nesting groups, so we can't put board,
# variant, and bug into a group and have that group as another mutually
@@ -148,8 +150,9 @@
variant = variant.lower()
bug = args.bug or 'None'
+ branch = args.branch or 'None'
- return (board, variant, bug, args.continue_flag, args.abort_flag)
+ return (board, variant, bug, branch, args.continue_flag, args.abort_flag)
def check_flags(board, variant, bug, continue_flag, abort_flag):
@@ -193,7 +196,7 @@
return True
-def get_status(board, variant, bug, continue_flag, abort_flag):
+def get_status(board, variant, bug, branch, continue_flag, abort_flag):
"""Create the status file or get the previous status
This program can stop at several places as we have to wait for CLs
@@ -263,6 +266,9 @@
* bug - optional text for a bug ID, used in the git commit messages.
Could be 'None' (as text, not the python None), or something like
'b:12345' for buganizer, or 'chromium:12345'
+ * branch - optional text for a BRANCH= value in the commit message for
+ repos that use the BRANCH field (coreboot and EC). If not specified,
+ then None.
* step - internal state tracking, what step of the variant creation
we are at.
* yaml_file - internal, just the name of the file where all this data
@@ -295,6 +301,7 @@
board: Name of the reference board
variant: Name of the variant being created
bug: Text for bug number, if any ('None' otherwise)
+ branch: Text for a BRANCH= value in the commit message (or 'None')
continue_flag: Flag if --continue was specified
abort_flag: Flag if --abort was specified
@@ -328,6 +335,7 @@
status.board = board
status.variant = variant
status.bug = bug
+ status.branch = branch
# Load the appropriate module and copy all the data from it.
try:
@@ -695,7 +703,8 @@
"""
logging.info('Running step create_coreboot_variant')
cb_src_dir = os.path.join('/mnt/host/source/src/', status.coreboot_dir)
- environ = {**os.environ, 'CB_SRC_DIR': cb_src_dir}
+ environ = {**os.environ, 'CB_SRC_DIR': cb_src_dir,
+ 'NEW_VARIANT_BRANCH': status.branch}
create_coreboot_variant_sh = os.path.join(status.my_loc,
'create_coreboot_variant.sh')
rc = run_process(
@@ -913,13 +922,14 @@
True if the script and test build succeeded, False if something failed
"""
logging.info('Running step create_initial_ec_image')
+ environ = {**os.environ, 'NEW_VARIANT_BRANCH': status.branch}
create_initial_ec_image_sh = os.path.join(status.my_loc,
'create_initial_ec_image.sh')
if not run_process(
[create_initial_ec_image_sh,
status.board,
status.variant,
- status.bug]):
+ status.bug], env=environ):
return False
# No need to `if rc:` because we already tested the run_process result above