Skip to content

Commit

Permalink
Add support for sapling
Browse files Browse the repository at this point in the history
  • Loading branch information
ktf committed Oct 6, 2023
1 parent 8c9fee6 commit 6fe1442
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
21 changes: 20 additions & 1 deletion alibuild_helpers/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from alibuild_helpers.utilities import yamlDump
from alibuild_helpers.utilities import resolve_tag, resolve_version
from alibuild_helpers.git import git, clone_speedup_options
from alibuild_helpers.sl import sapling
from alibuild_helpers.sync import (NoRemoteSync, HttpRemoteSync, S3RemoteSync,
Boto3RemoteSync, RsyncRemoteSync)
import yaml
Expand Down Expand Up @@ -318,6 +319,17 @@ def better_tarball(spec, old, new):
hashes = spec["local_hashes" if old_is_local else "remote_hashes"]
return old if hashes.index(old_hash) < hashes.index(new_hash) else new

class SCM(object):
def whereAmI(self, directory):
raise NotImplementedError

class Git(SCM):
def whereAmI(self, directory):
return git(("rev-parse", "HEAD"), directory)

class Sapling(SCM):
def whereAmI(self, directory):
return sapling(("whereami", ), directory)

def doBuild(args, parser):
if args.remoteStore.startswith("http"):
Expand Down Expand Up @@ -363,7 +375,14 @@ def doBuild(args, parser):
if not exists(specDir):
makedirs(specDir)

os.environ["ALIBUILD_ALIDIST_HASH"] = git(("rev-parse", "HEAD"), directory=args.configDir)
# if the alidist workdir contains a .git directory, we use Git as SCM
# otherwise we use Sapling
if exists("%s/.git" % args.configDir):
scm = Git()
else:
scm = Sapling()

os.environ["ALIBUILD_ALIDIST_HASH"] = scm.whereAmI(directory=args.configDir)

debug("Building for architecture %s", args.architecture)
debug("Number of parallel builds: %d", args.jobs)
Expand Down
25 changes: 25 additions & 0 deletions alibuild_helpers/sl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from shlex import quote # Python 3.3+
from alibuild_helpers.cmd import getstatusoutput
from alibuild_helpers.log import debug

SL_COMMAND_TIMEOUT_SEC = 120
"""How many seconds to let any sl command execute before being terminated."""

def sapling(args, directory=".", check=True, prompt=True):
debug("Executing sl %s (in directory %s)", " ".join(args), directory)
# We can't use git --git-dir=%s/.git or git -C %s here as the former requires
# that the directory we're inspecting to be the root of a git directory, not
# just contained in one (and that breaks CI tests), and the latter isn't
# supported by the git version we have on slc6.
# Silence cd as shell configuration can cause the new directory to be echoed.
err, output = getstatusoutput("""\
set -e +x
cd {directory} >/dev/null 2>&1
sl {args}
""".format(
directory=quote(directory),
args=" ".join(map(quote, args)),
), timeout=SL_COMMAND_TIMEOUT_SEC)
if check and err != 0:
raise RuntimeError("Error {} from sl {}: {}".format(err, " ".join(args), output))
return output if check else (err, output)

0 comments on commit 6fe1442

Please sign in to comment.