diff --git a/alibuild_helpers/build.py b/alibuild_helpers/build.py index 576447ec..ee845989 100644 --- a/alibuild_helpers/build.py +++ b/alibuild_helpers/build.py @@ -12,7 +12,7 @@ from alibuild_helpers.utilities import validateDefaults from alibuild_helpers.utilities import Hasher from alibuild_helpers.utilities import yamlDump -from alibuild_helpers.utilities import resolve_tag, resolve_version +from alibuild_helpers.utilities import resolve_tag, resolve_version, short_commit_hash from alibuild_helpers.git import Git, git from alibuild_helpers.sl import Sapling from alibuild_helpers.scm import SCMError @@ -1009,8 +1009,7 @@ def doBuild(args, parser): ("BUILD_REQUIRES", " ".join(spec["build_requires"])), ("CACHED_TARBALL", cachedTarball), ("CAN_DELETE", args.aggressiveCleanup and "1" or ""), - # Shorten the commit hash if it's a real commit hash and not simply the tag. - ("COMMIT_HASH", spec["tag"] if spec["tag"] == spec["commit_hash"] else spec["commit_hash"][:10]), + ("COMMIT_HASH", short_commit_hash(spec)), ("DEPS_HASH", spec.get("deps_hash", "")), ("DEVEL_HASH", spec.get("devel_hash", "")), ("DEVEL_PREFIX", develPrefix), diff --git a/alibuild_helpers/utilities.py b/alibuild_helpers/utilities.py index 747640cb..5f5318eb 100644 --- a/alibuild_helpers/utilities.py +++ b/alibuild_helpers/utilities.py @@ -90,6 +90,18 @@ def resolve_links_path(architecture, package): return "/".join(("TARS", architecture, package)) +def short_commit_hash(spec): + """Shorten the spec's commit hash to make it more human-readable. + + This is complicated by the fact that the commit_hash property is not + necessarily a commit hash, but might be a tag name. If it is a tag name, + return it as-is, else assume it is actually a commit hash and shorten it. + """ + if spec["tag"] == spec["commit_hash"]: + return spec["commit_hash"] + return spec["commit_hash"][:10] + + # Date fields to substitute: they are zero-padded now = datetime.now() nowKwds = { "year": str(now.year), diff --git a/alibuild_helpers/workarea.py b/alibuild_helpers/workarea.py index bfb6cde8..8be3f985 100644 --- a/alibuild_helpers/workarea.py +++ b/alibuild_helpers/workarea.py @@ -10,7 +10,7 @@ from ordereddict import OrderedDict from alibuild_helpers.log import dieOnError, debug, error -from alibuild_helpers.utilities import call_ignoring_oserrors, symlink +from alibuild_helpers.utilities import call_ignoring_oserrors, symlink, short_commit_hash FETCH_LOG_NAME = "fetch-log.txt" @@ -145,7 +145,9 @@ def scm_exec(command, directory=".", check=True): return 0 source_parent_dir = os.path.join(work_dir, "SOURCES", spec["package"], spec["version"]) - source_dir = os.path.join(source_parent_dir, spec["commit_hash"]) + # The build script expects SOURCEDIR to be named after the shortened commit + # hash, not the full one. + source_dir = os.path.join(source_parent_dir, short_commit_hash(spec)) os.makedirs(source_parent_dir, exist_ok=True) if spec["commit_hash"] != spec["tag"]: diff --git a/tests/test_build.py b/tests/test_build.py index e0184355..584476f1 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -104,22 +104,22 @@ GIT_CLONE_REF_ZLIB_ARGS = ("clone", "--bare", "https://github.com/star-externals/zlib", "/sw/MIRROR/zlib", "--filter=blob:none"), ".", False GIT_CLONE_SRC_ZLIB_ARGS = ("clone", "-n", "https://github.com/star-externals/zlib", - "/sw/SOURCES/zlib/v1.2.3/8822efa61f2a385e0bc83ca5819d608111b2168a", + "/sw/SOURCES/zlib/v1.2.3/8822efa61f", "--reference", "/sw/MIRROR/zlib", "--filter=blob:none"), ".", False GIT_SET_URL_ZLIB_ARGS = ("remote", "set-url", "--push", "origin", "https://github.com/star-externals/zlib"), \ - "/sw/SOURCES/zlib/v1.2.3/8822efa61f2a385e0bc83ca5819d608111b2168a", False + "/sw/SOURCES/zlib/v1.2.3/8822efa61f", False GIT_CHECKOUT_ZLIB_ARGS = ("checkout", "-f", "master"), \ - "/sw/SOURCES/zlib/v1.2.3/8822efa61f2a385e0bc83ca5819d608111b2168a", False + "/sw/SOURCES/zlib/v1.2.3/8822efa61f", False GIT_FETCH_REF_ROOT_ARGS = ("fetch", "-f", "https://github.com/root-mirror/root", "+refs/tags/*:refs/tags/*", "+refs/heads/*:refs/heads/*"), "/sw/MIRROR/root", False GIT_CLONE_SRC_ROOT_ARGS = ("clone", "-n", "https://github.com/root-mirror/root", - "/sw/SOURCES/ROOT/v6-08-30/f7b336611753f1f4aaa94222b0d620748ae230c0", + "/sw/SOURCES/ROOT/v6-08-30/f7b3366117", "--reference", "/sw/MIRROR/root", "--filter=blob:none"), ".", False GIT_SET_URL_ROOT_ARGS = ("remote", "set-url", "--push", "origin", "https://github.com/root-mirror/root"), \ - "/sw/SOURCES/ROOT/v6-08-30/f7b336611753f1f4aaa94222b0d620748ae230c0", False + "/sw/SOURCES/ROOT/v6-08-30/f7b3366117", False GIT_CHECKOUT_ROOT_ARGS = ("checkout", "-f", "v6-08-00-patches"), \ - "/sw/SOURCES/ROOT/v6-08-30/f7b336611753f1f4aaa94222b0d620748ae230c0", False + "/sw/SOURCES/ROOT/v6-08-30/f7b3366117", False def dummy_git(args, directory=".", check=True, prompt=True):