new_variant: handle empty lists for cros_workon

Make sure that the list of packages to cros_workon start or stop
is not empty. If it is empty, then don't try to cros_workon start
or stop it, because the library will raise an exception.

BUG=b:159092931
TEST=cros_workon all of the packages that are listed for Hatch,
so that when the build gets to the workon-and-emerge point, there
won't be any packages to stop working on:

(cr) $ cros_workon --board=hatch start coreboot libpayload \
vboot_reference depthcharge intel-cmlfsp coreboot-private-files-hatch \
chromeos-ec chromeos-config-bsp-hatch-private
(cr) $ ./new_variant.py --board=hatch --variant=tiamat

Generate the fitimage as directed, outside the chroot.

(cr) $ ./new_variant.py --continue

Observe that the emerge is successful, and you get a prompt to push
to coreboot. At that point, abort and clean up.

(cr) $ cros_workon --board=hatch stop coreboot libpayload \
vboot_reference depthcharge intel-cmlfsp coreboot-private-files-hatch \
chromeos-ec chromeos-config-bsp-hatch-private
(cr) $ ./new_variant.py --abort

Now make sure that the program doesn't try to cros_workon start an
empty list:

Change config_workon_pkgs in hatch.py to [].

(cr) $ ./new_variant.py --board=hatch --variant=tiamat

Generate the fitimage as directed, outside the chroot.

(cr) $ ./new_variant.py --continue

Observe that the build_config step succeeds. Once the build pauses
for coreboot upload, `./new_variant.py --abort` and then restore
hatch.py.

Change-Id: I481ab7c386e1fbc6f8dfca4006677bf01c09aacc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/2247049
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/new_variant.py b/contrib/variant/new_variant.py
index 6330129..3cc4220 100755
--- a/contrib/variant/new_variant.py
+++ b/contrib/variant/new_variant.py
@@ -588,7 +588,9 @@
     workon = workon_helper.WorkonHelper(build_target.root, build_target.name)
     before_workon = workon.ListAtoms()
 
-    workon.StartWorkingOnPackages(workon_pkgs)
+    # Only cros_workon start if the list is non-empty
+    if workon_pkgs:
+        workon.StartWorkingOnPackages(workon_pkgs)
 
     # Determine which packages we need to cros_workon stop.
     after_workon = workon.ListAtoms()
@@ -597,8 +599,9 @@
     # Run the emerge command.
     emerge_result = run_process([emerge_cmd] + emerge_pkgs, env=env)
 
-    # cros_workon stop before returning the result.
-    workon.StopWorkingOnPackages(stop_packages)
+    # If the list is non-empty, cros_workon stop before returning the result.
+    if stop_packages:
+        workon.StopWorkingOnPackages(stop_packages)
 
     return emerge_result
 
@@ -1011,7 +1014,7 @@
     Returns:
         True if the scripts and build succeeded, False is something failed
     """
-    logging.info('Running step build_yaml')
+    logging.info('Running step build_config')
     if not emerge_with_workon(status, status.config_workon_pkgs,
                               status.emerge_cmd, status.config_emerge_pkgs):
         return False