alibuild 2.0.4__tar.gz → 2.0.6__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.4 → alibuild-2.0.6}/PKG-INFO +1 -1
  2. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild.egg-info/PKG-INFO +1 -1
  3. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/_version.py +3 -3
  4. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/sync.py +75 -1
  5. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/sync_reapi.py +3 -1
  6. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/utilities.py +26 -5
  7. {alibuild-2.0.4 → alibuild-2.0.6}/docs/docs/reference.md +29 -1
  8. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_parseRecipe.py +112 -1
  9. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_sync.py +144 -0
  10. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_sync_reapi.py +19 -0
  11. {alibuild-2.0.4 → alibuild-2.0.6}/.claude/skills/s3-conditional-writes/SKILL.md +0 -0
  12. {alibuild-2.0.4 → alibuild-2.0.6}/.claude/skills/support-architecture/SKILL.md +0 -0
  13. {alibuild-2.0.4 → alibuild-2.0.6}/.flake8 +0 -0
  14. {alibuild-2.0.4 → alibuild-2.0.6}/.github/dependabot.yml +0 -0
  15. {alibuild-2.0.4 → alibuild-2.0.6}/.github/workflows/documentation.yml +0 -0
  16. {alibuild-2.0.4 → alibuild-2.0.6}/.github/workflows/homebrew.yml +0 -0
  17. {alibuild-2.0.4 → alibuild-2.0.6}/.github/workflows/pr-check.yml +0 -0
  18. {alibuild-2.0.4 → alibuild-2.0.6}/.github/workflows/release.yml +0 -0
  19. {alibuild-2.0.4 → alibuild-2.0.6}/.gitignore +0 -0
  20. {alibuild-2.0.4 → alibuild-2.0.6}/.pylintrc +0 -0
  21. {alibuild-2.0.4 → alibuild-2.0.6}/ANALYTICS.md +0 -0
  22. {alibuild-2.0.4 → alibuild-2.0.6}/DESIGN.md +0 -0
  23. {alibuild-2.0.4 → alibuild-2.0.6}/LICENSE.md +0 -0
  24. {alibuild-2.0.4 → alibuild-2.0.6}/PACKAGING.md +0 -0
  25. {alibuild-2.0.4 → alibuild-2.0.6}/README.rst +0 -0
  26. {alibuild-2.0.4 → alibuild-2.0.6}/REMOTE_STORE_CAS_AC.md +0 -0
  27. {alibuild-2.0.4 → alibuild-2.0.6}/alfaBuild +0 -0
  28. {alibuild-2.0.4 → alibuild-2.0.6}/aliBuild +0 -0
  29. {alibuild-2.0.4 → alibuild-2.0.6}/aliDeps +0 -0
  30. {alibuild-2.0.4 → alibuild-2.0.6}/aliDoctor +0 -0
  31. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild.egg-info/SOURCES.txt +0 -0
  32. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild.egg-info/dependency_links.txt +0 -0
  33. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild.egg-info/requires.txt +0 -0
  34. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild.egg-info/top_level.txt +0 -0
  35. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/__init__.py +0 -0
  36. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/analytics.py +0 -0
  37. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/args.py +0 -0
  38. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/build.py +0 -0
  39. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/build_template.sh +0 -0
  40. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/clean.py +0 -0
  41. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/cmd.py +0 -0
  42. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/completion.py +0 -0
  43. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/completions/__init__.py +0 -0
  44. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/completions/bash.sh +0 -0
  45. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/completions/zsh.sh +0 -0
  46. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/deps.py +0 -0
  47. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/doctor.py +0 -0
  48. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/git.py +0 -0
  49. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/init.py +0 -0
  50. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/install.py +0 -0
  51. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/keyring.json +0 -0
  52. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/log.py +0 -0
  53. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/migrate.py +0 -0
  54. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/reconstruct.py +0 -0
  55. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/sandbox.py +0 -0
  56. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/scm.py +0 -0
  57. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/signing.py +0 -0
  58. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/sl.py +0 -0
  59. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/source.py +0 -0
  60. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/templating_plugin.py +0 -0
  61. {alibuild-2.0.4 → alibuild-2.0.6}/alibuild_helpers/workarea.py +0 -0
  62. {alibuild-2.0.4 → alibuild-2.0.6}/alienv +0 -0
  63. {alibuild-2.0.4 → alibuild-2.0.6}/codecov.yml +0 -0
  64. {alibuild-2.0.4 → alibuild-2.0.6}/debian/changelog +0 -0
  65. {alibuild-2.0.4 → alibuild-2.0.6}/debian/compat +0 -0
  66. {alibuild-2.0.4 → alibuild-2.0.6}/debian/control +0 -0
  67. {alibuild-2.0.4 → alibuild-2.0.6}/debian/copyright +0 -0
  68. {alibuild-2.0.4 → alibuild-2.0.6}/debian/files +0 -0
  69. {alibuild-2.0.4 → alibuild-2.0.6}/debian/rules +0 -0
  70. {alibuild-2.0.4 → alibuild-2.0.6}/docs/SUPPORT +0 -0
  71. {alibuild-2.0.4 → alibuild-2.0.6}/docs/docs/alice_logo.png +0 -0
  72. {alibuild-2.0.4 → alibuild-2.0.6}/docs/docs/deps.png +0 -0
  73. {alibuild-2.0.4 → alibuild-2.0.6}/docs/docs/index.md +0 -0
  74. {alibuild-2.0.4 → alibuild-2.0.6}/docs/docs/quick.md +0 -0
  75. {alibuild-2.0.4 → alibuild-2.0.6}/docs/docs/stylesheets/extra.css +0 -0
  76. {alibuild-2.0.4 → alibuild-2.0.6}/docs/docs/troubleshooting.md +0 -0
  77. {alibuild-2.0.4 → alibuild-2.0.6}/docs/docs/user.md +0 -0
  78. {alibuild-2.0.4 → alibuild-2.0.6}/docs/mkdocs.yml +0 -0
  79. {alibuild-2.0.4 → alibuild-2.0.6}/extras/nix/alibuild_nix.jnj +0 -0
  80. {alibuild-2.0.4 → alibuild-2.0.6}/extras/nix/alidist-aliphysics.nix +0 -0
  81. {alibuild-2.0.4 → alibuild-2.0.6}/extras/nix/alidist-helpers.nix +0 -0
  82. {alibuild-2.0.4 → alibuild-2.0.6}/extras/nix/alidist.nix +0 -0
  83. {alibuild-2.0.4 → alibuild-2.0.6}/extras/nix/flake.lock +0 -0
  84. {alibuild-2.0.4 → alibuild-2.0.6}/extras/nix/flake.nix +0 -0
  85. {alibuild-2.0.4 → alibuild-2.0.6}/extras/nix/hyperloop.nix +0 -0
  86. {alibuild-2.0.4 → alibuild-2.0.6}/extras/nix/hyperloopTest.nix +0 -0
  87. {alibuild-2.0.4 → alibuild-2.0.6}/extras/nix/nix-interactive.bash +0 -0
  88. {alibuild-2.0.4 → alibuild-2.0.6}/extras/nix/update-envs.sh +0 -0
  89. {alibuild-2.0.4 → alibuild-2.0.6}/pb +0 -0
  90. {alibuild-2.0.4 → alibuild-2.0.6}/pyproject.toml +0 -0
  91. {alibuild-2.0.4 → alibuild-2.0.6}/requirements.txt +0 -0
  92. {alibuild-2.0.4 → alibuild-2.0.6}/setup.cfg +0 -0
  93. {alibuild-2.0.4 → alibuild-2.0.6}/setup.py +0 -0
  94. {alibuild-2.0.4 → alibuild-2.0.6}/templates/alibuild_nix.jnj +0 -0
  95. {alibuild-2.0.4 → alibuild-2.0.6}/templates/alibuild_to_please.jnj +0 -0
  96. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_analytics.py +0 -0
  97. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_args.py +0 -0
  98. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_build.py +0 -0
  99. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_clean.py +0 -0
  100. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_cmd.py +0 -0
  101. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_completion.py +0 -0
  102. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_deps.py +0 -0
  103. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_doctor.py +0 -0
  104. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_git.py +0 -0
  105. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_hashing.py +0 -0
  106. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_init.py +0 -0
  107. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_install.py +0 -0
  108. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_log.py +0 -0
  109. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_migrate.py +0 -0
  110. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_packagelist.py +0 -0
  111. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_reconstruct.py +0 -0
  112. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_sandbox.py +0 -0
  113. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_signing.py +0 -0
  114. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_source.py +0 -0
  115. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_utilities.py +0 -0
  116. {alibuild-2.0.4 → alibuild-2.0.6}/tests/test_workarea.py +0 -0
  117. {alibuild-2.0.4 → alibuild-2.0.6}/tests/testdist/broken1.sh +0 -0
  118. {alibuild-2.0.4 → alibuild-2.0.6}/tests/testdist/broken2.sh +0 -0
  119. {alibuild-2.0.4 → alibuild-2.0.6}/tests/testdist/broken3.sh +0 -0
  120. {alibuild-2.0.4 → alibuild-2.0.6}/tests/testdist/broken4.sh +0 -0
  121. {alibuild-2.0.4 → alibuild-2.0.6}/tests/testdist/broken5.sh +0 -0
  122. {alibuild-2.0.4 → alibuild-2.0.6}/tests/testdist/broken6.sh +0 -0
  123. {alibuild-2.0.4 → alibuild-2.0.6}/tests/testdist/broken7.sh +0 -0
  124. {alibuild-2.0.4 → alibuild-2.0.6}/tests/testdist/clobber-initdotsh.sh +0 -0
  125. {alibuild-2.0.4 → alibuild-2.0.6}/tests/testdist/defaults-o2.sh +0 -0
  126. {alibuild-2.0.4 → alibuild-2.0.6}/tests/testdist/delete-etc.sh +0 -0
  127. {alibuild-2.0.4 → alibuild-2.0.6}/tests/testdist/tracking-env.sh +0 -0
  128. {alibuild-2.0.4 → alibuild-2.0.6}/tox.ini +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: alibuild
