-
Notifications
You must be signed in to change notification settings - Fork 1
/
mkrelease
executable file
·205 lines (170 loc) · 5.69 KB
/
mkrelease
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
#!/bin/bash
#
# Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
#
# SPDX-License-Identifier: BSD-2-Clause
#
#
# Generate a standalone tarball of the C parser.
#
set -e
case $(uname) in
Darwin* ) TAR=gnutar ; SEDIOPT="-i ''" ;;
* ) TAR=tar ; SEDIOPT=-i ;;
esac
warn ()
{
echo "$1" >&2
}
die ()
{
echo "$1" >&2
echo "Fatal error"
exit 1
}
if [ $# -ne 1 ]
then
echo "Usage:" >&2
die " $0 tag" >&2
fi
# Get the directory that this script is running in.
CPARSER_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
TOPLEVEL_DIR=$( git -C ${CPARSER_DIR} rev-parse --show-toplevel)
RELEASE_ARCHS='ARM ARM_HYP X64'
pushd "${TOPLEVEL_DIR}"
# Ensure that our working directory is clean.
if git status --porcelain | grep -q -v '^??' ; then
if [[ -v ALLOW_DIRTY ]]; then
warn "WARNING: Dirty working tree."
else
warn "ERROR: Dirty working tree. Set the environment vairable ALLOW_DIRTY to ignore."
exit 1
fi
fi
# Create working directories.
tmpdir=$(mktemp -d)
outputdir=$tmpdir/c-parser
echo "Outputs being placed in \"${outputdir}\"."
# Parse command line arguments.
tag=$1
stem=c-parser-$tag
shift
[ -a "$stem" ] && die "Directory $stem already exists."
safemakedir ()
{
if [ ! -d "$1" ]
then
warn "Creating $1"
mkdir -p "$1"
else
warn "WARNING: release will be merged with existing $1 directory"
fi
}
safemakedir "$outputdir/src/lib"
safemakedir "$outputdir/src/c-parser"
safemakedir "$outputdir/doc"
echo "Tarring standard sources"
# Some testfiles have non-ASCII filenames, so we need git ls-files -z. Ugh.
git -C "${TOPLEVEL_DIR}" ls-files -z | tr '\0' '\n' |
grep ^tools/c-parser |
grep -v tools/c-parser/notes |
grep -v tools/c-parser/mkrelease |
tar -v -T - -c -f - -l |
(cd "$outputdir/src" ; tar xf -)
echo "Getting theory dependencies"
CPARSER_DEPS=$(tempfile)
for ARCH in $RELEASE_ARCHS; do
L4V_ARCH=$ARCH misc/scripts/thydeps -I ./isabelle -d . -b . -r CParser
done |
sort -u >"$CPARSER_DEPS"
if grep -q -vE '^(lib/|tools/c-parser/)' "$CPARSER_DEPS"; then
echo >&2 'unexpected dependencies outside lib/ and tools/c-parser/:'
grep >&2 -vE '^(lib/|tools/c-parser/)' "$CPARSER_DEPS"
exit 1
fi
echo "Copying misc files"
grep '^lib/' "$CPARSER_DEPS" |
xargs '-d\n' cp -v --parents -t "$outputdir/src"
# other misc files
cp -v --parents -t "$outputdir/src" \
lib/Word_Lib/ROOT
echo "Creating ROOTS file"
cat >"$outputdir/src/ROOTS" <<EOF
lib/Word_Lib
c-parser
EOF
echo "Rearranging directories"
/bin/mv -v "$outputdir/src/tools/c-parser/README.md" "$outputdir"
/bin/mv -v "$outputdir/src/tools/c-parser" "$outputdir/src/"
rmdir "$outputdir/src/tools"
echo "Removing files"
/bin/rm -v "$outputdir/src/c-parser/testfiles/many_local_vars".{c,thy}
echo "Executing gen_isabelle_root to generate testfiles/\$L4V_ARCH/ROOT."
for L4V_ARCH in $RELEASE_ARCHS; do
python misc/scripts/gen_isabelle_root.py -i "$outputdir/src/c-parser/testfiles" -i "$outputdir/src/c-parser/testfiles/${L4V_ARCH}" -o "$outputdir/src/c-parser/testfiles/$L4V_ARCH/ROOT" -s CParserTest -b CParser ||
die "gen_isabelle_root failed."
done
echo "Executing gen_isabelle_root to generate testfiles/all_tests_\$L4V_ARCH.thy."
for L4V_ARCH in $RELEASE_ARCHS; do
python misc/scripts/gen_isabelle_root.py -T -o "$outputdir/src/c-parser/all_tests_${L4V_ARCH}.thy" -b CParser -i "$outputdir/src/c-parser/testfiles" -i "$outputdir/src/c-parser/testfiles/${L4V_ARCH}" ||
die "gen_isabelle_root failed."
done
echo "Hacking Makefile to remove ROOT generation."
if ! grep -q '^testfiles/\$(L4V_ARCH)/ROOT' "$outputdir/src/c-parser/Makefile"; then
die "failed to process c-parser/Makefile"
fi
sed $SEDIOPT \
-e '/^testfiles\/\$(L4V_ARCH)\/ROOT/,/CParserTest/d' \
-e '/^all_tests_\$(L4V_ARCH)\.thy/,/CParser/d' \
"$outputdir/src/c-parser/Makefile"
echo "Hacking Makefile to change root dir."
if ! grep -q '^L4V_ROOT_DIR = ' "$outputdir/src/c-parser/Makefile"; then
die "failed to process c-parser/Makefile"
fi
sed $SEDIOPT \
-e 's/^L4V_ROOT_DIR = .*$/L4V_ROOT_DIR = ../' \
"$outputdir/src/c-parser/Makefile"
echo "Generating standalone-parser/table.ML"
pushd "$TOPLEVEL_DIR/tools/c-parser" > /dev/null
"$TOPLEVEL_DIR/isabelle/bin/isabelle" env make -f Makefile "$(pwd)/standalone-parser/table.ML" \
|| die "Couldn't generate table.ML for standalone parser"
cp standalone-parser/table.ML "$outputdir/src/c-parser/standalone-parser"
echo "Cleaning up standalone-parser's Makefile"
sed '
1i\
SML_COMPILER ?= mlton
/^include/d
/General\/table.ML/,/pretty-printing/d
/ISABELLE_HOME/d
/CLEAN_TARGETS/s|\$(STP_PFX)/table.ML||
' < standalone-parser/Makefile > "$outputdir/src/c-parser/standalone-parser/Makefile"
popd > /dev/null
echo "Making PDF of ctranslation file."
cd "$outputdir/src/c-parser/doc"
make ctranslation.pdf > /dev/null
/bin/rm ctranslation.{log,aux,blg,bbl,toc}
mv ctranslation.pdf "$outputdir/doc"
popd > /dev/null
lookforlicense=$(find "$outputdir" \! -name '*.lex.sml' \! -name '*.grm.sml' \! -type d -exec grep -q @LICENSE \{\} \; -print)
if [ -n "$lookforlicense" ]
then
die "### @LICENSE detected in file(s) $lookforlicense"
else
echo "No @LICENSEs remain unexpanded - good."
fi
lookformichaeln=$(find "$outputdir" \! -name RELEASES \! -type d -exec grep -q /michaeln \{\} \; -print)
if [ -n "$lookformichaeln" ]
then
die "### /michaeln detected in file(s) $lookformichaeln"
else
echo "No occurrences of \"/michaeln\" - good."
fi
echo -n "Compressing into $stem.tar.gz: "
mv "$tmpdir/c-parser" "$tmpdir/$stem"
pushd "$tmpdir"
"$TAR" --owner=nobody --group=nogroup -cvzf "${stem}.tar.gz" "$stem" |
while read ; do echo -n "." ; done
popd
/bin/mv -f -v "$tmpdir/${stem}.tar.gz" .
echo
echo Done.