1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p coreutils curl git gnutar jq moreutils nix
7 echo "usage: lock-sdk-deps.sh <macOS version> <Packages>" >&2
8 echo " <macOS version> Decimal-separated version number." >&2
9 echo " Must correspond to a tag in https://github.com/apple-oss-distributions/distribution-macOS" >&2
13 pkgdir
=$
(dirname "$(realpath "$0")")
15 lockfile
=$pkgdir/versions.json
16 if [ -e "$lockfile" ]; then
17 echo '{}' > "$lockfile"
21 trap 'rm -rf -- "$workdir"' EXIT
24 tag
="macos-${sdkVersion//.}"
26 declare -A ignoredPackages
=(
30 [update-source-releases.sh
]=1
34 readarray
-t packages
< <(
35 for file in "$pkgdir"/*; do
36 pkg
=$
(basename "$file" ".nix")
37 test ! "${ignoredPackages[$pkg]-}" && echo "$pkg"
41 echo "Locking versions for macOS $sdkVersion using tag '$tag'..."
43 pushd "$workdir" > /dev
/null
45 git clone
--branch "$tag" https
://github.com
/apple-oss-distributions
/distribution-macOS.git
&> /dev
/null
48 for package
in "${packages[@]}"; do
49 # If the tag exists in `release.json`, use that as an optimization to avoid downloading unnecessarily from Github.
50 packageTag
=$
(jq
-r --arg package
"$package" '.projects[] | select(.project == $package) | .tag' release.json
)
51 packageCommit
=$
(git ls-tree
-d HEAD
"$package" |
awk '{print $3}')
53 if [ ! -d "$package" ]; then
57 # However, sometimes it doesn’t exist. In that case, fall back to cloning the repo and check manually
58 # which tag corresponds to the commit from the submodule.
59 if [ -z "$packageTag" ]; then
60 git clone
--no-checkout "https://github.com/apple-oss-distributions/$package.git" ..
/source &> /dev
/null
61 pushd ..
/source > /dev
/null
62 packageTag
=$
(git tag
--points-at "$packageCommit")
67 packageVersion
=${packageTag##"$package"-}
69 curl
-OL "https://github.com/apple-oss-distributions/$package/archive/$packageTag.tar.gz" &> /dev
/null
70 tar axf
"$packageTag.tar.gz"
72 packageHash
=$
(nix
--extra-experimental-features nix-command
hash path
"$package-$packageTag")
74 pkgsjson
="{\"$package\": {\"version\": \"$packageVersion\", \"hash\": \"$packageHash\"}}"
76 echo " - Locking $package to version $packageVersion with hash '$packageHash'"
77 jq
--argjson pkg
"$pkgsjson" -S '. * $pkg' "$lockfile" | sponge
"$lockfile"