api/controller: Convert manual BuildTarget instantiations

There are controller_util functions to construct BuildTargets from
the protobuf messages so we can have a single place to address changes
to the protobuf message. Convert all the BuildTarget instantiations
from manual constructions to calls to the util function.

BUG=chromium:1060351
TEST=run_tests, cq

Change-Id: I60c6720cf7bbc60f122f2fa1e2e81ab13368193f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2096818
Reviewed-by: Michael Mortensen <mmortensen@google.com>
Commit-Queue: Alex Klein <saklein@chromium.org>
Tested-by: Alex Klein <saklein@chromium.org>
diff --git a/api/controller/artifacts.py b/api/controller/artifacts.py
index 31d75d0..7858680 100644
--- a/api/controller/artifacts.py
+++ b/api/controller/artifacts.py
@@ -16,7 +16,6 @@
 from chromite.api.controller import controller_util
 from chromite.api.gen.chromite.api import toolchain_pb2
 from chromite.cbuildbot import commands
-from chromite.lib import build_target_lib
 from chromite.lib import chroot_lib
 from chromite.lib import constants
 from chromite.lib import cros_build_lib
@@ -456,18 +455,13 @@
 @validate.validation_complete
 def BundleSimpleChromeArtifacts(input_proto, output_proto, _config):
   """Create the simple chrome artifacts."""
-  # Required args.
   sysroot_path = input_proto.sysroot.path
-  build_target_name = input_proto.sysroot.build_target.name
   output_dir = input_proto.output_dir
 
-  # Optional args.
-  chroot_path = input_proto.chroot.path or constants.DEFAULT_CHROOT_PATH
-  cache_dir = input_proto.chroot.cache_dir
-
   # Build out the argument instances.
-  build_target = build_target_lib.BuildTarget(build_target_name)
-  chroot = chroot_lib.Chroot(path=chroot_path, cache_dir=cache_dir)
+  build_target = controller_util.ParseBuildTarget(
+      input_proto.sysroot.build_target)
+  chroot = controller_util.ParseChroot(input_proto.chroot)
   # Sysroot.path needs to be the fully qualified path, including the chroot.
   full_sysroot_path = os.path.join(chroot.path, sysroot_path.lstrip(os.sep))
   sysroot = sysroot_lib.Sysroot(full_sysroot_path)
@@ -538,15 +532,11 @@
     output_proto (BundleResponse): The output proto.
     _config (api_config.ApiConfig): The API call config.
   """
-
-  # Required args.
-  build_target = build_target_lib.BuildTarget(input_proto.build_target.name)
   chrome_root = input_proto.chroot.chrome_dir
-  if not chrome_root:
-    cros_build_lib.Die('chrome_root is not included in chroot')
   output_dir = input_proto.output_dir
   artifact_type = input_proto.artifact_type
 
+  build_target = controller_util.ParseBuildTarget(input_proto.build_target)
   chroot = controller_util.ParseChroot(input_proto.chroot)
 
   try: