subtools_builder: textproto parsing and basic validation.
Introduces lib/subtool_lib.py for a clean separation with the script
that sets up the build environment. The "Subtool" class is responsible
for loading a single subtool manifest from .textproto and hosts methods
to bundle an export it according to the manifest, in a provided workdir.
InstalledSubtools globs manifests from a configdir and manages
operations on the collection of subtool manifests.
This CL sets up basic proto field validation and a stubbed bundling
workflow. A test manifest is "installed" by build_sdk_subtools for
end-to-end testing.
BUG=b:277992359
TEST=./bin/build_sdk_subtools shellcheck
Cq-Depend: chromium:4772194
Change-Id: I74321cfa104c71954a250ab4549f18943f048e6c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/4648634
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Trent Apted <tapted@chromium.org>
Tested-by: Trent Apted <tapted@chromium.org>
diff --git a/scripts/build_sdk_subtools.py b/scripts/build_sdk_subtools.py
index ddfb655..092c97a 100644
--- a/scripts/build_sdk_subtools.py
+++ b/scripts/build_sdk_subtools.py
@@ -35,6 +35,7 @@
from chromite.lib import cros_sdk_lib
from chromite.lib import osutils
from chromite.lib import portage_util
+from chromite.lib import subtool_lib
from chromite.lib import sysroot_lib
from chromite.service import sysroot
@@ -58,12 +59,36 @@
"sys-libs/glibc",
"sys-devel/gcc",
"sys-devel/binutils",
+ "sys-kernel/linux-headers",
)
+# Path in subtools chroot that holds export package manifests.
+SUBTOOLS_EXPORTS_CONFIG_DIR = Path("/etc/cros/sdk-packages.d")
+
+# Path where subtools will be bundled.
+SUBTOOLS_BUNDLE_WORK_DIR = Path("/var/tmp/cros-subtools")
+
# Flag passed to subprocesses in chroots that might not yet be set up as a
# subtools chroot.
_RELAUNCH_FOR_SETUP_FLAG = "--relaunch-for-setup"
+# Used to populate a test manifest in /etc/cros/standalone-packages.d/.
+# Ebuilds will later be updated to provide these files instead.
+_TEST_PACKAGE = SUBTOOLS_EXPORTS_CONFIG_DIR / "shellcheck.textproto"
+_TEST_PACKAGE_CONTENTS = """\
+# proto-file: chromiumos/build/api/subtools.proto
+# proto-message: chromiumos.build.api.SubtoolPackage
+name: "shellcheck"
+type: EXPORT_CIPD
+max_files: 2
+paths: [{
+ input: "/usr/bin/shellcheck"
+},{
+ input: "/usr/share/doc/*/LICENSE.gz"
+ ebuild_filter: "dev-util/shellcheck"
+}]
+"""
+
class Options(Protocol):
"""Protocol to formalize commandline arguments."""
@@ -198,8 +223,9 @@
)
if setup_chroot:
- # TODO(b/277992359): Additional setup here, e.g., packages, base layout.
logging.info("Setting up subtools SDK in %s.", build_target.root)
+ osutils.SafeMakedirs(SUBTOOLS_EXPORTS_CONFIG_DIR)
+ _TEST_PACKAGE.write_text(_TEST_PACKAGE_CONTENTS, encoding="utf-8")
def _run_system_emerge(
@@ -267,6 +293,21 @@
cros_build_lib.Die(e)
+def _run_inside_subtools_chroot(opts: Options) -> None:
+ """Steps that build_sdk_subtools performs once it is in its chroot."""
+ _assert_inside_subtools_chroot()
+
+ if opts.update_packages:
+ _build_sdk_packages(opts.build_run_config)
+
+ subtools = subtool_lib.InstalledSubtools(
+ config_dir=SUBTOOLS_EXPORTS_CONFIG_DIR,
+ work_root=SUBTOOLS_BUNDLE_WORK_DIR,
+ )
+ subtools.bundle_all()
+ subtools.export_all()
+
+
def main(argv: Optional[List[str]] = None) -> Optional[int]:
opts = parse_args(argv)
return build_sdk_subtools(opts, argv if argv else [])
@@ -283,8 +324,7 @@
# If the process is in the subtools chroot, we must assume it's already set
# up (we are in it). So start building.
if _is_inside_subtools_chroot() and not opts.relaunch_for_setup:
- if opts.update_packages:
- _build_sdk_packages(opts.build_run_config)
+ _run_inside_subtools_chroot(opts)
return 0
# Otherwise, we have the option to set it up. Then restart inside it. The