sapling: 0.2.20240718-145624+f4e9df48 -> 0.2.20250521-115337+25ed6ac4

Fixes: #459551

Signed-off-by: William Phetsinorath <william.phetsinorath@shikanime.studio>
Change-Id: I3f79614811b654db41ac4d2db4bbf2cc6a6a6964
This commit is contained in:
William Phetsinorath
2026-01-06 04:02:10 +01:00
parent 8fb96d077a
commit edfdc195dd
5 changed files with 5065 additions and 3857 deletions
+4927 -3742
View File
File diff suppressed because it is too large Load Diff
-5
View File
@@ -1,5 +0,0 @@
{
"links": [],
"version": "0.2.20240718-145624+f4e9df48",
"versionHash": "7014953821350190751"
}
-69
View File
@@ -1,69 +0,0 @@
#!/usr/bin/env nix-shell
#!nix-shell -i python3 -p cargo -p "python3.withPackages (ps: with ps; [ requests ])"
import json
import pathlib
import re
import tempfile
import os
import shutil
from hashlib import sha1
from struct import unpack
from subprocess import run
import subprocess
from requests import get
# Fetch the latest stable release metadata from GitHub
releaseMetadata = get("https://api.github.com/repos/facebook/sapling/releases/latest").json()
latestTag = releaseMetadata["tag_name"]
latestTarballURL = releaseMetadata["tarball_url"]
[_tarballHash, sourceDirectory] = run(
["nix-prefetch-url", "--print-path", "--unpack", latestTarballURL],
check=True,
text=True,
stdout=subprocess.PIPE,
).stdout.rstrip().splitlines()
def updateCargoLock():
with tempfile.TemporaryDirectory() as tempDir:
tempDir = pathlib.Path(tempDir)
# NOTE(strager): We cannot use shutil.tree because it copies the
# read-only permissions.
for dirpath, dirnames, filenames in os.walk(sourceDirectory):
relativeDirpath = os.path.relpath(dirpath, sourceDirectory)
for filename in filenames:
shutil.copy(os.path.join(dirpath, filename), tempDir / relativeDirpath / filename)
for dirname in dirnames:
os.mkdir(tempDir / relativeDirpath / dirname)
run(["cargo", "fetch"], check=True, cwd=tempDir / "eden" / "scm")
shutil.copy(tempDir / "eden" / "scm" / "Cargo.lock", "Cargo.lock")
updateCargoLock()
def nixPrefetchUrl(url):
return run(
["nix-prefetch-url", "--type", "sha256", url],
check=True,
text=True,
capture_output=True,
).stdout.rstrip()
# Fetch the `setup.py` source and look for instances of assets being downloaded
# from files.pythonhosted.org.
setupPy = (pathlib.Path(sourceDirectory) / "eden/scm/setup.py").read_text()
foundUrls = re.findall(r'(https://files\.pythonhosted\.org/packages/[^\s]+)"', setupPy)
dataDeps = {
"links": [{"url": url, "sha256": nixPrefetchUrl(url)} for url in foundUrls],
"version": latestTag,
# Find latest's git tag which corresponds to the Sapling version. Also
# needed is a hash of the version, so calculate that here. Taken from
# Sapling source `$root/eden/scm/setup_with_version.py`.
"versionHash": str(unpack(">Q", sha1(latestTag.encode("ascii")).digest()[:8])[0]),
}
open("deps.json", "w").write(json.dumps(dataDeps, indent=2, sort_keys=True) + "\n")
+40 -41
View File
@@ -1,11 +1,12 @@
{
lib,
stdenv,
python311Packages,
python312Packages,
fetchFromGitHub,
fetchurl,
cargo,
curl,
gettext,
libclang,
pkg-config,
openssl,
rustPlatform,
@@ -16,12 +17,14 @@
fixup-yarn-lock,
glibcLocales,
libiconv,
versionCheckHook,
enableMinimal ? false,
}:
let
inherit (lib.importJSON ./deps.json) links version versionHash;
version = "0.2.20250521-115337+25ed6ac4";
# Sapling sets a Cargo config containing lines like so:
# [target.aarch64-apple-darwin]
# rustflags = ["-C", "link-args=-Wl,-undefined,dynamic_lookup"]
@@ -41,8 +44,8 @@ let
src = fetchFromGitHub {
owner = "facebook";
repo = "sapling";
rev = version;
hash = "sha256-4pOpJ91esTSH90MvvMu74CnlLULLUawqxcniUeqnLwA=";
tag = version;
hash = "sha256-NvfSx6BMbwOFY+y6Yb/tyUNYeuL8WCoc+HSVys8Ko0Y=";
};
addonsSrc = "${src}/addons";
@@ -50,7 +53,7 @@ let
# Fetches the Yarn modules in Nix to to be used as an offline cache
yarnOfflineCache = fetchYarnDeps {
yarnLock = "${addonsSrc}/yarn.lock";
sha256 = "sha256-jCtrflwDrwql6rY1ff1eXLKdwmnXhg5bCJPlCczBCIk=";
sha256 = "sha256-9l4lSzFTF5rSByO388tosJCxOb65Nnua6HaDD7F62No=";
};
# Builds the NodeJS server that runs with `sl web`
@@ -78,7 +81,7 @@ let
substituteInPlace build-tar.py \
--replace-fail 'run(yarn + ["--cwd", src_join(), "install", "--prefer-offline"])' 'pass'
${python311Packages.python}/bin/python3 build-tar.py \
${python312Packages.python}/bin/python3 build-tar.py \
--output isl-dist.tar.xz \
--yarn 'yarn --offline --frozen-lockfile --ignore-engines --ignore-scripts --no-progress'
@@ -96,7 +99,7 @@ let
};
in
# Builds the main `sl` binary and its Python extensions
python311Packages.buildPythonApplication {
python312Packages.buildPythonApplication {
format = "setuptools";
pname = "sapling";
inherit src version;
@@ -108,14 +111,19 @@ python311Packages.buildPythonApplication {
lockFile = ./Cargo.lock;
outputHashes = {
"abomonation-0.7.3+smallvec1" = "sha256-AxEXR6GC8gHjycIPOfoViP7KceM29p2ZISIt4iwJzvM=";
"cloned-0.1.0" = "sha256-2BaNR/pQmR7pHtRf6VBQLcZgLHbj2JCxeX4auAB0efU=";
"fb303_core-0.0.0" = "sha256-PDGdKjR6KPv1uH1JSTeoG5Rs0ZkmNJLqqSXtvV3RWic=";
"fbthrift-0.0.1+unstable" = "sha256-J4REXGuLjHyN3SHilSWhMoqpRcn1QnEtsTsZF4Z3feU=";
"serde_bser-0.4.0" = "sha256-Su1IP3NzQu/87p/+uQaG8JcICL9hit3OV1O9oFiACsQ=";
"cloned-0.1.0" = "sha256-026OKsszbF2aPWpA8JBc6KwZHxEqwnKIluzDjO/opgc=";
"fb303_core-0.0.0" = "sha256-IJKAWgBLrLnWItw6UTNdwjuTDO6dUfqyKsVv2aW6Kyo=";
"fbthrift-0.0.1+unstable" = "sha256-FuUo1cZG7Ed+TAXY53MpylBPGzFruIsWaxKPR26TxVk=";
"serde_bser-0.4.0" = "sha256-OY+IZh4nz5ICrDKYr8pPfORW4i8KBULhGC5YyXb5Ulg=";
"watchman_client-0.9.0" = "sha256-OY+IZh4nz5ICrDKYr8pPfORW4i8KBULhGC5YyXb5Ulg=";
};
};
postPatch = ''
cp ${./Cargo.lock} Cargo.lock
substituteInPlace sapling/thirdparty/pysocks/setup.py \
--replace-fail 'os.path.dirname(__file__)' "\"$out/lib/${python312Packages.python.libPrefix}/site-packages/sapling/thirdparty/pysocks\""
''
+ lib.optionalString (!enableMinimal) ''
# If asked, we optionally patch in a hardcoded path to the
@@ -125,17 +133,6 @@ python311Packages.buildPythonApplication {
--replace '"#);' $'[web]\nnode-path=${nodejs}/bin/node\n"#);'
'';
# Since the derivation builder doesn't have network access to remain pure,
# fetch the artifacts manually and link them. Then replace the hardcoded URLs
# with filesystem paths for the curl calls.
postUnpack = ''
mkdir $sourceRoot/hack_pydeps
${lib.concatStrings (
map (li: "ln -s ${fetchurl li} $sourceRoot/hack_pydeps/${baseNameOf li.url}\n") links
)}
sed -i "s|https://files.pythonhosted.org/packages/[[:alnum:]]*/[[:alnum:]]*/[[:alnum:]]*/|file://$NIX_BUILD_TOP/$sourceRoot/hack_pydeps/|g" $sourceRoot/setup.py
'';
postInstall = ''
install ${isl}/isl-dist.tar.xz $out/lib/isl-dist.tar.xz
'';
@@ -151,7 +148,8 @@ python311Packages.buildPythonApplication {
myCargoSetupHook
cargo
rustc
];
]
++ lib.optionals stdenv.hostPlatform.isLinux [ gettext ];
buildInputs = [
openssl
@@ -162,26 +160,27 @@ python311Packages.buildPythonApplication {
];
HGNAME = "sl";
LIBCLANG_PATH = "${lib.getLib libclang}/lib";
SAPLING_OSS_BUILD = "true";
SAPLING_VERSION_HASH = versionHash;
SAPLING_VERSION = version;
SAPLING_VERSION_HASH =
let
sha1Hash = builtins.hashString "sha1" version;
hexSubstring = builtins.substring 0 16 sha1Hash;
in
lib.trivial.fromHexString hexSubstring;
# Python setuptools version 66 and newer does not support upstream Sapling's
# version numbers (e.g. "0.2.20230124-180750-hf8cd450a"). Change the version
# number to something supported by setuptools (e.g. "0.2.20230124").
# https://github.com/facebook/sapling/issues/571
SAPLING_VERSION = builtins.elemAt (builtins.split "-" version) 0;
nativeInstallCheckInputs = [
versionCheckHook
];
versionCheckProgramArg = "version";
doInstallCheck = true;
# just a simple check phase, until we have a running test suite. this should
# help catch issues like lack of a LOCALE_ARCHIVE setting (see GH PR #202760)
doCheck = true;
installCheckPhase = ''
echo -n "testing sapling version; should be \"$SAPLING_VERSION\"... "
$out/bin/sl version | grep -qw "$SAPLING_VERSION"
echo "OK!"
'';
# Expose isl to nix repl as sapling.isl.
passthru.isl = isl;
passthru = {
# Expose isl to nix repl as sapling.isl.
isl = isl;
updateScript = ./update.sh;
};
meta = {
description = "Scalable, User-Friendly Source Control System";
+98
View File
@@ -0,0 +1,98 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl jq git gnused nix-prefetch-github rustup python3 nix prefetch-yarn-deps coreutils nix-prefetch-git
set -euo pipefail
# Some Facebook package make use of nightly Rust features
rustup toolchain install nightly --force
# Paths
nixpkgs="$(git rev-parse --show-toplevel)"
pkgdir="$nixpkgs/pkgs/by-name/sa/sapling"
pkgfile="$pkgdir/package.nix"
latest_json="$(curl -s https://api.github.com/repos/facebook/sapling/releases/latest)"
latest_tag="$(jq -r .tag_name <<<"$latest_json")"
tarball_url="$(jq -r .tarball_url <<<"$latest_json")"
# Update version
sed -i -e 's|^ version = "[^"]*";| version = "'"$latest_tag"'";|' "$pkgfile"
# Prefetch source tarball and get unpacked path
mapfile -t tarball_lines < <(nix-prefetch-url --print-path --unpack "$tarball_url")
source_dir="${tarball_lines[1]}"
# Update Cargo.lock by running cargo fetch in a writable copy of the source
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
cp -R "$source_dir" "$tmpdir/src"
chmod -R u+w "$tmpdir/src"
rustup run nightly cargo fetch --manifest-path "$tmpdir/src/eden/scm/Cargo.toml"
cp "$tmpdir/src/eden/scm/Cargo.lock" "$pkgdir/Cargo.lock"
# Parse Cargo.lock and prefetch git sources
cargo_output_hashes="$(python3 -c '
import json
import subprocess
import sys
import tomllib
cargo_lock_path = sys.argv[1]
allowed_packages = {
"abomonation",
"cloned",
"fb303_core",
"fbthrift",
"serde_bser",
"watchman_client"
}
with open(cargo_lock_path, "rb") as f:
lock = tomllib.load(f)
for pkg in lock.get("package", []):
source = pkg.get("source", "")
if source.startswith("git+"):
name = pkg["name"]
if name not in allowed_packages:
continue
version = pkg["version"]
# source format: git+https://url?rev#hash
parts = source.split("#")
if len(parts) == 2:
rev = parts[1]
url_part = parts[0][4:] # remove git+
if "?" in url_part:
url = url_part.split("?")[0]
else:
url = url_part
out = subprocess.check_output(
["nix-prefetch-git", "--url", url, "--rev", rev, "--quiet"],
text=True
)
data = json.loads(out)
hash_val = data["hash"]
print(f" \"{name}-{version}\" = \"{hash_val}\";")
' "$pkgdir/Cargo.lock")"
# First clear existing hashes
sed -i '/outputHashes = {/,/};/ {
/outputHashes = {/n
/};/!d
}' "$pkgfile"
# Then insert new hashes
echo "$cargo_output_hashes" > "$tmpdir/hashes.txt"
sed -i '/outputHashes = {/r '"$tmpdir/hashes.txt" "$pkgfile"
# Prefetch source hash for fetchFromGitHub
src_hash="$(nix-prefetch-github facebook sapling --rev "$latest_tag" | jq -r '.hash')"
# Update the fetchFromGitHub src block's hash
sed -i -e '/src = fetchFromGitHub {/,/}/{s|hash = "[^"]*";|hash = "'"$src_hash"'";|}' "$pkgfile"
# Compute yarn offline cache hash without building
yarn_lock="$source_dir/addons/yarn.lock"
yarn_hash_raw="$(prefetch-yarn-deps "$yarn_lock")"
yarn_hash_sri="$(nix hash convert --hash-algo sha256 --to sri "$yarn_hash_raw")"
sed -i -e '/yarnOfflineCache = fetchYarnDeps {/,/};/{s|sha256 = "[^"]*";|sha256 = "'"$yarn_hash_sri"'";|}' "$pkgfile"