Refactor artifacts.BundleEbuildLogs to use service/lib structure.

Also, Add *args functionality to chroot.full_path.

BUG=chromium:954303
TEST=manual, run_tests

Change-Id: I4d0dbd6b2a1cda5776d5d8388e2cee28da9db8f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/1724797
Reviewed-by: Alex Klein <saklein@chromium.org>
Tested-by: Michael Mortensen <mmortensen@google.com>
Commit-Queue: Michael Mortensen <mmortensen@google.com>
diff --git a/api/controller/artifacts.py b/api/controller/artifacts.py
index b61f40c..446d2a3 100644
--- a/api/controller/artifacts.py
+++ b/api/controller/artifacts.py
@@ -242,6 +242,7 @@
   output_proto.artifacts.add().path = os.path.join(output_dir, archive)
 
 
+@validate.exists('output_dir')
 def BundleEbuildLogs(input_proto, output_proto):
   """Tar the ebuild logs for a build target.
 
@@ -249,20 +250,24 @@
     input_proto (BundleRequest): The input proto.
     output_proto (BundleResponse): The output proto.
   """
-  target = input_proto.build_target.name
   output_dir = input_proto.output_dir
+  sysroot_path = input_proto.sysroot.path
+  chroot = controller_util.ParseChroot(input_proto.chroot)
 
-  # commands.BuildEbuildLogsTarball conflates "buildroot" with sysroot.
-  # Adjust accordingly...
-  build_root = os.path.join(constants.SOURCE_ROOT, 'chroot', 'build')
+  # TODO(mmortensen) Cleanup legacy handling after it has been switched over.
+  target = input_proto.build_target.name
+  if target:
+    # Legacy handling.
+    build_root = constants.SOURCE_ROOT
+    chroot.path = os.path.join(build_root, 'chroot')
+    sysroot_path = os.path.join('/build', target)
 
-  # TODO(crbug.com/954303): Replace with a chromite/service implementation.
-  archive = commands.BuildEbuildLogsTarball(build_root, target, output_dir)
-
+  sysroot = sysroot_lib.Sysroot(sysroot_path)
+  archive = artifacts.BundleEBuildLogsTarball(chroot, sysroot, output_dir)
   if archive is None:
     cros_build_lib.Die(
-        'Could not create ebuild logs archive. No logs found for %s.', target)
-
+        'Could not create ebuild logs archive. No logs found for %s.',
+        sysroot.path)
   output_proto.artifacts.add().path = os.path.join(output_dir, archive)