This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremake.sh
110 lines (93 loc) · 2.34 KB
/
remake.sh
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
#! /bin/bash
# retry a make until it succeeds, only using parallelization on the first attempt
pkg='remake'
version='0.2'
# defaults
retry=1
jobs=1
cmd=
# loop through positional parameters
prev_arg=
optarg=
for arg
do
if test -n "$prev_arg"; then
eval "$prev_arg=\$arg"
prev_arg=
continue
fi
case "$arg" in
-*=*) optarg=`echo "$arg" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
*) optarg= ;;
esac
case "$arg" in
-h | --help | --hel | --he | --h)
cat <<EOF
Usage: $pkg [OPTIONS]... [LOGIN]
If an argument to a long option is mandatory, it is also mandatory for
the corresponding short option; the same is true for optional arguments.
Options:
-h,--help print this message and exit
-j,--jobs=N specifies the number of jobs, default 1
-r,--retry=N number of times to retry a failed make, default 1
-v,--version print version number and exit
This script wraps around make and retries make if is fails. Multiple
jobs are only attempted on the first make.
EOF
exit 0;;
--version | --versio | --versi | --vers | --ver | --ve)
echo "$pkg $version"
exit 0;;
-j | --jobs | --job | --jo | --j)
prev_arg=jobs
;;
--jobs=* | --job=* | --jo=* | --j=*)
jobs="$optarg"
;;
-r | --retry | --retr | --ret | --re | --r)
prev_arg=retry
;;
--retry=* | --retr=* | --ret=* | --re=* | --r=*)
retry="$optarg"
;;
*)
# use unrecognized arguments as make arguments
cmd="$cmd $arg"
;;
esac
done
# check number of retries
if [ "$retry" -gt 0 ]; then
:
else
retry=1
echo "$pkg: invalid number of tries, using $retry"
fi
# check number of jobs
if [ "$jobs" -gt 0 ]; then
:
else
jobs=1
echo "$pkg: invalid number of jobs, using $jobs"
fi
# loop through the tries
for (( i = 0 ; i < retry ; ++i )) ; do
echo "[`date`] $pkg: attempt $i"
make=make
if [ $i = 0 ]; then
make="$make -j $jobs"
fi
# run the program
echo "[`date`] $pkg: $make $cmd"
$make $cmd
status=$?
echo "[`date`] $pkg: \$?: $status for $make $cmd"
# exit loop if successfully completed
if [ $status -eq 0 ]; then
break
fi
# wait a bit
sleep 1
done
echo "[`date`] $pkg: exiting with status $status"
exit $status