sapling: teach gen-deps.py script to update Cargo.lock
Upstream Sapling does not maintain a Cargo.lock file, so Nixpkgs has its own. Teach the gen-deps.py script to update Nixpkgs' Cargo.lock whenever the Cargo.toml files change.
This commit is contained in:
committed by
Austin Seipp
parent
ea6dad3223
commit
97ebbdef91
@@ -1,18 +1,47 @@
|
||||
#!/usr/bin/env nix-shell
|
||||
#!nix-shell -i python3 -p "python3.withPackages (ps: with ps; [ requests ])"
|
||||
#!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
|
||||
latestTag = get("https://api.github.com/repos/facebook/sapling/releases/latest").json()[
|
||||
"tag_name"
|
||||
]
|
||||
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(
|
||||
@@ -25,9 +54,7 @@ def nixPrefetchUrl(url):
|
||||
|
||||
# Fetch the `setup.py` source and look for instances of assets being downloaded
|
||||
# from files.pythonhosted.org.
|
||||
setupPy = get(
|
||||
f"https://github.com/facebook/sapling/raw/{latestTag}/eden/scm/setup.py"
|
||||
).text
|
||||
setupPy = (pathlib.Path(sourceDirectory) / "eden/scm/setup.py").read_text()
|
||||
foundUrls = re.findall(r'(https://files\.pythonhosted\.org/packages/[^\s]+)"', setupPy)
|
||||
|
||||
dataDeps = {
|
||||
|
||||
Reference in New Issue
Block a user