-
Notifications
You must be signed in to change notification settings - Fork 6
/
run.in
executable file
·183 lines (150 loc) · 5.89 KB
/
run.in
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
#!/usr/bin/env bash
set -o nounset -o errexit -o pipefail
. "$HOME"/share/wrtools-core/opt_help.bash
. "$HOME"/share/wrtools-core/fail.bash
. "$HOME"/share/wrtools-core/opt_verbose.bash
#HELP:COMMAND_NAME: Run some convenient stuff
#HELP:Usage: COMMAND_NAME $global-options* $command ...
default_commands=( pre d all post )
#HELP:Default commands: pre d all post
#HELP:global-options:
#HELP: --help | -h: Print this help
#HELP: -j ${number of jobs}: run this many jobs in parallel
#HELP: default = number of processing units available
number_of_jobs=$(nproc)
OPTIND=1
while getopts :hj:v-: option
do
case "$option" in
h ) opt_help;;
j )
if ! printf -v number_of_jobs '%d' "$OPTARG"
then fail "Error: parameter to -j must be a number (got \"$OPTARG\")"
fi;;
v ) opt_verbose;;
- )
case "$OPTARG" in
help ) opt_help;;
verbose ) opt_verbose;;
verbose=* ) fail "Long option \"${OPTARG%%=*}\" has unexpected argument";;
help=* ) fail "Long option \"${OPTARG%%=*}\" has an unexpected argument";;
* ) fail "Unknown long option \"${OPTARG%%=*}\"";;
esac
;;
'?' ) fail "unknown option \"$OPTARG\"";;
: ) fail "option \"$OPTARG\" missing argument";;
* ) assert false;;
esac
done
shift $((OPTIND - 1))
if (( $# == 0 ))
then echo "No command given. Defaulting to \"${default_commands[*]}\"" >&2
set -- ${default_commands[@]}
fi
while (( $# > 0 ))
do command=$1
shift
#HELP:Commands:
# put the most important / main targets higher
case $command in
#HELP: help: Print this help
help ) opt_help;;
#HELP: reconfigure: Run './configure' with the current settings
reconfigure )
(( $# == 0 )) || fail "Don't append commands after $command"
exec @srcdir@/configure
;;
#HELP: d: Build dependencies, if needed
d )
make -j $number_of_jobs depend build_dependencies=true
;;
#HELP: oh: "open html": Build the HTML doc ASAP, then open it
oh )
make -j $number_of_jobs publish/niem-ndr.html
open publish/niem-ndr.html
;;
#HELP: open: Open the HTML doc without rebuilding it.
open )
open publish/niem-ndr.html
;;
#HELP: pre: Run pre-processing validity checks; make sure inputs are well-formed
pre )
make -j $number_of_jobs pre-valid
;;
#HELP: all: Build artifacts; no testing
all )
make -j $number_of_jobs all
;;
#HELP: post | valid: Run post-processing validity checks
post | valid )
make -j $number_of_jobs valid
;;
#HELP: cdiff: color diff
#HELP: usage: COMMAND_NAME cdiff $diff-args...
cdiff ) PAGER=less git diff --word-diff=color "$@";;
#HELP: rebuild: scrub & rebuild everything from nothing
rebuild )
make clean
"$0" d pre all valid
;;
#HELP: grep: find something in the doc XML
#HELP: usage: COMMAND_NAME grep $grep-args...
grep )
(( $# > 0 )) || fail "grep needs args; what am I looking for?"
make -j $number_of_jobs tmp/ndr-doc.xml
exec 3>&1
grep -nH "$@" tmp/ndr-doc.xml | tee /dev/fd/3 | emacsclientgrep
;;
#HELP: uss: update subset. Update xsd/ndr-examples/subset from the latest in Downloads
uss )
(
cd "$(dirname "$0")"
latest_subset=$(get-newest ~/Downloads/Subset_??-??-????_????.zip)
[[ -f "$latest_subset" ]] || fail "did not find subset"
rm -rf xsd/ndr-examples/niem
mkdir -p xsd/ndr-examples
unzip -d xsd/ndr-examples "$latest_subset"
rm -rf xsd/ndr-examples/niem/codes/genc
git checkout -- xsd/ndr-examples/niem/utility/structures/4.0/structures.xsd
) ;;
#HELP: xsv: xml schema validate
xsv ) (
cd "$(dirname "$0")"
make tmp/ndr-doc.xml depend=no
check-doc --catalog=xsd/ndr-examples/xml-catalog.xml tmp/ndr-doc.xml 2>&1 | emacsclientgrep
) ;;
#HELP: publish: publish docs to subversion (for version 4.0rc1)
publish )
artifacts_dir=repo
version_real=4.0rc1
version_pretend=4.0
no_version_dir=$HOME/r/iead/niem-gov/reference/niem/specification/naming-and-design-rules
version_dir=$no_version_dir/$version_real
short_name=niem-ndr
mkdir -p "${version_dir}"
(
cd "$artifacts_dir"
vrun git archive -9 \
--prefix=${short_name}-${version_pretend}/ \
-o ${version_dir}/${short_name}-${version_real}.zip \
$short_name-$version_real
vrun git show $short_name-$version_real:niem-ndr-doc.html > ${version_dir}/${short_name}-${version_real}.html
vrun git show $short_name-$version_real:niem-ndr-doc.txt > ${version_dir}/${short_name}-${version_real}.txt
)
;;
#HELP: show: open grep-friendly buffer on copied text (e.g., jump to an error from a message)
show ) pbpaste | emacsclientgrep;;
#HELP: zip: Generate zip file for published products
zip )
(( $# == 1 )) || fail "Need 1 arg: version number"
version=$1
shift
destination=@abs_builddir@/tmp/niem-ndr-${version}.zip
rm -f "$destination"
( cd @builddir@/publish && find . -mindepth 1 -maxdepth 1 -print0 | xargs -0 zip -r -9 "$destination" )
printf 'Zip file is %s\n' "$destination"
;;
* )
fail "Unknown command \"$command\"";;
esac
done