Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix source checkout with bare commit hash #837

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions alibuild_helpers/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
12 changes: 12 additions & 0 deletions alibuild_helpers/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 4 additions & 2 deletions alibuild_helpers/workarea.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"]:
Expand Down
12 changes: 6 additions & 6 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading