sysroot: Add dryrun option to InstallPackages endpoint.

Allow calls from the Build API to invoke the build_packages script with
the pretend flag.

BUG=b:189336144
TEST=./run_tests

Change-Id: Ib8901e50bc5c8467cb6b7198656f20a2ffdcb993
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2919899
Reviewed-by: Sean McAllister <smcallis@google.com>
Tested-by: Navil Perez <navil@google.com>
Commit-Queue: Navil Perez <navil@google.com>
diff --git a/api/controller/sysroot.py b/api/controller/sysroot.py
index b6e925c..2f5c73b 100644
--- a/api/controller/sysroot.py
+++ b/api/controller/sysroot.py
@@ -170,6 +170,9 @@
       for x in input_proto.package_indexes
   ]
 
+  # Calculate which packages would have been merged, but don't install anything.
+  dryrun = input_proto.flags.dryrun
+
   if not target_sysroot.IsToolchainInstalled():
     cros_build_lib.Die('Toolchain must first be installed.')
 
@@ -184,7 +187,8 @@
       use_flags=use_flags,
       use_goma=use_goma,
       incremental_build=False,
-      setup_board=False)
+      setup_board=False,
+      dryrun=dryrun)
 
   try:
     sysroot.BuildPackages(build_target, target_sysroot, build_packages_config)
@@ -200,6 +204,10 @@
 
     return controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE
 
+  # Return without populating the response if it is a dryrun.
+  if dryrun:
+    return controller.RETURN_CODE_SUCCESS
+
   # Copy goma logs to specified directory if there is a goma_config and
   # it contains a log_dir to store artifacts.
   if input_proto.goma_config.log_dir.dir: