biglybt: 3.5.0.0 -> 3.6.0.0
[NixPkgs.git] / pkgs / development / tools / swiftpm2nix / swiftpm2nix.sh
blobeda7f475064a9c48f901c72ea618391ebcd157e1
1 #!/usr/bin/env bash
3 # Generates a Nix expression to fetch swiftpm dependencies, and a
4 # configurePhase snippet to prepare a working directory for swift-build.
6 set -eu -o pipefail
7 shopt -s lastpipe
9 stateFile=".build/workspace-state.json"
10 if [[ ! -f "$stateFile" ]]; then
11 echo >&2 "Missing $stateFile. Run 'swift package resolve' first."
12 exit 1
15 stateVersion="$(jq .version $stateFile)"
16 if [[ $stateVersion -lt 5 || $stateVersion -gt 6 ]]; then
17 echo >&2 "Unsupported $stateFile version"
18 exit 1
21 # Iterate dependencies and prefetch.
22 hashes=""
23 jq -r '.object.dependencies[] | "\(.subpath) \(.packageRef.location) \(.state.checkoutState.revision)"' $stateFile \
24 | while read -r name url rev; do
25 echo >&2 "-- Fetching $name"
26 sha256="$(nix-prefetch-git --fetch-submodules $url $rev | jq -r .sha256)"
27 hashes+="
28 \"$name\" = \"$sha256\";"
29 echo >&2
30 done
31 hashes+=$'\n'" "
33 # Generate output.
34 mkdir -p nix
35 # Copy the workspace state, but clear 'artifacts'.
36 jq '.object.artifacts = []' < $stateFile > nix/workspace-state.json
37 # Build an expression for fetching sources, and preparing the working directory.
38 cat > nix/default.nix << EOF
39 # This file was generated by swiftpm2nix.
41 workspaceStateFile = ./workspace-state.json;
42 hashes = {$hashes};
44 EOF
45 echo >&2 "-- Generated ./nix"