File tree Expand file tree Collapse file tree 2 files changed +70
-0
lines changed
Expand file tree Collapse file tree 2 files changed +70
-0
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments