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_unittest.py b/scripts/build_sdk_subtools_unittest.py
index 70922bd..61919f4 100644
--- a/scripts/build_sdk_subtools_unittest.py
+++ b/scripts/build_sdk_subtools_unittest.py
@@ -35,6 +35,13 @@
yield mocks["_run_system_emerge"]
+@pytest.fixture(name="mock_exporter", autouse=True)
+def mock_exporter_fixture():
+ """Stubs the exporter for InstalledSubtools to avoid side-effects."""
+ with mock.patch("chromite.lib.subtool_lib.InstalledSubtools") as mock_lib:
+ yield mock_lib
+
+
def test_must_run_outside_sdk(caplog) -> None:
"""Tests build_sdk_subtools complains if run in the chroot."""
with pytest.raises(cros_build_lib.DieSystemExit) as error_info:
@@ -160,3 +167,13 @@
"""Tests --skip-package-update will not try to emerge anything."""
assert build_sdk_subtools.main(["--no-update-packages"]) == 0
assert mock_emerge.call_count == 0
+
+
+def test_invokes_exporter(mock_emerge, mock_exporter) -> None:
+ """Tests that the exporter is invoked."""
+ assert build_sdk_subtools.main([]) == 0
+ assert mock_emerge.call_count == 1
+ assert mock_exporter.called
+ installed_subtools = mock_exporter.return_value
+ assert installed_subtools.bundle_all.called
+ assert installed_subtools.export_all.called