chromite: Add a stage to generate sysroot for the builds.

We want to start fuzzing testing for Chrome OS.
To do that we need a new stage to create a sysroot that can be
used by clusterfuzz to run the fuzz binaries.

BUG=chromium:807401

TEST=Chromite Unit tests pass.

Change-Id: I92d3e5dda0eac8b0ba15ea5f2e41cbfb4b131d83
Reviewed-on: https://chromium-review.googlesource.com/914937
Commit-Ready: Manoj Gupta <manojgupta@chromium.org>
Tested-by: Manoj Gupta <manojgupta@chromium.org>
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
diff --git a/scripts/cros_generate_sysroot.py b/scripts/cros_generate_sysroot.py
index fa1bf1b..1838388 100644
--- a/scripts/cros_generate_sysroot.py
+++ b/scripts/cros_generate_sysroot.py
@@ -30,7 +30,10 @@
   parser.add_argument('--board', required=True,
                       help=('The board to generate the sysroot for.'))
   parser.add_argument('--package', required=True,
-                      help=('The package to generate the sysroot for.'))
+                      help=('The packages to generate the sysroot for.'))
+  parser.add_argument('--deps-only', action='store_true',
+                      default=False,
+                      help='Build dependencies only.')
   parser.add_argument('--out-dir', type='path', required=True,
                       help='Directory to place the generated tarball.')
   parser.add_argument('--out-file', default=DEFAULT_NAME,
@@ -39,7 +42,7 @@
   options = parser.parse_args(argv)
 
   options.out_file %= {
-      'package': options.package.replace(PACKAGE_SEPARATOR, '_'),
+      'package': options.package.split()[0].replace(PACKAGE_SEPARATOR, '_'),
   }
 
   return options
@@ -82,19 +85,24 @@
   def _InstallBuildDependencies(self):
     # Calculate buildtime deps that are not runtime deps.
     raw_sysroot = cros_build_lib.GetSysroot(board=self.options.board)
-    cmd = ['qdepends', '-q', '-C', self.options.package]
-    output = cros_build_lib.RunCommand(
-        cmd, extra_env={'ROOT': raw_sysroot}, capture_output=True).output
+    packages = []
+    if not self.options.deps_only:
+      packages = self.options.package.split()
+    else:
+      for pkg in self.options.package.split():
+        cmd = ['qdepends', '-q', '-C', pkg]
+        output = cros_build_lib.RunCommand(
+            cmd, extra_env={'ROOT': raw_sysroot}, capture_output=True).output
 
-    if output.count('\n') > 1:
-      raise AssertionError('Too many packages matched given package pattern')
+        if output.count('\n') > 1:
+          raise AssertionError('Too many packages matched for given pattern')
 
-    # qdepend outputs "package: deps", so only grab the deps.
-    atoms = output.partition(':')[2].split()
-
-    # Install the buildtime deps.
-    if atoms:
-      self._Emerge(*atoms)
+        # qdepend outputs "package: deps", so only grab the deps.
+        deps = output.partition(':')[2].split()
+        packages.extend(deps)
+    # Install the required packages.
+    if packages:
+      self._Emerge(*packages)
 
   def _CreateTarball(self):
     target = os.path.join(self.options.out_dir, self.options.out_file)