-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathupdate-library.sh
executable file
·346 lines (327 loc) · 9.86 KB
/
update-library.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
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#!/bin/sh
BUILD=build/
ENCODING=UTF-8
STD=3.3
LICENSE=modelica2
SVNOPTS="--non-interactive --username anonymous"
OMC=omc
OMC_PARAMS="+n=1"
GITBRANCH=release
while echo $1 | grep -q "^--"; do
OPT="$1"
shift
case $OPT in
--omc)
OMC="$1"
shift
;;
--build-dir)
BUILD="$1"
shift
;;
--encoding)
ENCODING="$1"
shift
;;
--std)
STD="$1"
shift
;;
--license)
LICENSE="$1"
shift
;;
--breaks)
BREAKS="$1"
shift
;;
--patchlevel)
PATCHLEVEL="$1"
shift
;;
--gitbranch)
GITBRANCH="$1"
shift
;;
--gittag)
GITBRANCH="$1"
shift
;;
--no-package)
# $1 will be a comment
NOPACKAGE="$1"
shift
;;
--no-dependencies)
NO_DEPENDENCY="$1"
shift
;;
--remove-files)
# Files that should be stripped from the package. Usually redundant binaries.
REMOVE_FILES="$1"
shift
;;
--patch-files)
# Used by update-library.py
shift
;;
--generate-patch-mos)
# Used by update-library.py
shift
;;
--automatic-updates)
# Skip this; used in the python script
shift
;;
--intertrac)
# Skip this; used in the python script
shift
;;
*)
echo "Unknown option $OPT"
exit 1
;;
esac
done
if test $# -lt 5 || !(test "$1" = SVN || test "$1" = GIT); then
echo "Usage: $0 [flags] [SVN|GIT] URL REVISION DEST [LIBRARIES]"
echo " --encoding=[UTF-8]"
echo " --std=[3.3]"
exit 1
fi
TYPE="$1"
URL="$2"
REVISION="$3"
DEST="$4"
shift;shift;shift;shift
CMD_REPLAY="$DEST.cmd"
echo "# Building $DEST" >> "$CMD_REPLAY"
if test "$TYPE" = SVN; then
./checkout-svn.sh "$DEST" "$URL" "$REVISION" || exit 1
echo "./checkout-svn.sh '$DEST' '$URL' '$REVISION'" >> "$CMD_REPLAY"
elif test "$TYPE" = GIT; then
./checkout-git.sh "$DEST" "$URL" "$GITBRANCH" "$REVISION" || exit 1
echo "./checkout-git.sh '$DEST' '$URL' '$GITBRANCH' '$REVISION'" >> "$CMD_REPLAY"
else
echo "Unknown repository type: $TYPE" >&2
exit 1
fi
mkdir -p "$BUILD"
if test "$*" = "all"; then
shift
CURWD=`pwd`
cd "$DEST"
for f in *.mo */package.mo; do
if test "$f" != "package.mo"; then
LIBS="$LIBS `echo $f | grep -v "[*]" | sed "s/ /%20/g" | sed "s,/package.mo,," | sed "s,.mo$,,"`"
fi
done
cd "$CURWD"
elif test "$*" = "none"; then
shift
fi
echo $LIBS
for f in $LIBS "$@"; do
if test "$f" = "self"; then
LIB=`./get-name.sh "$OMC" "$DEST/package.mo" "$ENCODING" "$STD"`
VER=""
if test -z "$LIB"; then
echo "*** Error: Failed to read package name from $DEST/package.mo"
exit 1
fi
else
LIB=`echo $f | sed "s/%20/ /g" | cut -d" " -f1`
VER=`echo $f | sed "s/%20/ /g" | grep " " | cut -d" " -f2-`
echo Copy library [$LIB] version [$VER] from `pwd`
fi
if test "$f" = "self"; then
SOURCE="$DEST"
MOFILE="$DEST/package.mo"
EXT=""
elif [ ! -z "$VER" ] && [ -d "$DEST/$LIB $VER" ]; then
SOURCE="$DEST/$LIB $VER"
EXT=""
elif [ ! -z "$VER" ] && [ -f "$DEST/$LIB $VER.mo" ]; then
SOURCE="$DEST/$LIB $VER.mo"
EXT=".mo"
elif test -d "$DEST/$LIB"; then
SOURCE="$DEST/$LIB"
MOFILE="$DEST/$LIB/package.mo"
EXT=""
elif test -f "$DEST/$LIB.mo"; then
SOURCE="$DEST/$LIB.mo"
MOFILE="$SOURCE"
EXT=".mo"
else
echo "Did not find library $DEST/$LIB :("
exit 1
fi
if test -z "$VER"; then
VER=`./get-version.sh "$OMC" "$BUILD" "$MOFILE" "$LIB" "$ENCODING" "$STD"`
echo "Got version $VER for $LIB"
if test -z "$VER"; then
NAME="$LIB"
else
NAME="$LIB $VER"
fi
elif test "$VER" = "none"; then
NAME="$LIB"
else
NAME="$LIB $VER"
fi
if test -z "$EXT"; then
echo "test ! -d '$BUILD/$NAME'" >> "$CMD_REPLAY"
if test -d "$BUILD/$NAME"; then
echo "$BUILD/$NAME already exists; bailing out (multiple repositories could try creating the same library)"
exit 1
fi
else
echo "test ! -f '$BUILD/$NAME$EXT'" >> "$CMD_REPLAY"
if test -f "$BUILD/$NAME$EXT"; then
echo "$BUILD/$NAME$EXT already exists; bailing out (multiple repositories could try creating the same library)"
exit 1
fi
fi
rm -rf "$BUILD/$NAME" "$BUILD/$NAME.mo"
# Link recursive... Fast, efficient
echo Copy: cp -a "$SOURCE" "$BUILD/$NAME$EXT"
cp -a "$SOURCE" "$BUILD/$NAME$EXT"
echo "cp -a '$SOURCE' \"\$(BUILD_DIR)/$NAME$EXT\"" >> "$CMD_REPLAY"
for FILES in $REMOVE_FILES; do
echo Removing files: [$BUILD/$NAME$EXT/$FILES]
# Need to check if the file exists, because OSX fails on /path/to/file/Dir
if test -e "$BUILD/$NAME$EXT/$FILES"; then
rm -rf "$BUILD/$NAME$EXT/$FILES"
echo "rm -rf \"\$(BUILD_DIR)/$NAME$EXT/$FILES\"" >> "$CMD_REPLAY"
fi
done
if test -f "$NAME.patch"; then
echo "patch -l -d \"\$(BUILD_DIR)/\" -f -p1 < '$NAME.patch'" >> "$CMD_REPLAY"
if ! patch -l -d "$BUILD/" -f -p1 < "$NAME.patch"; then
echo "Failed to apply $NAME.patch"
exit 1
fi
echo "Applied $NAME.patch"
PATCHREV=`git rev-list HEAD --count "$NAME.patch" 2>/dev/null`
if test -z "$PATCHREV"; then
echo "Not a git repository. We need it to give patch revisions."
exit 1
fi
PATCHREV=`echo -om$PATCHREV`
else
PATCHREV=""
fi
if echo "$NO_DEPENDENCY" | grep -q "^$LIB\$"; then
# Avoid cyclic dependencies
echo > "$BUILD/$NAME.uses"
echo "echo > \"\$(BUILD_DIR)/$NAME.uses\"" >> "$CMD_REPLAY"
else
# Do this a second time after patching for updated uses-annotations... Yes, a bit weird
if test -d "$BUILD/$NAME$EXT"; then
VVER=`./get-version.sh "$OMC" "$BUILD" "$BUILD/$NAME$EXT/package.mo" "$LIB" "$ENCODING" "$STD"`
else
VVER=`./get-version.sh "$OMC" "$BUILD" "$BUILD/$NAME$EXT" "$LIB" "$ENCODING" "$STD"`
fi
# adrpo: sometimes the version in package.mo is WRONG! check that here
if test -z "$VVER"; then
NNAME="$LIB"
else
NNAME="$LIB $VVER"
fi
# adrpo: see if the $NAME != $NNAME
if test "$NAME" != "$NNAME"; then
mv "$BUILD/$NNAME.uses" "$BUILD/$NAME.uses"
fi
test -f "$BUILD/$NAME.uses" || touch "$BUILD/$NAME.uses"
bash bad-uses.sh "$BUILD/$NAME.uses"
HAS_USES_LINE=0
while read line
do
echo "echo '$line' >> \"\$(BUILD_DIR)/$NAME.uses\"" >> "$CMD_REPLAY"
HAS_USES_LINE=1
done < "$BUILD/$NAME.uses"
if test "$HAS_USES_LINE" = 0; then
echo "echo '' > \"\$(BUILD_DIR)/$NAME.uses\"" >> "$CMD_REPLAY"
fi
fi
# Add custom patch levels
if echo "$PATCHLEVEL" | grep -q ":"; then
PATCHLEVELTHIS=`echo "$PATCHLEVEL" | grep -o "$LIB:[A-Za-z0-9_-]*" | cut -d: -f2`
else
PATCHLEVELTHIS="$PATCHLEVEL"
fi
if test ! -z "$PATCHLEVELTHIS"; then
PATCHREV="$PATCHLEVELTHIS"
fi
echo $LICENSE > "$BUILD/$NAME.license"
echo "echo '$LICENSE' > \"\$(BUILD_DIR)/$NAME.license\"" >> "$CMD_REPLAY"
if test "$TYPE" = SVN; then
CHANGED=`svn info $SVNOPTS --xml "$SOURCE" | xpath -q -e '/info/entry/commit/@revision' | grep -o "[0-9]*"`
echo $CHANGED$PATCHREV > "$BUILD/$NAME.last_change"
echo "echo '$CHANGED$PATCHREV' > \"\$(BUILD_DIR)/$NAME.last_change\"" >> "$CMD_REPLAY"
# Skipping changelog. Was only used for debian packages, but it is not that useful and quite slow
# svn log --xml --verbose "$SOURCE" | sed "s,<date>.*</date>,<date>1970-01-01</date>," | sed "s,<author>\(.*\)</author>,<author>none</author><author-svn>\1</author-svn>," | xsltproc svn2cl.xsl - > "$BUILD/$NAME.changes"
else
# CHANGED=`cd "$DEST" && git show -s --format="%ad" --date="iso" "$REVISION" | tr -d -- - | cut "-d " -f1-2 | tr -d : | tr " " -`
if test ! -z "$VER"; then
CHANGED=`cd "$DEST" && git describe --abbrev=7 --match "v$VER*" 2>/dev/null || git describe --abbrev=7 --tags --match "v$VER*" 2>/dev/null`
fi
if test -z "$CHANGED"; then
CHANGED=`cd "$DEST" && git show -s --format="%ad" --date="iso" "$REVISION" | tr -d -- - | cut "-d " -f1-2`
if test -z "$VER" || echo $VER | sed s,^v,, | grep -q [^0-9.]; then
CHANGED="$CHANGED~git~$GITBRANCH"
else
CHANGED="$VER-$CHANGED~git~$GITBRANCH"
fi
fi
CHANGED=`echo $CHANGED | tr -d : | tr " /_" "---" | sed s,^v,,`
CHANGED="$CHANGED$PATCHREV"
echo "$CHANGED" > "$BUILD/$NAME.last_change"
echo "echo '$CHANGED' > \"\$(BUILD_DIR)/$NAME.last_change\"" >> "$CMD_REPLAY"
cat "$BUILD/$NAME.last_change"
# Fix svn $Id::
if test -d "$BUILD/$NAME$EXT"; then
TOPLEVEL_FILE="$BUILD/$NAME$EXT/package.mo"
TOPLEVEL_FILE_MAKEFILE="\$(BUILD_DIR)/$NAME$EXT/package.mo"
else
TOPLEVEL_FILE="$BUILD/$NAME$EXT"
TOPLEVEL_FILE_MAKEFILE="\$(BUILD_DIR)/$NAME$EXT"
fi
# Skip fixing it. It makes the test suite harder to maintain, for very little gain
if false && grep -q 'revisionId *= *"$Id:: *$"' "$TOPLEVEL_FILE"; then
# sed -i on OSX requires the suffix
REPLACE_CMD="s/revisionId *= *\"$Id:: *\$\"/revisionId = \"$CHANGED\"/"
sed -i= "$REPLACE_CMD" "$TOPLEVEL_FILE" || exit 1
echo "sed -i= '$REPLACE_CMD' \"$TOPLEVEL_FILE_MAKEFILE\"" >> "$CMD_REPLAY"
fi
fi
if ! test -z "$BREAKS"; then
echo "$BREAKS" > "$BUILD/$NAME.breaks"
echo "echo '$BREAKS' > \"\$(BUILD_DIR)/$NAME.breaks\"" >> "$CMD_REPLAY"
fi
if ! test -z "$NOPACKAGE"; then
echo "$NOPACKAGE" > "$BUILD/$NAME.nopackage"
echo "echo '$NOPACKAGE' > \"\$(BUILD_DIR)/$NAME.nopackage\"" >> "$CMD_REPLAY"
fi
if test -e "$BUILD/$NAME$EXT/.svn"; then
rm -rf "$BUILD/$NAME$EXT/.svn"
echo "rm -rf \"\$(BUILD_DIR)/$NAME$EXT/.svn\"" >> "$CMD_REPLAY"
elif test -e "$BUILD/$NAME$EXT/.git"; then
rm -rf "$BUILD/$NAME$EXT/.git"*
echo "rm -rf \"\$(BUILD_DIR)/$NAME$EXT/.git\"*" >> "$CMD_REPLAY"
fi
if ! test "$STD" = "3.3"; then
echo "$STD" > "$BUILD/$NAME.std"
fi
if ! test "$ENCODING" = "UTF-8"; then
echo "$ENCODING" > "$BUILD/$NAME/package.encoding"
echo "echo '$ENCODING' > \"\$(BUILD_DIR)/$NAME/package.encoding\"" >> "$CMD_REPLAY"
fi
echo $URL > "$BUILD/$NAME.url"
if test -d "$BUILD/$NAME$EXT"; then
LIBTOTEST="$BUILD/$NAME$EXT/package.mo"
else
LIBTOTEST="$BUILD/$NAME$EXT"
fi
./test-valid.sh "$OMC" "$BUILD" "$LIBTOTEST" || exit 1
done