diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2015-08-03 12:49:29 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2015-08-03 12:49:29 +0200 |
commit | 230688a0b842cf57b316a7ba62910ca387afbce7 (patch) | |
tree | 6367087d25147335972cacf19bd34fb868863fd7 /do | |
parent | 7170488c37105691f4a690cbcf1e43000d779b59 (diff) | |
download | dirty-haskell.org-230688a0b842cf57b316a7ba62910ca387afbce7.tar dirty-haskell.org-230688a0b842cf57b316a7ba62910ca387afbce7.tar.gz dirty-haskell.org-230688a0b842cf57b316a7ba62910ca387afbce7.tar.bz2 dirty-haskell.org-230688a0b842cf57b316a7ba62910ca387afbce7.tar.xz dirty-haskell.org-230688a0b842cf57b316a7ba62910ca387afbce7.zip |
Start of complete rewrite to switch to hakyll
Diffstat (limited to 'do')
-rwxr-xr-x | do | 177 |
1 files changed, 0 insertions, 177 deletions
@@ -1,177 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | # | ||
3 | # A minimal alternative to djb redo that doesn't support incremental builds. | ||
4 | # For the full version, visit http://github.com/apenwarr/redo | ||
5 | # | ||
6 | # The author disclaims copyright to this source file and hereby places it in | ||
7 | # the public domain. (2010 12 14) | ||
8 | # | ||
9 | |||
10 | # By default, no output coloring. | ||
11 | green="" | ||
12 | bold="" | ||
13 | plain="" | ||
14 | |||
15 | if [ -n "$TERM" -a "$TERM" != "dumb" ] && tty <&2 >/dev/null 2>&1; then | ||
16 | green="$(printf '\033[32m')" | ||
17 | bold="$(printf '\033[1m')" | ||
18 | plain="$(printf '\033[m')" | ||
19 | fi | ||
20 | |||
21 | _dirsplit() | ||
22 | { | ||
23 | base=${1##*/} | ||
24 | dir=${1%$base} | ||
25 | } | ||
26 | |||
27 | dirname() | ||
28 | ( | ||
29 | _dirsplit "$1" | ||
30 | dir=${dir%/} | ||
31 | echo "${dir:-.}" | ||
32 | ) | ||
33 | |||
34 | _dirsplit "$0" | ||
35 | export REDO=$(cd "${dir:-.}" && echo "$PWD/$base") | ||
36 | |||
37 | DO_TOP= | ||
38 | if [ -z "$DO_BUILT" ]; then | ||
39 | DO_TOP=1 | ||
40 | [ -n "$*" ] || set all # only toplevel redo has a default target | ||
41 | export DO_BUILT=$PWD/.do_built | ||
42 | : >>"$DO_BUILT" | ||
43 | echo "Removing previously built files..." >&2 | ||
44 | sort -u "$DO_BUILT" | tee "$DO_BUILT.new" | | ||
45 | while read f; do printf "%s\0%s.did\0" "$f" "$f"; done | | ||
46 | xargs -0 rm -f 2>/dev/null | ||
47 | mv "$DO_BUILT.new" "$DO_BUILT" | ||
48 | DO_PATH=$DO_BUILT.dir | ||
49 | export PATH=$DO_PATH:$PATH | ||
50 | rm -rf "$DO_PATH" | ||
51 | mkdir "$DO_PATH" | ||
52 | for d in redo redo-ifchange; do | ||
53 | ln -s "$REDO" "$DO_PATH/$d"; | ||
54 | done | ||
55 | [ -e /bin/true ] && TRUE=/bin/true || TRUE=/usr/bin/true | ||
56 | for d in redo-ifcreate redo-stamp redo-always; do | ||
57 | ln -s $TRUE "$DO_PATH/$d"; | ||
58 | done | ||
59 | fi | ||
60 | |||
61 | |||
62 | _find_dofile_pwd() | ||
63 | { | ||
64 | dofile=default.$1.do | ||
65 | while :; do | ||
66 | dofile=default.${dofile#default.*.} | ||
67 | [ -e "$dofile" -o "$dofile" = default.do ] && break | ||
68 | done | ||
69 | ext=${dofile#default} | ||
70 | ext=${ext%.do} | ||
71 | base=${1%$ext} | ||
72 | } | ||
73 | |||
74 | |||
75 | _find_dofile() | ||
76 | { | ||
77 | local prefix= | ||
78 | while :; do | ||
79 | _find_dofile_pwd "$1" | ||
80 | [ -e "$dofile" ] && break | ||
81 | [ "$PWD" = "/" ] && break | ||
82 | target=${PWD##*/}/$target | ||
83 | tmp=${PWD##*/}/$tmp | ||
84 | prefix=${PWD##*/}/$prefix | ||
85 | cd .. | ||
86 | done | ||
87 | base=$prefix$base | ||
88 | } | ||
89 | |||
90 | |||
91 | _run_dofile() | ||
92 | { | ||
93 | export DO_DEPTH="$DO_DEPTH " | ||
94 | export REDO_TARGET=$PWD/$target | ||
95 | local line1 | ||
96 | set -e | ||
97 | read line1 <"$PWD/$dofile" || true | ||
98 | cmd=${line1#"#!/"} | ||
99 | if [ "$cmd" != "$line1" ]; then | ||
100 | /$cmd "$PWD/$dofile" "$@" >"$tmp.tmp2" | ||
101 | else | ||
102 | :; . "$PWD/$dofile" >"$tmp.tmp2" | ||
103 | fi | ||
104 | } | ||
105 | |||
106 | |||
107 | _do() | ||
108 | { | ||
109 | local dir=$1 target=$2 tmp=$3 | ||
110 | if [ ! -e "$target" ] || [ -d "$target" -a ! -e "$target.did" ]; then | ||
111 | printf '%sdo %s%s%s%s\n' \ | ||
112 | "$green" "$DO_DEPTH" "$bold" "$dir$target" "$plain" >&2 | ||
113 | echo "$PWD/$target" >>"$DO_BUILT" | ||
114 | dofile=$target.do | ||
115 | base=$target | ||
116 | ext= | ||
117 | [ -e "$target.do" ] || _find_dofile "$target" | ||
118 | if [ ! -e "$dofile" ]; then | ||
119 | echo "do: $target: no .do file" >&2 | ||
120 | return 1 | ||
121 | fi | ||
122 | [ ! -e "$DO_BUILT" ] || [ ! -d "$(dirname "$target")" ] || | ||
123 | : >>"$target.did" | ||
124 | ( _run_dofile "$target" "$base" "$tmp.tmp" ) | ||
125 | rv=$? | ||
126 | if [ $rv != 0 ]; then | ||
127 | printf "do: %s%s\n" "$DO_DEPTH" \ | ||
128 | "$dir$target: got exit code $rv" >&2 | ||
129 | rm -f "$tmp.tmp" "$tmp.tmp2" | ||
130 | return $rv | ||
131 | fi | ||
132 | mv "$tmp.tmp" "$target" 2>/dev/null || | ||
133 | ! test -s "$tmp.tmp2" || | ||
134 | mv "$tmp.tmp2" "$target" 2>/dev/null | ||
135 | rm -f "$tmp.tmp2" | ||
136 | else | ||
137 | echo "do $DO_DEPTH$target exists." >&2 | ||
138 | fi | ||
139 | } | ||
140 | |||
141 | |||
142 | # Make corrections for directories that don't actually exist yet. | ||
143 | _dir_shovel() | ||
144 | { | ||
145 | local dir base | ||
146 | xdir=$1 xbase=$2 xbasetmp=$2 | ||
147 | while [ ! -d "$xdir" -a -n "$xdir" ]; do | ||
148 | _dirsplit "${xdir%/}" | ||
149 | xbasetmp=${base}__$xbase | ||
150 | xdir=$dir xbase=$base/$xbase | ||
151 | echo "xbasetmp='$xbasetmp'" >&2 | ||
152 | done | ||
153 | } | ||
154 | |||
155 | |||
156 | _redo() | ||
157 | { | ||
158 | set +e | ||
159 | for i in "$@"; do | ||
160 | _dirsplit "$i" | ||
161 | _dir_shovel "$dir" "$base" | ||
162 | dir=$xdir base=$xbase basetmp=$xbasetmp | ||
163 | ( cd "$dir" && _do "$dir" "$base" "$basetmp" ) | ||
164 | [ "$?" = 0 ] || return 1 | ||
165 | done | ||
166 | } | ||
167 | |||
168 | |||
169 | _redo "$@" | ||
170 | [ "$?" = 0 ] || exit 1 | ||
171 | |||
172 | if [ -n "$DO_TOP" ]; then | ||
173 | echo "Removing stamp files..." >&2 | ||
174 | [ ! -e "$DO_BUILT" ] || | ||
175 | while read f; do printf "%s.did\0" "$f"; done <"$DO_BUILT" | | ||
176 | xargs -0 rm -f 2>/dev/null | ||
177 | fi | ||