chiark / gitweb /
better parsing, can cope with { } things
[nailing-cargo.git] / fucking-cargo
1 #!/bin/bash
2 set -e
3
4 # CARGO='../fucking-cargo/fucking-cargo cargo' make && make check CARGO='../fucking-cargo/fucking-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%/*}/.fuck.lock
14 if [ "x$FUCKING_CARGO" != "x$lock" ]; then
15         FUCKING_CARGO=$lock \
16         exec with-lock-ex -w "$lock" "$0" "$@"
17 fi
18
19 exec 203<../Fuck
20 f=Cargo.toml
21
22 sed='
23 /^ *\[dependencies\]/,/^ \[/{
24 '
25
26 exec 204<../Fuck
27 while read <&204 what where; do
28         if [ "x$what" = x- ]; then continue; fi
29         qwhere="${where//\//\\/}"
30         sed+='
31                 s/^'$what' *= *\(\".*\"\) *$/'$what' = { version = \1 }/;
32                 s/^'$what' *= *{/'$what' = { path = "..\/'"${qwhere}"'", /;
33                 /^'$what' *=/ s/version *= *\"[^"]*\"//;
34                 /^'$what' *=/ s/, *\([,}]\)/\1/;
35         '
36 done
37 sed+='}
38 '
39
40 exec 204<../Fuck
41 while read <&204 what where; do
42         wf=../$where/$f
43         rm -f $wf.fucking~
44         sed <$wf >$wf.fucking~ "$sed"
45 done
46
47 exec 204<../Fuck
48 while read <&204 what where; do
49         wf=../$where/$f
50         if ! test -e $wf.unfucked~; then
51                 ln $wf $wf.unfucked~
52         fi
53 done
54
55 trap '
56         set +e
57         while read <&203 what where; do
58                 wf=../$where/$f
59                 if test -e $wf.unfucked~; then
60                         rm -f $wf.fucked~
61                         ln $wf $wf.fucked~
62                         mv -f $wf.unfucked~ $wf
63                 fi
64         done
65         echo >&2 'Unfucked'
66 ' EXIT
67
68 exec 204<../Fuck
69 printf >&2 'Fucking'
70 while read <&204 what where; do
71         wf=../$where/$f
72         printf >&2 ' %s' "$what"
73         if cmp -s $wf.fucked~ $wf.fucking~; then
74                 mv -f $wf.fucked~ $wf
75                 rm -f $wf.fucking
76         else
77                 mv -f $wf.fucking~ $wf
78                 rm -f $wf.fucked
79         fi
80 done
81 echo >&2
82
83 "$@"