@@ -481,31 +481,49 @@ def setup_tools_tarball(ourconfig, btdir, bttarball, name="buildtools"):
if ";" in bttarball:
bttarball, sha256 = bttarball.split(";")
btdir = os.path.abspath(btdir)
+ btdlpath = getconfig("BASE_SHAREDDIR", ourconfig) + "/cluster-downloads-cache/" + os.path.basename(bttarball)
+ btlock = btdlpath + ".lock"
+ if not os.path.exists(os.path.dirname(btdlpath)):
+ os.makedirs(os.path.dirname(btdlpath), exist_ok=True)
+ # Always run the cache-validation / download step so that a freshly
+ # published tarball is detected even when btdir already exists from a
+ # previous build. tarball_updated is set to True whenever the cached
+ # download is replaced, which triggers removal of the stale btdir.
+ tarball_updated = False
+ while True:
+ try:
+ with open(btlock, 'a+') as lf:
+ fileno = lf.fileno()
+ fcntl.flock(fileno, fcntl.LOCK_EX)
+ if sha256 and os.path.exists(btdlpath):
+ dl_sha256 = sha256_file(btdlpath)
+ if dl_sha256 != sha256:
+ os.unlink(btdlpath)
+ elif bttarball.startswith("/") and os.path.exists(btdlpath):
+ # For local-path sources (e.g. vcontainer-tarball-latest)
+ # invalidate the cached copy when the source is newer so
+ # that a freshly-published tarball is always picked up.
+ if os.path.getmtime(bttarball) > os.path.getmtime(btdlpath):
+ os.unlink(btdlpath)
+ os.unlink(btdlpath)
+ if not os.path.exists(btdlpath):
+ if bttarball.startswith("/"):
+ subprocess.check_call(["cp", bttarball, btdlpath])
+ else:
+ subprocess.check_call(["wget", "-O", btdlpath, bttarball])
+ os.chmod(btdlpath, 0o775)
+ tarball_updated = True
+ break
+ except OSError:
+ # We raced with someone else, try again
+ pass
+ # If the underlying tarball changed, remove any stale extraction
+ # directory so it is re-extracted below.
+ if tarball_updated and os.path.exists(btdir):
+ print("Removing stale %s extraction at %s" % (name, btdir))
+ subprocess.check_call(["rm", "-rf", btdir])
if not os.path.exists(btdir):
- btdlpath = getconfig("BASE_SHAREDDIR", ourconfig) + "/cluster-downloads-cache/" + os.path.basename(bttarball)
print("Extracting %s %s" % (name, bttarball))
- btlock = btdlpath + ".lock"
- if not os.path.exists(os.path.dirname(btdlpath)):
- os.makedirs(os.path.dirname(btdlpath), exist_ok=True)
- while True:
- try:
- with open(btlock, 'a+') as lf:
- fileno = lf.fileno()
- fcntl.flock(fileno, fcntl.LOCK_EX)
- if sha256 and os.path.exists(btdlpath):
- dl_sha256 = sha256_file(btdlpath)
- if dl_sha256 != sha256:
- os.unlink(btdlpath)
- if not os.path.exists(btdlpath):
- if bttarball.startswith("/"):
- subprocess.check_call(["cp", bttarball, btdlpath])
- else:
- subprocess.check_call(["wget", "-O", btdlpath, bttarball])
- os.chmod(btdlpath, 0o775)
- break
- except OSError:
- # We raced with someone else, try again
- pass
subprocess.check_call(["bash", btdlpath, "-d", btdir, "-y"])
enable_tools_tarball(btdir, name)