3
- Version: 2.0.4
3
+ Version: 2.0.6
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.4
3
+ Version: 2.0.6
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.4'
32
- __version_tuple__ = version_tuple = (2, 0, 4)
31
+ __version__ = version = '2.0.6'
32
+ __version_tuple__ = version_tuple = (2, 0, 6)
33
33
 
34
- __commit_id__ = commit_id = 'g923d84715'
34
+ __commit_id__ = commit_id = 'g53d1fd621'
@@ -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)
@@ -610,7 +610,9 @@ class REAPIRemoteSync(Boto3RemoteSync):
610
610
  """Return the retention tag value of an object, or None if untagged/absent."""
611
611
  from botocore.exceptions import ClientError
612
612
  try:
613
- tags = self.s3.get_object_tagging(Bucket=bucket, Key=key)["TagSet"]
613
+ # An untagged object (e.g. uploaded before retention tags existed)
614
+ # comes back from Ceph RGW without a TagSet at all, not an empty one.
615
+ tags = self.s3.get_object_tagging(Bucket=bucket, Key=key).get("TagSet", [])
614
616
  except ClientError:
615
617
  return None
616
618
  return next((t["Value"] for t in tags if t["Key"] == self.RETENTION_TAG_KEY), None)
@@ -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
 
@@ -376,6 +376,29 @@ For a more complete example see
376
376
  You can limit which defaults can be applied to a given package by using the
