1 #!/usr/bin/env nix-shell
2 #!nix-shell -i python3 -p cargo -p "python3.withPackages (ps: with ps; [ requests ])"
9 from hashlib
import sha1
10 from struct
import unpack
11 from subprocess
import run
14 from requests
import get
16 # Fetch the latest stable release metadata from GitHub
17 releaseMetadata
= get("https://api.github.com/repos/facebook/sapling/releases/latest").json()
18 latestTag
= releaseMetadata
["tag_name"]
19 latestTarballURL
= releaseMetadata
["tarball_url"]
21 [_tarballHash
, sourceDirectory
] = run(
22 ["nix-prefetch-url", "--print-path", "--unpack", latestTarballURL
],
25 stdout
=subprocess
.PIPE
,
26 ).stdout
.rstrip().splitlines()
28 def updateCargoLock():
29 with tempfile
.TemporaryDirectory() as tempDir
:
30 tempDir
= pathlib
.Path(tempDir
)
32 # NOTE(strager): We cannot use shutil.tree because it copies the
33 # read-only permissions.
34 for dirpath
, dirnames
, filenames
in os
.walk(sourceDirectory
):
35 relativeDirpath
= os
.path
.relpath(dirpath
, sourceDirectory
)
36 for filename
in filenames
:
37 shutil
.copy(os
.path
.join(dirpath
, filename
), tempDir
/ relativeDirpath
/ filename
)
38 for dirname
in dirnames
:
39 os
.mkdir(tempDir
/ relativeDirpath
/ dirname
)
41 run(["cargo", "fetch"], check
=True, cwd
=tempDir
/ "eden" / "scm")
42 shutil
.copy(tempDir
/ "eden" / "scm" / "Cargo.lock", "Cargo.lock")
46 def nixPrefetchUrl(url
):
48 ["nix-prefetch-url", "--type", "sha256", url
],
55 # Fetch the `setup.py` source and look for instances of assets being downloaded
56 # from files.pythonhosted.org.
57 setupPy
= (pathlib
.Path(sourceDirectory
) / "eden/scm/setup.py").read_text()
58 foundUrls
= re
.findall(r
'(https://files\.pythonhosted\.org/packages/[^\s]+)"', setupPy
)
61 "links": [{"url": url
, "sha256": nixPrefetchUrl(url
)} for url
in foundUrls
],
63 # Find latest's git tag which corresponds to the Sapling version. Also
64 # needed is a hash of the version, so calculate that here. Taken from
65 # Sapling source `$root/eden/scm/setup_with_version.py`.
66 "versionHash": str(unpack(">Q", sha1(latestTag
.encode("ascii")).digest()[:8])[0]),
69 open("deps.json", "w").write(json
.dumps(dataDeps
, indent
=2, sort_keys
=True) + "\n")