Skip to content

Commit a5e989a

Browse files
authored
Merge pull request #5235 from IntersectMBO/nm/srp-scripts
Add scripts for adding and updating srp's in cabal.project
2 parents 4edd7fd + ac2d180 commit a5e989a

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

scripts/add-srp.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# Add a source-repository-package stanza to cabal.project
6+
#
7+
# Usage: add-srp URL REF [SUBDIRS]
8+
#
9+
# URL is the URL of the repo
10+
# REF can be any reference (eg a branch name or tag)
11+
# SUBDIRS is a list of subdirectories for the `subdir` field
12+
13+
URL=$1
14+
REF=$2
15+
SUBDIRS=("${@:3}")
16+
17+
if grep -q -e "^ *location:.*$URL" cabal.project
18+
then
19+
echo "There's already an srp for $URL in cabal.project" >&2
20+
exit 1
21+
fi
22+
23+
PREFETCH=$(nix-prefetch-git --quiet "$URL" "$REF")
24+
25+
cat <<EOF >>cabal.project
26+
27+
source-repository-package
28+
type: git
29+
location: $URL
30+
--sha256: $(jq -r .hash <<<"$PREFETCH")
31+
tag: $(jq -r .rev <<<"$PREFETCH")
32+
EOF
33+
34+
if (( ${#SUBDIRS[@]} > 0 ))
35+
then
36+
echo ' subdir:'
37+
for SUBDIR in "${SUBDIRS[@]}"
38+
do
39+
echo " $SUBDIR"
40+
done
41+
fi >>cabal.project

scripts/update-srp.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# Update a source-repository-package stanza in cabal.project
6+
#
7+
# Usage: update-srp REPO REF
8+
#
9+
# REPO can be any regex that matches the repo URL
10+
# REF can be any reference (eg a branch name or tag)
11+
12+
REPO=$1
13+
REF=$2
14+
15+
URL=$(sed -n -e "\#location:.*$REPO#s#^ *location: *##p" cabal.project)
16+
17+
if [[ -z $URL ]]
18+
then
19+
echo "There's no srp for $REPO in cabal.project" >&2
20+
exit 1
21+
fi
22+
23+
PREFETCH=$(nix-prefetch-git --quiet "$URL" "$REF")
24+
25+
sed -i -e "
26+
\#location:.*$REPO#,/^$/{
27+
s#tag:.*#tag: $(jq -r .rev <<<"$PREFETCH")#
28+
s#--sha256:.*#--sha256: $(jq -r .hash <<<"$PREFETCH")#
29+
}" cabal.project

0 commit comments

Comments
 (0)