377
377
  `valid_defaults` key.
378
378
 
379
+ ### Per-architecture variables
380
+
381
+ A variable that only means something on some architectures can be set in
382
+ `arch_env`, which maps a regular expression on the architecture (matched
383
+ with `re.match`, as in `requires`) to variables applied over `env`:
384
+
385
+ ```yaml
386
+ env:
387
+ MACOSX_DEPLOYMENT_TARGET: '14.0'
388
+ arch_env:
389
+ "osx.*":
390
+ MACOSX_DEPLOYMENT_TARGET: '26.0'
391
+ ```
392
+
393
+ Every variable in the defaults' `env` is part of the hash of every package,
394
+ on every architecture. Setting a macOS-only variable in `env` therefore
395
+ rebuilds everything on Linux too, whereas changing a value under `arch_env`
396
+ only changes the hashes of the architectures its regular expression
397
+ matches.
398
+
399
+ aliBuild versions before `arch_env` existed ignore it and use `env`, so keep
400
+ a value there as long as such versions build with these defaults.
401
+
379
402
  ### Architecture defaults
380
403
 
381
404
  Architecture defaults are similar to normal defaults but they are
@@ -387,7 +410,12 @@ Their filename is always:
387
410
  defaults-<arch>.sh
388
411
 
389
412
  where `<arch>` is the current architecture. They have precedence over normal
390
- defaults.
413
+ defaults, including their `arch_env`; their `disable` list is added to the
414
+ normal defaults' one.
415
+
416
+ aliBuild up to v2.0.5 does not read this file correctly and fails on any
417
+ architecture for which it exists, whenever the normal defaults have a
418
+ `disable` list. Prefer `arch_env` while such versions are in use.
391
419
 
392
420
  ## Relocation
393
421
 
@@ -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
@@ -696,6 +696,25 @@ class REAPIRemoteSyncTestCase(unittest.TestCase):
696
696
  reapi.download_artifact(REAPI_CONTENT_HASH, "/tmp/x")
697
697
  client.copy_object.assert_not_called() # fresh (10d < 60d), no refresh
698
698
 
699
+ @patch("os.path.exists", new=MagicMock(return_value=False))
700
+ def test_download_old_untagged_blob(self) -> None:
701
+ # A blob from before retention tags: Ceph RGW answers GetObjectTagging
702
+ # with no TagSet at all. That must read as "untagged" (no refresh),
703
+ # not crash the build with KeyError.
704
+ from datetime import datetime, timezone, timedelta
705
+ client = self.make_client()
706
+ client.get_object_tagging = MagicMock(return_value={"ResponseMetadata": {}})
707
+ client.head_object = MagicMock(
708
+ return_value={"LastModified": datetime.now(timezone.utc) - timedelta(days=400)})
709
+ client.copy_object = MagicMock()
710
+ reapi = sync_reapi.REAPIRemoteSync("reapi://localhost/bucket", "reapi://localhost/bucket",
711
+ architecture=ARCHITECTURE, workdir="/sw",
712
+ storage="ephemeral")
713
+ reapi.s3 = client
714
+ self.assertIsNone(reapi._retention_of("bucket", "key"))
715
+ reapi.download_artifact(REAPI_CONTENT_HASH, "/tmp/x")
716
+ client.copy_object.assert_not_called()
717
+
699
718
  @patch("glob.glob", new=MagicMock(return_value=[]))
700
719
  @patch("os.makedirs", new=MagicMock())
701
720
  def test_fetch_via_action_cache(self) -> None:
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
File without changes
File without changes