about summary refs log tree commit diff
path: root/pkgs/applications/version-management
diff options
context:
space:
mode:
authorMatthew "strager" Glazar <strager.nds@gmail.com>2023-04-15 18:02:00 -0700
committerAustin Seipp <aseipp@pobox.com>2023-08-21 17:09:39 -0500
commit97ebbdef918efcb1875b086d135b965bf9953609 (patch)
tree9b4059bbed3c6e28b8549be40780b8c7d5c20119 /pkgs/applications/version-management
parentea6dad32233de83d6d45fa2a3e473babc4a5edeb (diff)
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.
Diffstat (limited to 'pkgs/applications/version-management')
-rwxr-xr-xpkgs/applications/version-management/sapling/gen-deps.py41
1 files changed, 34 insertions, 7 deletions
diff --git a/pkgs/applications/version-management/sapling/gen-deps.py b/pkgs/applications/version-management/sapling/gen-deps.py
index e3fe56f73221b..ddab0080f6406 100755
--- a/pkgs/applications/version-management/sapling/gen-deps.py
+++ b/pkgs/applications/version-management/sapling/gen-deps.py
@@ -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 = {