]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
script/build-with-container: add workarounds for older python versions 63913/head
authorJohn Mulligan <jmulligan@redhat.com>
Fri, 13 Jun 2025 00:37:56 +0000 (20:37 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Fri, 13 Jun 2025 00:37:56 +0000 (20:37 -0400)
Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/script/build-with-container.py

index 33e53e82f76448ab20e047d13d76c5aea7bd8deb..251137c05fda2ea16fb73c56700a584a047290d2 100755 (executable)
@@ -71,7 +71,6 @@ import contextlib
 import enum
 import glob
 import hashlib
-import functools
 import json
 import logging
 import os
@@ -95,6 +94,12 @@ except ImportError:
             return self.value
 
 
+try:
+    from functools import cache as ftcache
+except ImportError:
+    ftcache = lambda f: f
+
+
 class DistroKind(StrEnum):
     CENTOS10 = "centos10"
     CENTOS8 = "centos8"
@@ -236,7 +241,7 @@ def _git_command(ctx, args):
 
 # Assume that the git version will not be changing after the 1st time
 # the command is run.
-@functools.cache
+@ftcache
 def _git_current_branch(ctx):
     cmd = _git_command(ctx, ["rev-parse", "--abbrev-ref", "HEAD"])
     res = _run(cmd, check=True, capture_output=True)
@@ -253,7 +258,7 @@ def _git_current_sha(ctx, short=True):
     return res.stdout.decode("utf8").strip()
 
 
-@functools.cache
+@ftcache
 def _hash_sources(bsize=4096):
     hh = hashlib.sha256()
     buf = bytearray(bsize)
@@ -683,7 +688,20 @@ def bc_make_source_rpm(ctx):
 
 def _glob_search(ctx, pattern):
     overlay = ctx.overlay()
-    return glob.glob(pattern, root_dir=overlay.upper if overlay else None)
+    try:
+        return glob.glob(pattern, root_dir=overlay.upper if overlay else None)
+    except TypeError:
+        log.info("glob with root_dir failed... falling back to chdir")
+    try:
+        prev_dir = os.getcwd()
+        if overlay:
+            os.chdir(overlay.upper)
+            log.debug("chdir %s -> %s", prev_dir, overlay.upper)
+        result = glob.glob(pattern)
+    finally:
+        if overlay:
+            os.chdir(prev_dir)
+    return result
 
 
 @Builder.set(Steps.RPM)