alibuild 2.0.5__tar.gz → 2.0.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. {alibuild-2.0.5 → alibuild-2.0.7}/PKG-INFO +1 -1
  2. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild.egg-info/PKG-INFO +1 -1
  3. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/_version.py +3 -3
  4. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/migrate.py +36 -15
  5. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/sync.py +75 -1
  6. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/utilities.py +32 -6
  7. {alibuild-2.0.5 → alibuild-2.0.7}/docs/docs/reference.md +59 -1
  8. {alibuild-2.0.5 → alibuild-2.0.7}/docs/docs/user.md +3 -2
  9. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_migrate.py +48 -0
  10. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_parseRecipe.py +112 -1
  11. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_sync.py +144 -0
  12. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_utilities.py +10 -0
  13. {alibuild-2.0.5 → alibuild-2.0.7}/.claude/skills/s3-conditional-writes/SKILL.md +0 -0
  14. {alibuild-2.0.5 → alibuild-2.0.7}/.claude/skills/support-architecture/SKILL.md +0 -0
  15. {alibuild-2.0.5 → alibuild-2.0.7}/.flake8 +0 -0
  16. {alibuild-2.0.5 → alibuild-2.0.7}/.github/dependabot.yml +0 -0
  17. {alibuild-2.0.5 → alibuild-2.0.7}/.github/workflows/documentation.yml +0 -0
  18. {alibuild-2.0.5 → alibuild-2.0.7}/.github/workflows/homebrew.yml +0 -0
  19. {alibuild-2.0.5 → alibuild-2.0.7}/.github/workflows/pr-check.yml +0 -0
  20. {alibuild-2.0.5 → alibuild-2.0.7}/.github/workflows/release.yml +0 -0
  21. {alibuild-2.0.5 → alibuild-2.0.7}/.gitignore +0 -0
  22. {alibuild-2.0.5 → alibuild-2.0.7}/.pylintrc +0 -0
  23. {alibuild-2.0.5 → alibuild-2.0.7}/ANALYTICS.md +0 -0
  24. {alibuild-2.0.5 → alibuild-2.0.7}/DESIGN.md +0 -0
  25. {alibuild-2.0.5 → alibuild-2.0.7}/LICENSE.md +0 -0
  26. {alibuild-2.0.5 → alibuild-2.0.7}/PACKAGING.md +0 -0
  27. {alibuild-2.0.5 → alibuild-2.0.7}/README.rst +0 -0
  28. {alibuild-2.0.5 → alibuild-2.0.7}/REMOTE_STORE_CAS_AC.md +0 -0
  29. {alibuild-2.0.5 → alibuild-2.0.7}/alfaBuild +0 -0
  30. {alibuild-2.0.5 → alibuild-2.0.7}/aliBuild +0 -0
  31. {alibuild-2.0.5 → alibuild-2.0.7}/aliDeps +0 -0
  32. {alibuild-2.0.5 → alibuild-2.0.7}/aliDoctor +0 -0
  33. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild.egg-info/SOURCES.txt +0 -0
  34. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild.egg-info/dependency_links.txt +0 -0
  35. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild.egg-info/requires.txt +0 -0
  36. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild.egg-info/top_level.txt +0 -0
  37. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/__init__.py +0 -0
  38. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/analytics.py +0 -0
  39. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/args.py +0 -0
  40. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/build.py +0 -0
  41. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/build_template.sh +0 -0
  42. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/clean.py +0 -0
  43. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/cmd.py +0 -0
  44. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/completion.py +0 -0
  45. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/completions/__init__.py +0 -0
  46. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/completions/bash.sh +0 -0
  47. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/completions/zsh.sh +0 -0
  48. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/deps.py +0 -0
  49. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/doctor.py +0 -0
  50. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/git.py +0 -0
  51. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/init.py +0 -0
  52. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/install.py +0 -0
  53. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/keyring.json +0 -0
  54. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/log.py +0 -0
  55. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/reconstruct.py +0 -0
  56. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/sandbox.py +0 -0
  57. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/scm.py +0 -0
  58. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/signing.py +0 -0
  59. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/sl.py +0 -0
  60. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/source.py +0 -0
  61. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/sync_reapi.py +0 -0
  62. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/templating_plugin.py +0 -0
  63. {alibuild-2.0.5 → alibuild-2.0.7}/alibuild_helpers/workarea.py +0 -0
  64. {alibuild-2.0.5 → alibuild-2.0.7}/alienv +0 -0
  65. {alibuild-2.0.5 → alibuild-2.0.7}/codecov.yml +0 -0
  66. {alibuild-2.0.5 → alibuild-2.0.7}/debian/changelog +0 -0
  67. {alibuild-2.0.5 → alibuild-2.0.7}/debian/compat +0 -0
  68. {alibuild-2.0.5 → alibuild-2.0.7}/debian/control +0 -0
  69. {alibuild-2.0.5 → alibuild-2.0.7}/debian/copyright +0 -0
  70. {alibuild-2.0.5 → alibuild-2.0.7}/debian/files +0 -0
  71. {alibuild-2.0.5 → alibuild-2.0.7}/debian/rules +0 -0
  72. {alibuild-2.0.5 → alibuild-2.0.7}/docs/SUPPORT +0 -0
  73. {alibuild-2.0.5 → alibuild-2.0.7}/docs/docs/alice_logo.png +0 -0
  74. {alibuild-2.0.5 → alibuild-2.0.7}/docs/docs/deps.png +0 -0
  75. {alibuild-2.0.5 → alibuild-2.0.7}/docs/docs/index.md +0 -0
  76. {alibuild-2.0.5 → alibuild-2.0.7}/docs/docs/quick.md +0 -0
  77. {alibuild-2.0.5 → alibuild-2.0.7}/docs/docs/stylesheets/extra.css +0 -0
  78. {alibuild-2.0.5 → alibuild-2.0.7}/docs/docs/troubleshooting.md +0 -0
  79. {alibuild-2.0.5 → alibuild-2.0.7}/docs/mkdocs.yml +0 -0
  80. {alibuild-2.0.5 → alibuild-2.0.7}/extras/nix/alibuild_nix.jnj +0 -0
  81. {alibuild-2.0.5 → alibuild-2.0.7}/extras/nix/alidist-aliphysics.nix +0 -0
  82. {alibuild-2.0.5 → alibuild-2.0.7}/extras/nix/alidist-helpers.nix +0 -0
  83. {alibuild-2.0.5 → alibuild-2.0.7}/extras/nix/alidist.nix +0 -0
  84. {alibuild-2.0.5 → alibuild-2.0.7}/extras/nix/flake.lock +0 -0
  85. {alibuild-2.0.5 → alibuild-2.0.7}/extras/nix/flake.nix +0 -0
  86. {alibuild-2.0.5 → alibuild-2.0.7}/extras/nix/hyperloop.nix +0 -0
  87. {alibuild-2.0.5 → alibuild-2.0.7}/extras/nix/hyperloopTest.nix +0 -0
  88. {alibuild-2.0.5 → alibuild-2.0.7}/extras/nix/nix-interactive.bash +0 -0
  89. {alibuild-2.0.5 → alibuild-2.0.7}/extras/nix/update-envs.sh +0 -0
  90. {alibuild-2.0.5 → alibuild-2.0.7}/pb +0 -0
  91. {alibuild-2.0.5 → alibuild-2.0.7}/pyproject.toml +0 -0
  92. {alibuild-2.0.5 → alibuild-2.0.7}/requirements.txt +0 -0
  93. {alibuild-2.0.5 → alibuild-2.0.7}/setup.cfg +0 -0
  94. {alibuild-2.0.5 → alibuild-2.0.7}/setup.py +0 -0
  95. {alibuild-2.0.5 → alibuild-2.0.7}/templates/alibuild_nix.jnj +0 -0
  96. {alibuild-2.0.5 → alibuild-2.0.7}/templates/alibuild_to_please.jnj +0 -0
  97. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_analytics.py +0 -0
  98. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_args.py +0 -0
  99. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_build.py +0 -0
  100. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_clean.py +0 -0
  101. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_cmd.py +0 -0
  102. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_completion.py +0 -0
  103. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_deps.py +0 -0
  104. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_doctor.py +0 -0
  105. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_git.py +0 -0
  106. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_hashing.py +0 -0
  107. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_init.py +0 -0
  108. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_install.py +0 -0
  109. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_log.py +0 -0
  110. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_packagelist.py +0 -0
  111. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_reconstruct.py +0 -0
  112. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_sandbox.py +0 -0
  113. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_signing.py +0 -0
  114. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_source.py +0 -0
  115. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_sync_reapi.py +0 -0
  116. {alibuild-2.0.5 → alibuild-2.0.7}/tests/test_workarea.py +0 -0
  117. {alibuild-2.0.5 → alibuild-2.0.7}/tests/testdist/broken1.sh +0 -0
  118. {alibuild-2.0.5 → alibuild-2.0.7}/tests/testdist/broken2.sh +0 -0
  119. {alibuild-2.0.5 → alibuild-2.0.7}/tests/testdist/broken3.sh +0 -0
  120. {alibuild-2.0.5 → alibuild-2.0.7}/tests/testdist/broken4.sh +0 -0
  121. {alibuild-2.0.5 → alibuild-2.0.7}/tests/testdist/broken5.sh +0 -0
  122. {alibuild-2.0.5 → alibuild-2.0.7}/tests/testdist/broken6.sh +0 -0
  123. {alibuild-2.0.5 → alibuild-2.0.7}/tests/testdist/broken7.sh +0 -0
  124. {alibuild-2.0.5 → alibuild-2.0.7}/tests/testdist/clobber-initdotsh.sh +0 -0
  125. {alibuild-2.0.5 → alibuild-2.0.7}/tests/testdist/defaults-o2.sh +0 -0
  126. {alibuild-2.0.5 → alibuild-2.0.7}/tests/testdist/delete-etc.sh +0 -0
  127. {alibuild-2.0.5 → alibuild-2.0.7}/tests/testdist/tracking-env.sh +0 -0
  128. {alibuild-2.0.5 → alibuild-2.0.7}/tox.ini +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: alibuild
