scripts: upload_prebuilts: Handle version prefixes other than "chroot-"
Previously, upload_prebuilts assumed that the version prefix was "chroot-",
and chopped off the first 7 characters of the prefix+version string to
get the version alone. This updates the code to be a bit more robust,
instead looking for the expected format of the version and stripping
the prefix that precedes it.
BUG=b:289990183
TEST=./run_tests scripts/upload_prebuilts_unittest.py
Change-Id: Id36dd69c0e7529885151f26f41d86b5ce573de5b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/4669938
Commit-Queue: Bob Haarman <inglorion@chromium.org>
Tested-by: Bob Haarman <inglorion@chromium.org>
Reviewed-by: Lizzy Presland <zland@google.com>
diff --git a/scripts/upload_prebuilts.py b/scripts/upload_prebuilts.py
index 0425f14..1c685b0 100644
--- a/scripts/upload_prebuilts.py
+++ b/scripts/upload_prebuilts.py
@@ -25,6 +25,7 @@
import multiprocessing
import os
from pathlib import Path
+import re
import tempfile
from typing import Optional, Tuple
@@ -491,7 +492,12 @@
assert boardname == constants.CHROOT_BUILDER_BOARD
assert prepackaged is not None
- version_str = self._version[len("chroot-") :]
+ # _version consists of a prefix followed by the actual version.
+ # We want the version without the prefix. It starts with the
+ # year, month, and date in YYYY.MM.DD format, so we match that.
+ m = re.match(r"(.*-)?(\d\d\d\d\.\d\d\.\d\d.*)", self._version)
+ assert m, "version does not match format .*YYYY.MM.DD.*"
+ version_str = m[2]
remote_tarfile = toolchain.GetSdkURL(
for_gsutil=True, suburl="cros-sdk-%s.tar.xz" % (version_str,)
)
diff --git a/scripts/upload_prebuilts_unittest.py b/scripts/upload_prebuilts_unittest.py
index 47dbaf8..09bb2b1 100644
--- a/scripts/upload_prebuilts_unittest.py
+++ b/scripts/upload_prebuilts_unittest.py
@@ -667,6 +667,8 @@
class TestSdk(cros_test_lib.MockTestCase):
"""Test logic related to uploading SDK binaries"""
+ VERSION_PREFIX = "cros-"
+
def setUp(self):
self.PatchObject(
prebuilt,
@@ -706,7 +708,7 @@
False,
"x86-foo",
[],
- "chroot-1234",
+ f"{self.VERSION_PREFIX}-1234.08.01.5678",
report={},
)
@@ -719,7 +721,7 @@
):
"""Make sure we can upload just an SDK tarball"""
tar = "sdk.tar.xz"
- ver = "1234"
+ ver = "1234.08.01.5678"
vtar = "cros-sdk-%s.tar.xz" % ver
upload_calls = [
@@ -805,6 +807,12 @@
)
+class TestSdkBuildToolchain(TestSdk):
+ """Like TestSdk, but uses a different version prefix."""
+
+ VERSION_PREFIX = "build_toolchain-"
+
+
@pytest.mark.parametrize(
"extra_args,expected_sync",
[