anvil-editor: init at 0.4
[NixPkgs.git] / pkgs / build-support / fetchmtn / builder.sh
blobde929fad55a929b3c2f3bab034f14d4956f6dd00
1 if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
2 source $stdenv/setup
4 set -x
6 if ! [ -f "$cacheDB" ]; then
7 echo "Creating cache DB $cacheDB"
8 mtn --db "$cacheDB" db init
9 fi
11 echo "getting revision $selector";
13 done=;
14 for source in $dbs; do
15 if mtn pull --db "$cacheDB" "$source" "${branch}"; then
16 revision="$(mtn --db "$cacheDB" au toposort $(mtn --db "$cacheDB" au select "$selector") | tail -1)";
17 if [ -n "$revision" ]; then
18 if mtn --db "$cacheDB" au get_revision "$revision"; then
19 echo "found revision $revision"
20 done=1;
21 else
22 echo "revision $revision does not exist";
24 else
25 echo "selector $selector does not match any revision";
27 else
28 echo "pulling branch $branch wasn't successful";
29 fi;
30 if test -n "$done"; then
31 break;
32 fi;
33 done;
35 echo "checking out the revision $revision";
37 if test -n "$done"; then
38 mtn checkout --db "$cacheDB" -r "$revision" "$out" -b "${branch}"
39 else
40 echo "Needed revision still not found. Exiting";
41 exit 1;
42 fi;
44 echo "clearing _MTN in the output"
46 rm -rf "$out/_MTN"