3
- Version: 2.0.5
3
+ Version: 2.0.7
4
4
  Summary: ALICE Build Tool
5
5
  Home-page: https://alisw.github.io/alibuild
6
6
  Author: Giulio Eulisse
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: alibuild
3
- Version: 2.0.5
3
+ Version: 2.0.7
4
4
  Summary: ALICE Build Tool
5
5
  Home-page: https://alisw.github.io/alibuild
6
6
  Author: Giulio Eulisse
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '2.0.5'
32
- __version_tuple__ = version_tuple = (2, 0, 5)
31
+ __version__ = version = '2.0.7'
32
+ __version_tuple__ = version_tuple = (2, 0, 7)
33
33
 
34
- __commit_id__ = commit_id = 'gb11291743'
34
+ __commit_id__ = commit_id = 'g194bf901d'
@@ -395,6 +395,28 @@ def _github_raw_base(remote_url):
395
395
  return "https://raw.githubusercontent.com/" + (match.group(1) if match else "alisw/alidist")
396
396
 
397
397
 
398
+ def recipe_from_meta(meta, tarball_path):
399
+ """The recipe an aliBuild 2.0 tarball archives in its .meta.json, or None.
400
+
401
+ Such a tarball is normally in the Action Cache already, and the migration
402
+ loop skips it as present before getting here. It reaches migrate when it was
403
+ uploaded to a plain legacy store, with no Action Cache to write to (e.g. a
404
+ Jenkins daily run with aliBuild 2.0 against b3://). It records no alidist
405
+ commit, so the archived recipe is the only way to migrate it -- and the
406
+ better one, being exactly what was built. A text that does not match its
407
+ recorded digest is not trusted (None: fall back to the alidist commit)."""
408
+ archived = meta.get("recipe") or {}
409
+ text = archived.get("text")
410
+ if not text:
411
+ return None
412
+ digest = "sha256:" + hashlib.sha256(text.encode("utf-8", "ignore")).hexdigest()
413
+ if archived.get("digest") not in (None, digest):
414
+ warning("%s: the archived recipe does not match its digest %s; ignoring it",
415
+ tarball_path, archived.get("digest"))
416
+ return None
417
+ return text
418
+
419
+
398
420
  def recover_recipe(alidist_dir, alidist_commit, package):
399
421
  """Recover the full recipe of `package` at the recorded alidist commit.
400
422
 
@@ -805,21 +827,20 @@ def migrate_tarball(sync, tarball_path, alidist_dir, container_override=None,
805
827
  tarball_path)
806
828
  return None
807
829
  container = container_for_migration(meta["architecture"], container_override)
808
- # Only legacy tarballs carry an alidist commit; current builds record it in the AC
809
- # entry. Checked before the try below, whose handler would otherwise raise a
810
- # second KeyError while reporting the first.
811
- alidist_commit = (meta.get("alidist") or {}).get("commit")
812
- if not alidist_commit:
813
- warning("%s records no alidist commit; skipping (not a legacy tarball -- "
814
- "current builds archive the recipe and are already in the ledger)",
815
- tarball_path)
816
- return None
817
- try:
818
- recipe = recover_recipe(alidist_dir, alidist_commit, meta["package"]["name"])
819
- except Exception as exc: # pylint: disable=broad-except
820
- warning("Could not recover recipe for %s from alidist@%s: %s",
821
- meta["package"]["name"], alidist_commit, exc)
822
- return None
830
+ recipe = recipe_from_meta(meta, tarball_path)
831
+ if recipe is None:
832
+ # aliBuild 1.x tarballs record the alidist commit instead of the recipe.
833
+ alidist_commit = (meta.get("alidist") or {}).get("commit")
834
+ if not alidist_commit:
835
+ warning("%s records neither its recipe nor an alidist commit; skipping "
836
+ "(not migratable)", tarball_path)
837
+ return None
838
+ try:
839
+ recipe = recover_recipe(alidist_dir, alidist_commit, meta["package"]["name"])
840
+ except Exception as exc: # pylint: disable=broad-except
841
+ warning("Could not recover recipe for %s from alidist@%s: %s",
842
+ meta["package"]["name"], alidist_commit, exc)
843
+ return None
823
844
  if verify:
824
845
  ok, reason = verify_recovered_recipe(meta, recipe)
825
846
  if not ok:
@@ -744,6 +744,17 @@ class Boto3RemoteSync:
744
744
  fetch_key = tarball
745
745
  fetch_bucket = self.legacyReadStore
746
746
  redirect = meta.get("WebsiteRedirectLocation")
747
+ dest = os.path.join(self.workdir, store_path, os.path.basename(tarball))
748
+ if redirect and redirect.startswith(("http://", "https://")):
749
+ # An ABSOLUTE target: the store was written with --legacy-links-store,
750
+ # so this tree and the CAS blobs are in different buckets and the stub
751
+ # names the blob by its public URL. It is not a key in any bucket we
752
+ # hold a client for -- stripping the slash and asking our own bucket
753
+ # for "https:/..." 404s, and nothing above catches that -- so fetch it
754
+ # over HTTP, as HttpRemoteSync does for the same stubs.
755
+ if self._fetch_absolute_redirect(redirect, dest):
756
+ return pkg_hash, dest
757
+ continue
747
758
  if redirect:
748
759
  fetch_key = redirect.lstrip("/")
749
760
  fetch_bucket = self.remoteStore
@@ -753,7 +764,6 @@ class Boto3RemoteSync:
753
764
  total_size = int(meta.get("ContentLength", 0))
754
765
  debug("Downloading tarball for %s@%s: %s (%d MB)", spec["package"],
755
766
  spec["version"], tarball, total_size >> 20)
756
- dest = os.path.join(self.workdir, store_path, os.path.basename(tarball))
757
767
  # boto3 invokes Callback with the per-chunk *delta*, not the cumulative
758
768
  # total; byte_progress accumulates it (a raw delta looks stuck at 256 KB).
759
769
  self.s3.download_file(
@@ -766,6 +776,61 @@ class Boto3RemoteSync:
766
776
  ", ".join(spec["remote_hashes"]))
767
777
  return None
768
778
 
779
+ def _is_dangling_stub(self, key):
780
+ """Whether the legacy store object at key redirects to a blob that is gone.
781
+
782
+ Only a definite "not found" counts. Anything else -- a plain tarball, a
783
+ reachable blob, an error while checking -- returns False, because the
784
+ caller then overwrites the store object, and doing that on a transient
785
+ error would replace a good stub for nothing."""
786
+ from botocore.exceptions import ClientError
787
+ try:
788
+ redirect = self.s3.head_object(Bucket=self.legacyWriteStore,
789
+ Key=key).get("WebsiteRedirectLocation")
790
+ except ClientError:
791
+ return False # not there at all, or unreadable: not ours to judge
792
+ if not isinstance(redirect, str) or not redirect:
793
+ return False # a plain tarball
794
+ try:
795
+ if redirect.startswith(("http://", "https://")):
796
+ resp = requests.head(redirect, timeout=15, allow_redirects=True)
797
+ return resp.status_code == 404
798
+ # Relative: the blob is in the bucket we write artifacts to (the CAS
799
+ # bucket for reapi://, the one bucket for a single-bucket store).
800
+ self.s3.head_object(Bucket=self.writeStore, Key=redirect.lstrip("/"))
801
+ return False
802
+ except ClientError as err:
803
+ return err.response["Error"]["Code"] in ("404", "NoSuchKey")
804
+ except RequestException as err:
805
+ debug("Could not check %s's redirect target: %s", key, err)
806
+ return False
807
+
808
+ def _fetch_absolute_redirect(self, url, dest):
809
+ """Download the blob an absolute store redirect names to dest, over HTTP.
810
+
811
+ A content-addressed target names its own digest, so the bytes are checked
812
+ against it. Returns False, leaving nothing at dest, when the blob is gone
813
+ (an expired ephemeral artifact) or does not match: the package is then not
814
+ available and gets rebuilt, which is what the HTTP and reapi backends do."""
815
+ debug("Store object redirects to %s; fetching it over HTTP", url)
816
+ # Always verified: --insecure is about the store endpoint we write through
817
+ # (a loopback proxy, say), never about the public CAS URL a stub names.
818
+ http = HttpRemoteSync(remoteStore=url, architecture=self.architecture,
819
+ workdir=self.workdir, insecure=False)
820
+ if not http.getRetry(url, dest=dest):
821
+ return False
822
+ cas_digest = re.search(r"(?:^|/)cas/sha256/[0-9a-f]{2}/([0-9a-f]{64})$", url)
823
+ if cas_digest:
824
+ sha256 = hashlib.sha256()
825
+ with open(dest, "rb") as tarball:
826
+ for chunk in iter(lambda: tarball.read(1 << 20), b""):
827
+ sha256.update(chunk)
828
+ if sha256.hexdigest() != cas_digest.group(1):
829
+ warning("GET %s: content does not match its sha256, ignoring it", url)
830
+ os.unlink(dest)
831
+ return False
832
+ return True
833
+
769
834
  def fetch_symlinks(self, spec) -> None:
770
835
  from botocore.exceptions import ClientError
771
836
  links_path = resolve_links_path(self.architecture, spec["package"])
@@ -857,6 +922,15 @@ class Boto3RemoteSync:
857
922
  link_path = os.path.join(resolve_links_path(self.architecture, spec["package"]),
858
923
  tarball)
859
924
  tar_exists = self._s3_key_exists(tar_path)
925
+ if tar_exists and self._is_dangling_stub(tar_path):
926
+ # The store object is a reapi redirect stub whose CAS blob has expired.
927
+ # It "exists", but no reader can get a tarball out of it, so treat it as
928
+ # missing: otherwise every later build of this hash fails to fetch it,
929
+ # rebuilds, and then skips the upload because the stub is still there.
930
+ # The link stays: it names this hash, so the ownership check below
931
+ # accepts it, and the upload replaces the stub with real bytes.
932
+ warning("%s is a redirect stub whose blob is gone; replacing it.", tar_path)
933
+ tar_exists = False
860
934
  link_exists = self._s3_key_exists(link_path)
861
935
  if tar_exists and link_exists:
862
936
  debug("%s exists on S3 already, not uploading", tarball)
@@ -395,16 +395,37 @@ def readDefaults(configDir, defaults, error, architecture):
395
395
  if err:
396
396
  error(err)
397
397
  sys.exit(1)
398
+ # arch_env: {<regex>: {VAR: value}}, applied over env for every regex that
399
+ # matches the architecture (re.match, as for "pkg:<regex>" requirements).
400
+ # It lives in the header because aliBuild versions that predate it ignore
401
+ # it there: they keep the plain env, which then acts as the fallback. And
402
+ # the header is not part of any hash, so an architecture no regex matches
403
+ # (Linux, for an "osx.*" entry) keeps exactly the hashes it had.
404
+ archEnv = defaultsMeta.get("arch_env") or {}
405
+ if not isinstance(archEnv, dict) or \
406
+ not all(isinstance(v, dict) for v in archEnv.values()):
407
+ error("In %s: arch_env must map architecture regexes to dictionaries "
408
+ "of variables" % defaultsFilename)
409
+ sys.exit(1)
410
+ for matcher, env in archEnv.items():
411
+ if re.match(matcher, architecture):
412
+ defaultsMeta.setdefault("env", OrderedDict()).update(env)
398
413
  archDefaults = f"{configDir}/defaults-{architecture}.sh"
399
- archMeta = {}
400
- archBody = ""
401
414
  if exists(archDefaults):
402
- err, archMeta, archBody = parseRecipe(getRecipeReader(defaultsFilename))
415
+ # Up to v2.0.5 the general defaults were parsed a second time here instead
416
+ # of this file, and merging their "disable" list raised AttributeError:
417
+ # those versions fail on any architecture that has such a file, so prefer
418
+ # arch_env above for as long as they are in use.
419
+ err, archMeta, archBody = parseRecipe(getRecipeReader(archDefaults))
403
420
  if err:
404
421
  error(err)
405
422
  sys.exit(1)
406
- for x in ["env", "disable", "overrides"]:
407
- defaultsMeta.setdefault(x, {}).update(archMeta.get(x, {}))
423
+ for x in ["env", "overrides"]:
424
+ if archMeta.get(x):
425
+ defaultsMeta.setdefault(x, OrderedDict()).update(archMeta[x])
426
+ if archMeta.get("disable"):
427
+ defaultsMeta["disable"] = asList(defaultsMeta.get("disable", [])) + \
428
+ asList(archMeta["disable"])
408
429
  defaultsBody += "\n# Architecture defaults\n" + archBody
409
430
  return (defaultsMeta, defaultsBody)
410
431
 
@@ -431,7 +452,7 @@ class GitReader:
431
452
  m = re.search(r'^dist:(.*)@([^@]+)$', self.url)
432
453
  fn, gh = m.groups()
433
454
  err, d = git(("show", f"{gh}:{fn.lower()}.sh"),
434
- directory=self.configDir)
455
+ directory=self.configDir, check=False)
435
456
  if err:
436
457
  raise RuntimeError("Cannot read recipe {fn} from reference {gh}.\n"
437
458
  "Make sure you run first (this will not alter your recipes):\n"
@@ -522,6 +543,11 @@ def getPkgDirs(configDir):
522
543
  return pkgDirs
523
544
 
524
545
  def resolveFilename(taps: dict, pkg: str, configDir: str):
546
+ # A recipe pinned in the defaults' overrides (PKG@<ref>) is read with
547
+ # "git show" from the -c repository: it is not a file to look for, and no
548
+ # BITS_PATH directory can shadow it.
549
+ if pkg in taps:
550
+ return (taps[pkg], os.path.abspath(configDir))
525
551
  for d in getPkgDirs(configDir):
526
552
  filename = checkForFilename(taps, pkg, d)
527
553
  if os.path.exists(filename):
@@ -4,6 +4,7 @@ layout: main
4
4
  ---
5
5
 
6
6
  1. [Recipe formats](#recipe-formats)
7
+ 1. [Searching several directories: `BITS_PATH`](#searching-several-directories-bits_path)
7
8
  1. [The header](#the-header)
8
9
  2. [The body](#the-body)
9
10
  3. [Defaults, common requirements for builds](#defaults)
@@ -18,6 +19,35 @@ The recipes themselves are called `<package>.sh` where `<package>` is the name
18
19
  of the package whose build recipe is described. Please note that all recipe
19
20
  filenames are lowercase: _e.g._ the recipe for `ROOT` will be in `root.sh`.
20
21
 
22
+ ### Searching several directories: `BITS_PATH`
23
+
24
+ Recipes can also come from directories other than the `-c` one, listed in the
25
+ `BITS_PATH` environment variable, separated by colons as in `PATH`:
26
+
27
+ ```bash
28
+ export BITS_PATH=/home/user/my-recipes:extra
29
+ aliBuild build O2 --defaults o2
30
+ ```
31
+
32
+ For every package, and for the `defaults-<name>.sh` selected with
33
+ `--defaults`, aliBuild looks in each `BITS_PATH` directory in order and then in
34
+ the `-c` directory, and takes the first `<package>.sh` it finds. So a recipe in
35
+ a `BITS_PATH` directory replaces the one of the same name in alidist, and the
36
+ `-c` directory is always searched last.
37
+
38
+ - A relative entry is taken relative to the `-c` directory, not to the current
39
+ directory: above, `extra` means `alidist/extra`.
40
+ - Empty entries and a trailing colon are ignored; an unset or empty
41
+ `BITS_PATH` means only the `-c` directory is searched.
42
+ - Some files are only read from the `-c` directory: the architecture defaults
43
+ (`defaults-<arch>.sh`, see [below](#architecture-defaults)), and the list of
44
+ available defaults printed when the one requested does not exist.
45
+ - A recipe pinned to a commit in a defaults' `overrides` (`ROOT@<ref>`, see
46
+ [Defaults](#defaults)) is read with `git show` from that commit of the `-c`
47
+ repository, whatever `BITS_PATH` says. The `-c` directory must then be a
48
+ git repository. aliBuild v1.17.15 to v2.0.6 cannot find such a
49
+ recipe and stop with `Package ROOT not found`.
50
+
21
51
  The recipe itself is made up of two parts: an header, and the actual build
22
52
  script, separated by three dashes (`---`) standalone.
23
53
 
@@ -376,6 +406,29 @@ For a more complete example see
376
406
  You can limit which defaults can be applied to a given package by using the
377
407
  `valid_defaults` key.
378
408
 
409
+ ### Per-architecture variables
410
+
411
+ A variable that only means something on some architectures can be set in
412
+ `arch_env`, which maps a regular expression on the architecture (matched
413
+ with `re.match`, as in `requires`) to variables applied over `env`:
414
+
415
+ ```yaml
416
+ env:
417
+ MACOSX_DEPLOYMENT_TARGET: '14.0'
418
+ arch_env:
419
+ "osx.*":
420
+ MACOSX_DEPLOYMENT_TARGET: '26.0'
421
+ ```
422
+
423
+ Every variable in the defaults' `env` is part of the hash of every package,
424
+ on every architecture. Setting a macOS-only variable in `env` therefore
425
+ rebuilds everything on Linux too, whereas changing a value under `arch_env`
426
+ only changes the hashes of the architectures its regular expression
427
+ matches.
428
+
429
+ aliBuild versions before `arch_env` existed ignore it and use `env`, so keep
430
+ a value there as long as such versions build with these defaults.
431
+
379
432
  ### Architecture defaults
380
433
 
381
434
  Architecture defaults are similar to normal defaults but they are
@@ -387,7 +440,12 @@ Their filename is always:
387
440
  defaults-<arch>.sh
388
441
 
389
442
  where `<arch>` is the current architecture. They have precedence over normal
390
- defaults.
443
+ defaults, including their `arch_env`; their `disable` list is added to the
444
+ normal defaults' one.
445
+
446
+ aliBuild up to v2.0.5 does not read this file correctly and fails on any
447
+ architecture for which it exists, whenever the normal defaults have a
448
+ `disable` list. Prefer `arch_env` while such versions are in use.
391
449
 
392
450
  ## Relocation
393
451
 
@@ -427,8 +427,9 @@ aliBuild reconstruct O2 --version nightly-20261015 \
427
427
  `aliBuild migrate` turns tarballs from a classic store into reapi entries, so
428
428
  that releases built before any of this existed become installable and
429
429
  reconstructible. For each tarball it reads the embedded `.meta.json` provenance,
430
- recovers the full recipe from the alidist commit recorded there, synthesises the
431
- Action Cache entry, and writes the CAS blob, the recipe blob, the entry, the
430
+ takes the full recipe from it (tarballs built by aliBuild 2.0 archive it there,
431
+ including those uploaded to a classic store only) or else recovers it from the
432
+ alidist commit recorded there (aliBuild 1.x), synthesises the Action Cache entry, and writes the CAS blob, the recipe blob, the entry, the
432
433
  legacy redirect and the per-package link. The old store is only ever read, never
433
434
  written.
434
435
 
@@ -226,6 +226,54 @@ class MigrateTestCase(unittest.TestCase):
226
226
  self.assertIn("build zlib", recipe) # recovered from alidist
227
227
  self.assertEqual(entry["action"]["package"], "zlib")
228
228
 
229
+ def _meta_with_archived_recipe(self, text, digest=None):
230
+ """The .meta.json of an aliBuild 2.0 build: the recipe, no alidist commit."""
231
+ meta = json.loads(json.dumps(META))
232
+ del meta["alidist"], meta["alibuild_version"]
233
+ meta["recipe"] = {
234
+ "digest": digest or "sha256:" + hashlib.sha256(text.encode()).hexdigest(),
235
+ "text": text, "env": {}, "append_path": {}, "prepend_path": {}}
236
+ return meta
237
+
238
+ def test_migrate_tarball_uses_the_archived_recipe(self):
239
+ # A 2.0 build uploaded to a legacy store only (no Action Cache): it has
240
+ # no alidist commit, and used to be skipped as "already in the ledger".
241
+ text = "package: zlib\nversion: v1.3.1\n---\narchived zlib\n"
242
+ path = self._write_tarball(self._meta_with_archived_recipe(text))
243
+ sync = FakeReapiSync()
244
+ self.assertEqual(migrate_tarball(sync, path, None), "z" * 40)
245
+ entry, _, recipe = sync.calls[0]
246
+ self.assertEqual(recipe, text)
247
+ self.assertEqual(entry["action"]["recipeDigest"],
248
+ "sha256:" + hashlib.sha256(text.encode()).hexdigest())
249
+
250
+ def test_migrate_tarball_prefers_the_archived_recipe(self):
251
+ alidist, commit = self._make_alidist()
252
+ text = "package: zlib\nversion: v1.3.1\n---\narchived zlib\n"
253
+ meta = self._meta_with_archived_recipe(text)
254
+ meta["alidist"] = {"commit": commit}
255
+ sync = FakeReapiSync()
256
+ migrate_tarball(sync, self._write_tarball(meta), alidist)
257
+ self.assertIn("archived zlib", sync.calls[0][2])
258
+
259
+ def test_migrate_tarball_distrusts_a_mismatched_archived_recipe(self):
260
+ text = "package: zlib\n---\narchived zlib\n"
261
+ meta = self._meta_with_archived_recipe(text, digest="sha256:" + "0" * 64)
262
+ sync = FakeReapiSync()
263
+ self.assertIsNone(migrate_tarball(sync, self._write_tarball(meta), None))
264
+ self.assertEqual(sync.calls, [])
265
+ # ... and uses the alidist commit instead when there is one.
266
+ alidist, commit = self._make_alidist()
267
+ meta["alidist"] = {"commit": commit}
268
+ migrate_tarball(sync, self._write_tarball(meta), alidist)
269
+ self.assertIn("build zlib", sync.calls[0][2])
270
+
271
+ def test_migrate_tarball_skips_without_recipe_or_commit(self):
272
+ meta = json.loads(json.dumps(META)) # alidist commit None, no recipe
273
+ sync = FakeReapiSync()
274
+ self.assertIsNone(migrate_tarball(sync, self._write_tarball(meta), None))
275
+ self.assertEqual(sync.calls, [])
276
+
229
277
  def test_migrate_tarball_skips_without_meta(self):
230
278
  alidist, _ = self._make_alidist()
231
279
  path = os.path.join(self.tmp, "nometa.tar.gz")
@@ -1,5 +1,8 @@
1
+ import os
2
+ import shutil
3
+ import tempfile
1
4
  import unittest
2
- from alibuild_helpers.utilities import parseRecipe, getRecipeReader, parseDefaults
5
+ from alibuild_helpers.utilities import parseRecipe, getRecipeReader, parseDefaults, readDefaults
3
6
  from alibuild_helpers.utilities import FileReader, GitReader
4
7
  from alibuild_helpers.utilities import validateDefaults
5
8
  from collections import OrderedDict
@@ -127,6 +130,114 @@ class TestRecipes(unittest.TestCase):
127
130
  self.assertEqual(ok, False)
128
131
  self.assertEqual(out, 'valid_defaults needs to be a string or a list of strings. Found [{}].')
129
132
 
133
+
134
+ DEFAULTS_O2 = """package: defaults-o2
135
+ version: v1
136
+ env:
137
+ CXXSTD: '20'
138
+ MACOSX_DEPLOYMENT_TARGET: '14.0'
139
+ disable:
140
+ - mesos
141
+ ---
142
+ # body
143
+ """
144
+
145
+ DEFAULTS_O2_ARCH_ENV = """package: defaults-o2
146
+ version: v1
147
+ env:
148
+ CXXSTD: '20'
149
+ MACOSX_DEPLOYMENT_TARGET: '14.0'
150
+ arch_env:
151
+ "osx.*":
152
+ MACOSX_DEPLOYMENT_TARGET: '26.0'
153
+ "osx_arm64":
154
+ ARM_ONLY: '1'
155
+ disable:
156
+ - mesos
157
+ ---
158
+ # body
159
+ """
160
+
161
+
162
+ class TestReadDefaults(unittest.TestCase):
163
+ def setUp(self) -> None:
164
+ self.dir = tempfile.mkdtemp()
165
+ self.addCleanup(shutil.rmtree, self.dir)
166
+
167
+ def write(self, name, text) -> None:
168
+ with open(os.path.join(self.dir, name), "w") as f:
169
+ f.write(text)
170
+
171
+ def read(self, arch):
172
+ meta, body = readDefaults(self.dir, "o2", self.fail, arch)
173
+ return meta, body
174
+
175
+ def test_arch_env_applies_only_where_the_regex_matches(self) -> None:
176
+ self.write("defaults-o2.sh", DEFAULTS_O2_ARCH_ENV)
177
+ meta, _ = self.read("osx_arm64")
178
+ self.assertEqual(meta["env"], OrderedDict([("CXXSTD", "20"),
179
+ ("MACOSX_DEPLOYMENT_TARGET", "26.0"),
180
+ ("ARM_ONLY", "1")]))
181
+ meta, _ = self.read("osx_x86-64")
182
+ self.assertEqual(meta["env"]["MACOSX_DEPLOYMENT_TARGET"], "26.0")
183
+ self.assertNotIn("ARM_ONLY", meta["env"])
184
+
185
+ def test_arch_env_leaves_other_architectures_as_they_were(self) -> None:
186
+ # What makes it safe to add: the Linux defaults-release spec is the one it
187
+ # was without arch_env, so no Linux hash changes (the header is not hashed).
188
+ self.write("defaults-o2.sh", DEFAULTS_O2)
189
+ before, _ = self.read("slc9_x86-64")
190
+ _, overrides_before, _ = parseDefaults([], lambda: (before, ""), Recoder())
191
+ self.write("defaults-o2.sh", DEFAULTS_O2_ARCH_ENV)
192
+ after, _ = self.read("slc9_x86-64")
193
+ _, overrides_after, _ = parseDefaults([], lambda: (after, ""), Recoder())
194
+ self.assertEqual(overrides_after["defaults-release"],
195
+ overrides_before["defaults-release"])
196
+ self.assertEqual(after["env"]["MACOSX_DEPLOYMENT_TARGET"], "14.0")
197
+
198
+ def test_arch_env_must_be_a_mapping_of_mappings(self) -> None:
199
+ self.write("defaults-o2.sh", DEFAULTS_O2.replace(
200
+ "disable:", "arch_env:\n osx.*: '26.0'\ndisable:"))
201
+ errors = []
202
+ with self.assertRaises(SystemExit):
203
+ readDefaults(self.dir, "o2", errors.append, "osx_arm64")
204
+ self.assertIn("arch_env", errors[0])
205
+
206
+ def test_architecture_defaults_file_is_read(self) -> None:
207
+ # It used to parse defaults-o2.sh a second time instead, and then fail
208
+ # merging its "disable" list with AttributeError.
209
+ self.write("defaults-o2.sh", DEFAULTS_O2)
210
+ self.write("defaults-osx_arm64.sh", """package: defaults-osx_arm64
211
+ version: v1
212
+ env:
213
+ MACOSX_DEPLOYMENT_TARGET: '26.0'
214
+ disable:
215
+ - Vc
216
+ ---
217
+ # arch body
218
+ """)
219
+ meta, body = self.read("osx_arm64")
220
+ self.assertEqual(meta["env"]["MACOSX_DEPLOYMENT_TARGET"], "26.0")
221
+ self.assertEqual(meta["env"]["CXXSTD"], "20")
222
+ self.assertEqual(meta["disable"], ["mesos", "Vc"])
223
+ self.assertIn("# arch body", body)
224
+ meta, body = self.read("slc9_x86-64")
225
+ self.assertEqual(meta["env"]["MACOSX_DEPLOYMENT_TARGET"], "14.0")
226
+ self.assertEqual(meta["disable"], ["mesos"])
227
+ self.assertNotIn("# arch body", body)
228
+
229
+ def test_architecture_defaults_file_wins_over_arch_env(self) -> None:
230
+ self.write("defaults-o2.sh", DEFAULTS_O2_ARCH_ENV)
231
+ self.write("defaults-osx_arm64.sh", """package: defaults-osx_arm64
232
+ version: v1
233
+ env:
234
+ MACOSX_DEPLOYMENT_TARGET: '15.0'
235
+ ---
236
+ """)
237
+ meta, _ = self.read("osx_arm64")
238
+ self.assertEqual(meta["env"]["MACOSX_DEPLOYMENT_TARGET"], "15.0")
239
+
240
+
130
241
  if __name__ == '__main__':
131
242
  unittest.main()
132
243
 
@@ -1,6 +1,7 @@
1
1
  import hashlib
2
2
  import os
3
3
  import os.path
4
+ import pathlib
4
5
  import sys
5
6
  import tempfile
6
7
  import unittest
@@ -484,6 +485,149 @@ class Boto3TestCase(unittest.TestCase):
484
485
  self.assertTrue(downloaded[0]["Filename"].endswith(
485
486
  store_path + "/" + tarball_name(GOOD_SPEC)))
486
487
 
488
+ def fetch_through_absolute_stub(self, blob_response, digest):
489
+ """Fetch GOOD_SPEC over b3:// from a legacy tree whose store object is a
490
+ stub redirecting by ABSOLUTE URL to a CAS blob in another bucket, as a
491
+ reapi:// build with --legacy-links-store writes it. The blob answers with
492
+ blob_response. Returns (fetch_tarball's result, keys head_object was asked
493
+ for, URLs fetched over HTTP, {path: bytes} left in the work dir)."""
494
+ from botocore.exceptions import ClientError
495
+ store_path = resolve_store_path(ARCHITECTURE, GOOD_HASH)
496
+ tarball_key = store_path + "/" + tarball_name(GOOD_SPEC)
497
+ blob = "https://s3.example/swift/v1/alibuild-cas/cas/sha256/%s/%s" % (
498
+ digest[:2], digest)
499
+ heads, requested = [], []
500
+
501
+ def paginate(Bucket, Delimiter, Prefix):
502
+ if Prefix.rstrip(Delimiter) == store_path:
503
+ return [{"Contents": [{"Key": tarball_key}]}]
504
+ return [{}]
505
+
506
+ def head_object(Bucket, Key):
507
+ heads.append(Key)
508
+ if Key == tarball_key:
509
+ return {"WebsiteRedirectLocation": blob}
510
+ raise ClientError({"Error": {"Code": "404"}}, "head_object")
511
+
512
+ def get(url, *args, **kw):
513
+ requested.append(url)
514
+ return blob_response if url == blob else MockRequest(None)
515
+
516
+ with tempfile.TemporaryDirectory() as workdir, \
517
+ patch("requests.get", side_effect=get):
518
+ # os.makedirs is patched out for this whole class, and this download
519
+ # really writes: make the store directory the real way.
520
+ pathlib.Path(workdir, store_path).mkdir(parents=True)
521
+ b3sync = sync.Boto3RemoteSync(
522
+ remoteStore="b3://alibuild-repo", writeStore="",
523
+ architecture=ARCHITECTURE, workdir=workdir)
524
+ b3sync.s3 = MagicMock(
525
+ get_paginator=lambda method: MagicMock(paginate=paginate),
526
+ head_object=head_object,
527
+ download_file=MagicMock(side_effect=AssertionError(
528
+ "an absolute redirect is not a key in any bucket")))
529
+ result = b3sync.fetch_tarball(GOOD_SPEC)
530
+ left = {}
531
+ for d, _, files in os.walk(workdir):
532
+ for f in files:
533
+ with open(os.path.join(d, f), "rb") as fp:
534
+ left[os.path.relpath(os.path.join(d, f), workdir)] = fp.read()
535
+ if result:
536
+ result = (result[0], os.path.relpath(result[1], workdir))
537
+ return result, heads, requested, left
538
+
539
+ def test_tarball_download_follows_absolute_reapi_redirect(self) -> None:
540
+ """A stub naming its blob by absolute URL is fetched over HTTP and saved
541
+ under the legacy store path. Treating the URL as a key of our own bucket
542
+ ("https:/...") 404ed in head_object and killed the build."""
543
+ digest = hashlib.sha256(b"x" * 123456).hexdigest()
544
+ result, heads, requested, left = self.fetch_through_absolute_stub(
545
+ MockRequest([{"name": "blob"}]), digest)
546
+ store_file = resolve_store_path(ARCHITECTURE, GOOD_HASH) + "/" + tarball_name(GOOD_SPEC)
547
+ self.assertEqual(len(requested), 1)
548
+ self.assertFalse([k for k in heads if "http" in k],
549
+ "the absolute target was used as a key: %s" % heads)
550
+ self.assertEqual(left, {store_file: b"x" * 123456})
551
+ self.assertEqual(result, (GOOD_HASH, store_file))
552
+
553
+ @patch("alibuild_helpers.sync.warning", new=MagicMock())
554
+ def test_absolute_redirect_blob_checked_against_its_digest(self) -> None:
555
+ """Bytes that do not hash to the digest the CAS path names are dropped:
556
+ no tarball, no exception, so the package is rebuilt."""
557
+ result, _, requested, left = self.fetch_through_absolute_stub(
558
+ MockRequest([{"name": "blob"}]), "ab" * 32)
559
+ self.assertEqual(len(requested), 1)
560
+ self.assertIsNone(result)
561
+ self.assertEqual(left, {})
562
+
563
+ @patch("alibuild_helpers.sync.warning", new=MagicMock())
564
+ def test_absolute_redirect_missing_blob_is_not_a_tarball(self) -> None:
565
+ """A stub whose CAS blob is gone (an expired ephemeral artifact) gives no
566
+ tarball and no exception, so the package is rebuilt."""
567
+ gone = MockRequest(None)
568
+ gone.iter_content = lambda chunk_size=10: iter([b"NoSuchKey"])
569
+ gone.headers["content-length"] = "9"
570
+ result, _, requested, left = self.fetch_through_absolute_stub(gone, "fa" * 32)
571
+ self.assertEqual(len(requested), 1)
572
+ self.assertIsNone(result)
573
+ self.assertEqual(left, {})
574
+
575
+ def upload_over_stub(self, redirect, blob_status):
576
+ """Publish GOOD_SPEC over b3:// where its link and store object already
577
+ exist, the store object being a reapi stub redirecting to `redirect`,
578
+ whose blob answers HTTP `blob_status` (absolute) or is missing from the
579
+ write bucket when blob_status is 404 (relative). Returns the keys
580
+ upload_file wrote."""
581
+ from botocore.exceptions import ClientError
582
+ store_path = resolve_store_path(ARCHITECTURE, GOOD_HASH)
583
+ tar_key = store_path + "/" + tarball_name(GOOD_SPEC)
584
+ link_key = resolve_links_path(ARCHITECTURE, PACKAGE) + "/" + tarball_name(GOOD_SPEC)
585
+ link_body = tar_key[len("TARS/"):]
586
+
587
+ def head_object(Bucket, Key):
588
+ if Key == tar_key:
589
+ return {"WebsiteRedirectLocation": redirect}
590
+ if Key == link_key:
591
+ return {}
592
+ if Key == redirect.lstrip("/") and blob_status == 200:
593
+ return {"ContentLength": 4096}
594
+ raise ClientError({"Error": {"Code": "404"}}, "head_object")
595
+
596
+ uploaded = []
597
+ b3sync = sync.Boto3RemoteSync(
598
+ remoteStore="b3://alibuild-repo", writeStore="b3://alibuild-repo",
599
+ architecture=ARCHITECTURE, workdir="/sw")
600
+ b3sync.s3 = MagicMock(
601
+ get_paginator=lambda method: MagicMock(paginate=lambda **kw: [{}]),
602
+ head_object=head_object,
603
+ get_object=lambda Bucket, Key: {"Body": BytesIO(link_body.encode())},
604
+ upload_file=MagicMock(side_effect=lambda **kw: uploaded.append(kw["Key"])))
605
+ with patch("os.listdir", new=MagicMock(return_value=[])), \
606
+ patch("os.path.islink", new=MagicMock(return_value=True)), \
607
+ patch("os.readlink", new=MagicMock(return_value="../../" + link_body)), \
608
+ patch("alibuild_helpers.sync.warning", new=MagicMock()), \
609
+ patch("requests.head", new=MagicMock(
610
+ return_value=MagicMock(status_code=blob_status))):
611
+ b3sync.upload_symlinks_and_tarball(GOOD_SPEC)
612
+ return uploaded, tar_key
613
+
614
+ def test_upload_replaces_stub_whose_blob_is_gone(self) -> None:
615
+ """A stub whose CAS blob expired is replaced by the real tarball. Without
616
+ this, the stub counted as "already uploaded": every later build of the
617
+ hash failed to fetch it, rebuilt, and skipped the upload again."""
618
+ for redirect in ("https://s3.example/swift/v1/alibuild-cas/cas/sha256/ab/" + "ab" * 32,
619
+ "/cas/sha256/ab/" + "ab" * 32):
620
+ uploaded, tar_key = self.upload_over_stub(redirect, 404)
621
+ self.assertEqual(uploaded, [tar_key], redirect)
622
+
623
+ def test_upload_keeps_stub_whose_blob_exists(self) -> None:
624
+ """A stub whose blob is still there is a complete publication: nothing
625
+ is uploaded over it."""
626
+ for redirect in ("https://s3.example/swift/v1/alibuild-cas/cas/sha256/ab/" + "ab" * 32,
627
+ "/cas/sha256/ab/" + "ab" * 32):
628
+ uploaded, _ = self.upload_over_stub(redirect, 200)
629
+ self.assertEqual(uploaded, [], redirect)
630
+
487
631
  @patch("os.listdir", new=lambda path: (
488
632
  [tarball_name(GOOD_SPEC)] if path.endswith("-" + GOOD_SPEC["revision"]) else
489
633
  [tarball_name(BAD_SPEC)] if path.endswith("-" + BAD_SPEC["revision"]) else
@@ -460,6 +460,16 @@ class TestUtilities(unittest.TestCase):
460
460
  self.assertEqual(resolveFilename({}, "zlib", "alidost"), (None, None))
461
461
  self.assertEqual(resolveFilename({}, "python", "alidist"), ("/bar/python.sh", "/bar"))
462
462
 
463
+ # A recipe pinned in the defaults' overrides is not a file: it is read
464
+ # from the -c repository at that ref, whatever BITS_PATH contains.
465
+ taps = {"root": "dist:ROOT@v6-32-00"}
466
+ with patch.object(os.path, "exists", fake_exists), \
467
+ patch.object(os.path, "abspath", fake_abspath), \
468
+ patch.object(os, "environ", {"BITS_PATH": "/bar:/foo"}):
469
+ self.assertEqual(resolveFilename(taps, "root", "alidist"),
470
+ ("dist:ROOT@v6-32-00", "/fake/alidist"))
471
+ self.assertEqual(resolveFilename(taps, "python", "alidist"), ("/bar/python.sh", "/bar"))
472
+
463
473
 
464
474
  class TestTopologicalSort(unittest.TestCase):
465
475
  """Check that various properties of topological sorting hold."""
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes