Reland "cros_run_unit_tests: Add --host option to run tests on host"

This is a reland of 295df5d587d616eef10a012a9715fdfb9923e9c3

This reland contains a fix for b:208651520 which triggered the revert.
cros_generate_sysroot writes config (etc/make.conf.board_setup) to an
empty sysroot, but with this CL now needs to also write etc/make.conf so
the generated config can be read.

BUG=b:193915549
TEST=pass CQ, run cros_generate_sysroot

Original change's description:
> Reland "cros_run_unit_tests: Add --host option to run tests on host"
>
> This is a reland of da20116575cb305bff6d08fe6aa0b04bdf5b34f3
>
> Ok to reland now as underlying issue for revert has been resolved by
> chromium:3256026, chromium:3253802, and chromium:3253130.
>
> Original change's description:
> > cros_run_unit_tests: Add --host option to run tests on host
> >
> > Better support is needed for running host package unit tests.  This adds
> > that functionality to the cros_run_unit_tests command with the --host
> > option.  Aligned with the existing behavior, specifying only the --host
> > option tests all installed packages in virtual/target-sdk.  Existing
> > additional cros_run_unit_tests options are supported in this mode as
> > well.
> >
> > BUG=b:193915549
> > TEST=pass CQ
> >
> > Change-Id: I0b20332c3b09c9faac3500f2ed813d916f701f36
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/3188310
> > Reviewed-by: Mike Frysinger <vapier@chromium.org>
> > Reviewed-by: Lizzy Presland <zland@google.com>
> > Commit-Queue: Sloan Johnson <sloanjohnson@google.com>
> > Tested-by: Sloan Johnson <sloanjohnson@google.com>
>
> Bug: b:193915549
> Cq-Depend: chromium:3256026
> Change-Id: Ifa13db9fbcc36497985506bd6ff2b1cec18ac34d
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/3256201
> Tested-by: Sloan Johnson <sloanjohnson@google.com>
> Commit-Queue: Sloan Johnson <sloanjohnson@google.com>
> Reviewed-by: Mike Frysinger <vapier@chromium.org>
> Reviewed-by: Lizzy Presland <zland@google.com>

Change-Id: I8eb06d784ccb25329f8a1ab3ccb813581c858329
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/3312069
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Sloan Johnson <sloanjohnson@google.com>
Commit-Queue: Sloan Johnson <sloanjohnson@google.com>
diff --git a/scripts/cros_run_unit_tests.py b/scripts/cros_run_unit_tests.py
index ab7afd3..d2506e1 100644
--- a/scripts/cros_run_unit_tests.py
+++ b/scripts/cros_run_unit_tests.py
@@ -24,6 +24,7 @@
                           constants.TARGET_OS_DEV_PKG,
                           constants.TARGET_OS_TEST_PKG,
                           constants.TARGET_OS_FACTORY_PKG)
+SDK_VIRTUAL_PACKAGES = (constants.TARGET_SDK,)
 IMPLICIT_TEST_DEPS = ('virtual/implicit-system',)
 
 
@@ -38,6 +39,8 @@
   target = parser.add_mutually_exclusive_group(required=True)
   target.add_argument('--sysroot', type='path', help='Path to the sysroot.')
   target.add_argument('--board', help='Board name.')
+  target.add_argument('--host', action='store_true',
+                      help='Run tests for the host SDK.')
 
   parser.add_argument('--pretend', default=False, action='store_true',
                       help='Show the list of packages to be tested and return.')
@@ -89,7 +92,7 @@
   return options
 
 
-def determine_board_packages(sysroot, virtual_packages):
+def determine_packages(sysroot, virtual_packages):
   """Returns a set of the dependencies for the given packages"""
   deps, _bdeps = cros_extract_deps.ExtractDeps(
       sysroot, virtual_packages, include_bdepend=False)
@@ -102,8 +105,8 @@
 
   cros_build_lib.AssertInsideChroot()
 
-  sysroot = (opts.sysroot or
-             build_target_lib.get_default_sysroot_path(opts.board))
+  sysroot = (opts.sysroot or '/' if opts.host
+             else build_target_lib.get_default_sysroot_path(opts.board))
   skipped_packages = set()
   if opts.skip_packages:
     skipped_packages |= set(opts.skip_packages.split())
@@ -125,7 +128,8 @@
                 else set(workon.ListAtoms(use_all=True)))
 
   if opts.empty_sysroot:
-    packages |= determine_board_packages(sysroot, BOARD_VIRTUAL_PACKAGES)
+    packages |= determine_packages(sysroot, SDK_VIRTUAL_PACKAGES if opts.host
+                                   else BOARD_VIRTUAL_PACKAGES)
     workon = workon_helper.WorkonHelper(sysroot)
     workon_packages = set(workon.ListAtoms(use_all=True))
     packages &= workon_packages