-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·96 lines (81 loc) · 2.04 KB
/
build.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
#!/bin/zsh
if [[ "$1" == "--no-color" ]]; then
shift
nocolor="nocolor"
fi
if [[ "$nocolor" != "nocolor" ]] && [ -t 2 ]; then
BOLD="\e[1m"
ERROR="\e[1;31m"
WARNING="\e[1;38;5;208m"
SUCCESS="\e[1;32m"
INFO="\e[1;34m"
RESET="\e[0m"
else
BOLD=""
ERROR=""
WARNING=""
SUCCESS=""
INFO=""
RESET=""
fi
log() {
eval "STYLE=\"\${$1}\""
print -u 2 "${STYLE}$1: $2${RESET}"
}
prepare_figures() {
for name in meta reports reports-best-fit platforms countries continents flow share comparable-reports; do
rsvg-convert -f pdf -o "figure-${name}.pdf" "../figure/${name}.svg"
done
}
check_bibtex() {
# Surface actionable information from BibTeX's output
local warnings=$(
grep -e '^Warning--' "$1.blg" |
grep -ve 'no number and no volume' |
grep -ve 'page numbers missing' |
grep -ve 'can'"'"'t use both author and editor fields')
if [[ -n $warnings ]]; then
log ERROR "Please fix the following BibTeX warnings:\n$warnings"
exit 1
fi
}
check_latex() {
# Surface actionable information from LaTeX's output
local warnings=$(
grep -e '^LaTeX Warning: Reference `' "$1.log")
if [[ -n $warnings ]]; then
log ERROR "Please fix the following LaTeX warnings:\n$warnings"
exit 1
fi
}
local LATEX_ENGINE=pdflatex
do_build() {
log INFO "$LATEX_ENGINE $1"
$LATEX_ENGINE -interaction=batchmode "$1"
log INFO "bibtex $1"
bibtex -terse "$1"
check_bibtex "$1"
log INFO "$LATEX_ENGINE $1"
$LATEX_ENGINE -interaction=batchmode "$1"
while ( grep -q '^LaTeX Warning: Label(s) may have changed' "$1.log" ); do
log INFO "$LATEX_ENGINE $1"
$LATEX_ENGINE -interaction=batchmode "$1"
done
check_latex "$1"
}
target=${1:-report}
if [ $# -ne 0 ]; then
shift
fi
case $target in
figure )
prepare_figures
;;
report )
do_build report
;;
* )
log ERROR "\"$target\" is not a valid build target!"
exit 1
;;
esac