new_variant: allow building on WIP

When making changes to the files that new variants are based on,
like the coreboot template files, or the EC baseboard source code,
we want to be able to base the CLs for the new variants on top of
the CLs we're working on, not on m/master. Add the NEW_VARIANT_WIP
variable to signal to the scripts that `repo start` should add
the `--head` option to base the new branch off the current HEAD,
and not on m/master.

BUG=b:167305316
TEST=create a CL in src/platform/ec with a simple change to a file
like some docs. Run `create_initial_ec_image.sh waddledoo kingitchy`
and then check that the other change is missing; the new branch is
based on m/master, not HEAD. `repo abandon` the branch that
`create_initial_ec_image.sh` created. Run it again with
`NEW_VARIANT_WIP=1 create_initial_ec_image.sh waddledoo kingitchy`
and then check that the other change is included. `repo abandon`
the new branch, and see that you've been reset back to m/master
and will need to `git checkout` the experimental branch (which
you should also `repo abandon`.

Change-Id: I5998179cbaefce75ed1e7d168b656ccf66c2f513
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/2424754
Tested-by: Paul Fagerburg <pfagerburg@chromium.org>
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Commit-Queue: Paul Fagerburg <pfagerburg@chromium.org>
diff --git a/contrib/variant/add_variant_to_yaml.sh b/contrib/variant/add_variant_to_yaml.sh
index 15a535f..389856e 100755
--- a/contrib/variant/add_variant_to_yaml.sh
+++ b/contrib/variant/add_variant_to_yaml.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.3.0"
+VERSION="1.4.0"
 SCRIPT=$(basename -- "${0}")
 set -e
 
@@ -62,7 +62,9 @@
 # Start a branch. Use YMD timestamp to avoid collisions.
 DATE=$(date +%Y%m%d)
 BRANCH="create_${VARIANT}_${DATE}"
-repo start "${BRANCH}" .
+repo start "${BRANCH}" . "${NEW_VARIANT_WIP:+--head}"
+# ${parameter:+word}" substitutes "word" if $parameter is set to a non-null
+# value, or substitutes null if $parameter is null or unset.
 
 cleanup() {
   # If there is an error after the `repo start`, then restore modified files
diff --git a/contrib/variant/copy_cras_config.sh b/contrib/variant/copy_cras_config.sh
index 755af06..0f90d1f 100755
--- a/contrib/variant/copy_cras_config.sh
+++ b/contrib/variant/copy_cras_config.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.1.0"
+VERSION="1.2.0"
 SCRIPT=$(basename -- "${0}")
 set -e
 
@@ -47,7 +47,9 @@
 # Start a branch. Use YMD timestamp to avoid collisions.
 DATE=$(date +%Y%m%d)
 BRANCH="create_${VARIANT}_${DATE}"
-repo start "${BRANCH}" .
+repo start "${BRANCH}" . "${NEW_VARIANT_WIP:+--head}"
+# ${parameter:+word}" substitutes "word" if $parameter is set to a non-null
+# value, or substitutes null if $parameter is null or unset.
 
 cleanup() {
   # If there is an error after the `repo start`, then restore modified files
diff --git a/contrib/variant/create_coreboot_config.sh b/contrib/variant/create_coreboot_config.sh
index b0056db..f2c5333 100755
--- a/contrib/variant/create_coreboot_config.sh
+++ b/contrib/variant/create_coreboot_config.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="2.2.0"
+VERSION="2.3.0"
 SCRIPT=$(basename -- "${0}")
 set -e
 
@@ -58,7 +58,9 @@
 # Start a branch. Use YMD timestamp to avoid collisions.
 DATE=$(date +%Y%m%d)
 BRANCH="create_${VARIANT}_${DATE}"
-repo start "${BRANCH}" .
+repo start "${BRANCH}" . "${NEW_VARIANT_WIP:+--head}"
+# ${parameter:+word}" substitutes "word" if $parameter is set to a non-null
+# value, or substitutes null if $parameter is null or unset.
 
 cleanup() {
   # If there is an error after the `repo start`, then remove the added files
diff --git a/contrib/variant/create_coreboot_variant.sh b/contrib/variant/create_coreboot_variant.sh
index 419a509..70231bc 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.1.3"
+VERSION="4.2.0"
 SCRIPT="$(basename -- "$0")"
 set -e
 
@@ -78,7 +78,9 @@
 # Start a branch. Use YMD timestamp to avoid collisions.
 DATE="$(date +%Y%m%d)"
 BRANCH="coreboot_${VARIANT}_${DATE}"
-repo start "${BRANCH}" .
+repo start "${BRANCH}" . "${NEW_VARIANT_WIP:+--head}"
+# ${parameter:+word}" substitutes "word" if $parameter is set to a non-null
+# value, or substitutes null if $parameter is null or unset.
 
 abandon() {
   # If there is an error after the `repo start` and before we start adding
diff --git a/contrib/variant/create_initial_ec_image.sh b/contrib/variant/create_initial_ec_image.sh
index 07c4616..964d22b 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.1.0"
+VERSION="1.2.0"
 SCRIPT=$(basename -- "${0}")
 set -e
 
@@ -52,7 +52,9 @@
 # Start a branch. Use YMD timestamp to avoid collisions.
 DATE=$(date +%Y%m%d)
 BRANCH="create_${VARIANT}_${DATE}"
-repo start "${BRANCH}" .
+repo start "${BRANCH}" . "${NEW_VARIANT_WIP:+--head}"
+# ${parameter:+word}" substitutes "word" if $parameter is set to a non-null
+# value, or substitutes null if $parameter is null or unset.
 
 cleanup() {
   # If there is an error after the `repo start`, then remove the added files
diff --git a/contrib/variant/fw_build_config.sh b/contrib/variant/fw_build_config.sh
index 11aa978..e07af62 100755
--- a/contrib/variant/fw_build_config.sh
+++ b/contrib/variant/fw_build_config.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.0.3"
+VERSION="1.1.0"
 SCRIPT=$(basename -- "${0}")
 set -e
 
@@ -42,7 +42,9 @@
 # Start a branch. Use YMD timestamp to avoid collisions.
 DATE=$(date +%Y%m%d)
 BRANCH="create_${VARIANT}_${DATE}"
-repo start "${BRANCH}" .
+repo start "${BRANCH}" . "${NEW_VARIANT_WIP:+--head}"
+# ${parameter:+word}" substitutes "word" if $parameter is set to a non-null
+# value, or substitutes null if $parameter is null or unset.
 
 cleanup() {
   # If there is an error after the `repo start`, then restore modified files
diff --git a/contrib/variant/testdata/README.md b/contrib/variant/testdata/README.md
index 26a759a..9652903 100644
--- a/contrib/variant/testdata/README.md
+++ b/contrib/variant/testdata/README.md
@@ -75,10 +75,10 @@
 
 End-to-End Test
 ===============
-`testdata/e2e.sh` is an end-to-end test of `new_variant.py`. The script takes
-the name of a reference board as a parameter, and creates a new variant of
-that reference board. The script ensures that `new_variant.py` will not
-upload the CLs for the new variant to gerrit, so the script can be run
+`testdata/new_variant_fulltest.sh` is an end-to-end test of `new_variant.py`.
+The script takes the name of a reference board as a parameter, and creates a
+new variant of that reference board. The script ensures that `new_variant.py`
+will not upload the CLs for the new variant to gerrit, so the script can be run
 multiple times to test functionality.
 
 The supported reference boards are:
@@ -95,7 +95,7 @@
 
 ```
 cd /mnt/host/source/src/platform/dev/contrib/variant/testdata
-./e2e.sh waddledee
+./new_variant_fulltest.sh waddledee
 ```
 
 When the build finishes, all of the branches and commits for the new variant
@@ -159,18 +159,42 @@
 (cr) $
 ```
 
-For boards that require a fitimage, `e2e.sh` will create a fake fitimage for
-the new variant by copying the reference board's fitimage. Obviously this
-won't be bootable, but since the purpose is just to ensure that the build
-works, this is OK, and prevents the tester from having to create the fitimage
-outside the chroot (by running `gen_fit_image.sh`) and then restarting
+For boards that require a fitimage, `new_variant_fulltest.sh` will create a
+fake fitimage for the new variant by copying the reference board's fitimage.
+Obviously this won't be bootable, but since the purpose is just to ensure that
+the build works, this is OK, and prevents the tester from having to create the
+fitimage outside the chroot (by running `gen_fit_image.sh`) and then restarting
 `new_variant.py`.
 
 Similarly, for boards that use the project configuration repositories (all
-of the boards this test supports except for Hatch), `e2e.sh` creates a
-configuration directory that will suffice for building, but it is not an
-actual repo.
+of the boards this test supports except for Hatch), `new_variant_fulltest.sh`
+creates a configuration directory that will suffice for building, but it is not
+an actual repo.
 
-When `e2e.sh` is done, it will clean up the temporary files it created and
-revert the changes it made to checked-in files. If the build fails, the user
-will have to clean it up for now; improved error handling is planned.
+When `new_variant_fulltest.sh` is done, it will clean up the temporary files it
+created and revert the changes it made to checked-in files.
+
+Work-in-Progress
+----------------
+
+The scripts that create new CLs use `repo start`, which will begin a new branch
+off of `m/master`. This is almost always what we want to do, except when we
+don't. For example, if you are editing the coreboot template files (in
+`third_party/coreboot/util/mainboard/google`) on a branch, when
+`create_coreboot_variant.sh` runs, it will start a new branch based on
+`m/master` and the changes you had on your branch will not be visible. The
+script will copy the previous versions of the files (from `m/master`) without
+your updates. This same problem can happen with the EC baseboard sources that
+are copied to make a new variant, or when fixing bugs in the private fitimage
+scripts.
+
+To force the scripts to use `HEAD` instead of `m/master` as the basis for a
+new branch, set `NEW_VARIANT_WIP=1` in the environment:
+
+```
+NEW_VARIANT_WIP=1 ./new_variant_fulltest.sh waddledoo
+```
+
+When the branches are abandoned as part of clean-up, your repo will go back
+to `m/master`, so you will need to manually `git checkout` the branch where
+you were making changes.