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 10, 2023
1 parent 6bafdb2 commit a18c8c7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
30 changes: 29 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 @@ -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,6 +373,27 @@ def diffCmd(self, directory):
def checkUntracked(self, line):
return line.startswith("?? ")

Check warning on line 374 in alibuild_helpers/build.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/build.py#L374

Added line #L374 was not covered by tests

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

Check warning on line 379 in alibuild_helpers/build.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/build.py#L379

Added line #L379 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 383 in alibuild_helpers/build.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/build.py#L382-L383

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

Check warning on line 385 in alibuild_helpers/build.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/build.py#L385

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

Check warning on line 387 in alibuild_helpers/build.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/build.py#L387

Added line #L387 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 prefecthCmd(self):
return ["bookmark", "--list", "--remote", "-R"]

Check warning on line 392 in alibuild_helpers/build.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/build.py#L392

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

Check warning on line 394 in alibuild_helpers/build.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/build.py#L394

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

Check warning on line 396 in alibuild_helpers/build.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/build.py#L396

Added line #L396 was not covered by tests

def doBuild(args, parser):
if args.remoteStore.startswith("http"):
Expand Down Expand Up @@ -417,8 +443,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 447 in alibuild_helpers/build.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/build.py#L444-L447

Added lines #L444 - L447 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 450 in alibuild_helpers/build.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/build.py#L449-L450

Added lines #L449 - L450 were not covered by tests

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

Check warning on line 452 in alibuild_helpers/build.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/build.py#L452

Added line #L452 was not covered by tests
Expand Down
24 changes: 24 additions & 0 deletions alibuild_helpers/sl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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)

Check warning on line 9 in alibuild_helpers/sl.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/sl.py#L9

Added line #L9 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 15 in alibuild_helpers/sl.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/sl.py#L15

Added line #L15 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 24 in alibuild_helpers/sl.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/sl.py#L22-L24

Added lines #L22 - L24 were not covered by tests

0 comments on commit a18c8c7

Please sign in to comment.