forked from xonixx/makesure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakesurefile
331 lines (262 loc) · 7.12 KB
/
Makesurefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
@define NEXT_VERSION="0.9.13"
@define TUSH_REPO=https://github.com/adolfopa/tush
@define GOAWK_VERSION=1.9.1
@define GOAWK=goawk$GOAWK_VERSION
@options timing
@goal soft_folder_created @private
@reached_if [[ -d "soft" ]]
mkdir soft
@goal tush_installed @private
@depends_on soft_folder_created
@reached_if [[ -f "soft/tush/bin/tush-check" ]]
echo
echo "Fetching tush..."
echo
cd "soft"
if command -v wget >/dev/null
then
wget $TUSH_REPO/archive/master.tar.gz -O./tush.tar.gz
tar xzvf ./tush.tar.gz
rm ./tush.tar.gz
mv tush-master tush
else
git clone --depth 1 $TUSH_REPO.git
rm -r tush/.git
fi
@goal soft_installed @private
@depends_on tush_installed
@goal cleaned @private
@goal cleaned_soft @private
@reached_if [[ ! -d "soft" ]]
rm -r "soft"
@goal cleaned_all @private
@depends_on cleaned cleaned_soft
@goal debug @private
@doc shows software versions
AWK="${AWK:-awk}"
case "$AWK" in
*mawk*) "$AWK" -W version 2>&1 | head -n 1
;;
*) "$AWK" --version | head -n 1
;;
esac
bash --version| head -n 1
@goal prepared4tests @private
@depends_on tush_installed debug
@lib testing_tush
function run_tush_file() {
local f="$1"
before_count=$(calc_temp_files)
export PATH="$PATH:$MYDIR/soft/tush/bin"
export NEXT_VERSION
if DIFF="diff --strip-trailing-cr" tush-check "$f"
then
echo "TESTS PASSED : $f"
else
echo >&2 "!!! TESTS FAILED !!! : $f"
exit 1
fi
after_count=$(calc_temp_files)
if (( before_count != after_count ))
then
echo >&2 "!!! temp file not deleted !!!"
exit 1
fi
}
function calc_temp_files {
local tmp_count=$(find /tmp -maxdepth 1 -type f -name 'makesure.*' | wc -l)
local cnt
(( cnt = tmp_count ))
if [[ -d "/dev/shm" ]]
then
local shm_count=$(find /dev/shm -maxdepth 1 -type f -name 'makesure.*' | wc -l)
(( cnt += shm_count ))
fi
echo $cnt
}
@goal tested
@doc runs all *.tush tests
@depends_on tests/*.tush
@goal @glob tests/*.tush @private
@depends_on prepared4tests
@use_lib testing_tush
MAKESURE=makesure_dev \
run_tush_file "$ITEM"
@goal tested_candidate @glob tests/*.tush @private
@depends_on prepared4tests
@depends_on candidate_version_prepared
@use_lib testing_tush
MAKESURE=makesure_candidate \
run_tush_file "$ITEM"
@goal candidate
@doc compiles makesure_candidate
@depends_on tested_candidate
@goal release
@doc creates release version of 'makesure' + updates README.md
@depends_on candidate
@depends_on release_makesure
@depends_on README.md
@goal release_makesure @private
cp makesure_candidate makesure
@goal README.md @private
@doc compiles release version of README.md
awk '
/^\$ \.\/makesure -h$/ { print; stop=1; system("./makesure -h") }
/^```$/ { stop=0 }
!stop' README.md > README.md.1
mv README.md.1 README.md
@goal candidate_version_prepared @private
@depends_on tested
F=makesure_candidate
{
echo '#!/bin/sh'
# We use `makesure_awk`, not `AWK` because otherwise it clashes with `AWK` set for tests.
# The same we can't just use `A` because it can clash with external config variable that user might want to use.
# Since in Posix sh there is no way to declare local var, let's just make names more specific.
echo "if command -v gawk >/dev/null;then makesure_awk='gawk -ltime -v Gawk=1';makesure_pre='';else makesure_awk=awk;makesure_pre='function gettimeofday(){}';fi"
echo 'exec $makesure_awk -v "Version='$NEXT_VERSION'" -v "Prog=$0" "$makesure_pre"'\'
awk -v Q=\' '
function trim(s) { sub(/^[ \t\r\n]+/, "", s); sub(/[ \t\r\n]+$/, "", s); return s }
/^BEGIN/ { in_begin=1 }
in_begin && /^}/ { in_begin=0 }
in_begin && $1 ~ /^split/ { next }
/^function gettimeofday/ { next }
{ if (!/"#"/) gsub("\\s*#.+$", ""); gsub(Q, Q "\\" Q Q); if (trim($0)) print}' makesure.awk
echo \'' Makesurefile "$@"'
} > "$F"
chmod +x "$F"
@goal default
@doc calls 'tested' goal
@depends_on tested
@goal tested_awks
@doc tests with all awks
@depends_on tested
@depends_on tested_bwk
@depends_on tested_mawk
@depends_on tested_mawk134
@depends_on tested_gawk51
@depends_on tested_goawk
@goal tested_bwk @private
@depends_on installed_bwk
AWK="$(pwd)/soft/bwk" ./makesure_dev tested
@goal tested_mawk134 @private
@depends_on installed_mawk134
AWK="$(pwd)/soft/mawk134" ./makesure_dev tested
@goal tested_gawk51 @private
@depends_on installed_gawk51
AWK="$(pwd)/soft/gawk51" ./makesure_dev tested
@goal tested_goawk @private
@depends_on installed_goawk
AWK="$(pwd)/soft/$GOAWK" ./makesure_dev tested
@goal tested_mawk @private
if [[ -x /usr/bin/mawk ]]
then
AWK="/usr/bin/mawk" ./makesure_dev tested
else
echo "No default mawk... Skipped testing it."
fi
#@goal tested_busybox
# AWK="busybox awk" ./makesure_dev tested
@goal installed_awks
@doc installs all awks into ./soft
@depends_on installed_bwk
@depends_on installed_gawk51
@depends_on installed_mawk134
@depends_on installed_goawk
@goal installed_bwk @private
@reached_if [[ -f soft/bwk ]]
@depends_on soft_folder_created
echo
echo "Fetching BWK..."
echo
cd "soft"
wget https://github.com/onetrueawk/awk/archive/refs/heads/master.tar.gz -Obwk.tar.gz
tar xzvf bwk.tar.gz
rm bwk.tar.gz
echo
echo "Compile BWK..."
echo
cd "awk-master"
make
mv a.out ../bwk
cd ..
./bwk --version
rm -r awk-master
@goal installed_gawk51 @private
@reached_if [[ -f soft/gawk51 ]]
@depends_on soft_folder_created
echo
echo "Fetching Gawk-5.1.0..."
echo
cd "soft"
G=gawk-5.1.0.tar.gz
wget "http://git.savannah.gnu.org/cgit/gawk.git/snapshot/$G"
tar xzvf "$G"
rm "$G"
echo
echo "Compile Gawk-5.1.0..."
echo
cd "gawk-5.1.0"
./configure
make
# make check
mv gawk ../gawk51
mkdir ../gawk51_libs
mv extension/.libs/*.so ../gawk51_libs # for AWKLIBPATH
cd ..
./gawk51 --version
rm -r "gawk-5.1.0"
@goal installed_mawk134 @private
@reached_if [[ -f soft/mawk134 ]]
@depends_on soft_folder_created
echo
echo "Fetching Mawk 1.3.4..."
echo
cd "soft"
F=mawk.tar.gz
wget "https://invisible-island.net/datafiles/release/$F"
tar xzvf "$F"
rm "$F"
echo
echo "Compile Mawk 1.3.4..."
echo
cd mawk-1.3.4-*
./configure && make
mv mawk ../mawk134
cd ..
./mawk134 -W version
rm -r mawk-1.3.4-*
@goal installed_goawk @private
@reached_if [[ -f soft/$GOAWK ]]
@depends_on soft_folder_created
echo
echo "Fetching GoAWK $GOAWK_VERSION ..."
echo
cd "soft"
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
os="linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
os="darwin"
else
>&2 echo "Unknown OS"
exit 1
fi
F=goawk_v${GOAWK_VERSION}_${os}_amd64.tar.gz
wget "https://github.com/benhoyt/goawk/releases/download/v$GOAWK_VERSION/$F"
tar xzvf "$F" goawk
rm "$F"
mv goawk $GOAWK
"./$GOAWK" --version
@goal installed_just @private
@reached_if [[ -f soft/just ]]
@depends_on soft_folder_created
VER="0.10.1"
echo
echo "Fetching Just $VER ..."
echo
cd "soft"
F=just-$VER-x86_64-unknown-linux-musl.tar.gz
wget "https://github.com/casey/just/releases/download/$VER/$F"
tar xzvf "$F" just
rm "$F"
"./just" --version