Skip to content

Commit

Permalink
Add support for sapling
Browse files Browse the repository at this point in the history
Sapling is a somewhat novel SCM from Facebook / Meta.

It is fully compatible with Git and provides a more powerful
yet userfriendly frontend, modeled after mercurial.

This adds Sapling support in alibuild, including:

* Support for alidist sapling checkouts
* Support for development packages which were cloned via sapling
  • Loading branch information
ktf committed Oct 13, 2023
1 parent c526896 commit 83b2f53
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
9 changes: 8 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, Git
from alibuild_helpers.sl import sapling, Sapling
from alibuild_helpers.sync import (NoRemoteSync, HttpRemoteSync, S3RemoteSync,
Boto3RemoteSync, RsyncRemoteSync)
import yaml
Expand Down Expand Up @@ -62,6 +63,10 @@ def update_git_repos(args, specs, buildOrder, develPkgs):

def update_repo(package, git_prompt):
specs[package]["scm"] = Git()
if package in develPkgs:
localCheckout = os.path.join(os.getcwd(), specs[package]["package"])
if exists("%s/.sl" % localCheckout):
specs[package]["scm"] = Sapling()

Check warning on line 69 in alibuild_helpers/build.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/build.py#L65-L69

Added lines #L65 - L69 were not covered by tests
updateReferenceRepoSpec(args.referenceSources, package, specs[package],
fetch=args.fetchRepos,
usePartialClone=not args.docker,
Expand Down Expand Up @@ -368,8 +373,10 @@ def doBuild(args, parser):
# otherwise we use Sapling
if exists("%s/.git" % args.configDir):
scm = Git()
elif exists("%s/.sl" % args.configDir):
scm = Sapling()

Check warning on line 377 in alibuild_helpers/build.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/build.py#L374-L377

Added lines #L374 - L377 were not covered by tests
else:
error("Cannot find .git directory in %s.", args.configDir)
error("Cannot find SCM directory in %s.", args.configDir)
return 1

Check warning on line 380 in alibuild_helpers/build.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/build.py#L379-L380

Added lines #L379 - L380 were not covered by tests

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

Check warning on line 382 in alibuild_helpers/build.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/build.py#L382

Added line #L382 was not covered by tests
Expand Down
47 changes: 47 additions & 0 deletions alibuild_helpers/sl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from shlex import quote # Python 3.3+
from alibuild_helpers.cmd import getstatusoutput
from alibuild_helpers.log import debug
from alibuild_helpers.scm import SCM

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

class Sapling(SCM):
name = "Sapling"
def checkedOutCommitName(self, directory):
return sapling(("whereami", ), directory)

Check warning on line 12 in alibuild_helpers/sl.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/sl.py#L12

Added line #L12 was not covered by tests
def branchOrRef(self, directory):
# Format is <hash>[+] <branch>
identity = sapling(("identify", ), directory)
return identity.split(" ")[-1]

Check warning on line 16 in alibuild_helpers/sl.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/sl.py#L15-L16

Added lines #L15 - L16 were not covered by tests
def exec(self, *args, **kwargs):
return sapling(*args, **kwargs)

Check warning on line 18 in alibuild_helpers/sl.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/sl.py#L18

Added line #L18 was not covered by tests
def parseRefs(self, output):
return {

Check warning on line 20 in alibuild_helpers/sl.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/sl.py#L20

Added line #L20 was not covered by tests
sl_ref: sl_hash for sl_ref, sep, sl_hash
in (line.partition("\t") for line in output.splitlines()) if sep
}
def listRefsCmd(self):
return ["bookmark", "--list", "--remote", "-R"]

Check warning on line 25 in alibuild_helpers/sl.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/sl.py#L25

Added line #L25 was not covered by tests
def diffCmd(self, directory):
return "cd %s && sl diff && sl status" % directory

Check warning on line 27 in alibuild_helpers/sl.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/sl.py#L27

Added line #L27 was not covered by tests
def checkUntracked(self, line):
return line.startswith("? ")

Check warning on line 29 in alibuild_helpers/sl.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/sl.py#L29

Added line #L29 was not covered by tests

def sapling(args, directory=".", check=True, prompt=True):
debug("Executing sl %s (in directory %s)", " ".join(args), directory)

Check warning on line 32 in alibuild_helpers/sl.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/sl.py#L32

Added line #L32 was not covered by tests
# 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("""\

Check warning on line 38 in alibuild_helpers/sl.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/sl.py#L38

Added line #L38 was not covered by tests
set -e +x
sl -R {directory} {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)

Check warning on line 47 in alibuild_helpers/sl.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/sl.py#L45-L47

Added lines #L45 - L47 were not covered by tests

0 comments on commit 83b2f53

Please sign in to comment.