chiark / gitweb /
bowdlerise
[nailing-cargo.git] / fucking-cargo
1 #!/bin/bash
2 set -e
3
4 # CARGO='../nailing-cargo/nailing-cargo cargo' make && make check CARGO='../nailing-cargo/nailing-cargo cargo'
5
6
7 # Why do we need this ?
8 #
9 #  https://stackoverflow.com/questions/33025887/how-to-use-a-local-unpublished-crate
10 #  https://github.com/rust-lang/cargo/issues/1481
11
12
13 lock=${PWD%/*}/.nail.lock
14 if [ "x$NAILING_CARGO" != "x$lock" ]; then
15         NAILING_CARGO=$lock \
16         exec with-lock-ex -w "$lock" "$0" "$@"
17 fi
18
19 exec 203<../Cargo.nail
20 f=Cargo.toml
21
22 sed='
23 /^ *\[dependencies\]/,/^ \[/{
24 '
25
26 exec 204<../Cargo.nail
27 while read <&204 what where; do
28         if [ "x$what" = x- ]; then continue; fi
29         if [ "x$what" = 'x#' ]; then continue; fi
30         qwhere="${where//\//\\/}"
31         sed+='
32                 s/^'$what' *= *\(\".*\"\) *$/'$what' = { version = \1 }/;
33                 s/^'$what' *= *{/'$what' = { path = "..\/'"${qwhere}"'", /;
34                 /^'$what' *=/ s/version *= *\"[^"]*\"//;
35                 /^'$what' *=/ s/, *\([,}]\)/\1/;
36         '
37 done
38 sed+='}
39 '
40
41 exec 204<../Cargo.nail
42 while read <&204 what where; do
43         if [ "x$what" = 'x#' ]; then continue; fi
44         wf=../$where/$f
45         rm -f $wf.nailing~
46         sed <$wf >$wf.nailing~ "$sed"
47 done
48
49 exec 204<../Cargo.nail
50 while read <&204 what where; do
51         if [ "x$what" = 'x#' ]; then continue; fi
52         wf=../$where/$f
53         if ! test -e $wf.unnailed~; then
54                 ln $wf $wf.unnailed~
55         fi
56 done
57
58 trap '
59         set +e
60         while read <&203 what where; do
61                 if [ "x$what" = "x#" ]; then continue; fi
62                 wf=../$where/$f
63                 if test -e $wf.unnailed~; then
64                         rm -f $wf.nailed~
65                         ln $wf $wf.nailed~
66                         mv -f $wf.unnailed~ $wf
67                 fi
68         done
69         echo >&2 'Unnailed'
70 ' EXIT
71
72 exec 204<../Cargo.nail
73 printf >&2 'Nailing'
74 while read <&204 what where; do
75         if [ "x$what" = 'x#' ]; then continue; fi
76         wf=../$where/$f
77         printf >&2 ' %s' "$what"
78         if cmp -s $wf.nailed~ $wf.nailing~; then
79                 mv -f $wf.nailed~ $wf
80                 rm -f $wf.nailing
81         else
82                 mv -f $wf.nailing~ $wf
83                 rm -f $wf.nailed
84         fi
85 done
86 echo >&2
87
88 "$@"