aboutsummaryrefslogtreecommitdiffstats
path: root/tools/package.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tools/package.sh')
-rw-r--r--tools/package.sh75
1 files changed, 43 insertions, 32 deletions
diff --git a/tools/package.sh b/tools/package.sh
index a85ee6c..186dab5 100644
--- a/tools/package.sh
+++ b/tools/package.sh
@@ -22,63 +22,74 @@ for d in $RUNTIME_LIB_DIRS; do
22 echo " lib/$d/ ($n jars)" 22 echo " lib/$d/ ($n jars)"
23done 23done
24 24
25echo "=== Generating console manifest ===" 25echo "=== Generating executable manifests ==="
26# Generated from what is actually staged, never hand-maintained. Four silent 26# Generated from what is actually staged, never hand-maintained. Four silent
27# failure modes: wildcards match nothing; a missing trailing newline makes jar 27# failure modes: wildcards match nothing; a missing trailing newline makes jar
28# drop the line; paths are relative to this jar; and java -jar ignores -cp, so 28# drop the line; paths are relative to this jar; and java -jar ignores -cp, so
29# this line is the entire classpath at runtime. 29# this line is the entire classpath at runtime.
30MF="$TMP/console-manifest.txt" 30for e in $EXECUTABLES; do
31CPLINE="" 31 CPLINE=""
32for m in $MODULES; do 32 for m in $MODULES; do
33 [ "$m" = ui-console ] && continue 33 [ "$m" = "$e" ] && continue
34 CPLINE="$CPLINE${CPLINE:+ }$m.jar" 34 CPLINE="$CPLINE${CPLINE:+ }$m.jar"
35done 35 done
36for d in $RUNTIME_LIB_DIRS; do 36 for d in $RUNTIME_LIB_DIRS; do
37 for j in "$DIST"/lib/"$d"/*.jar; do 37 for j in "$DIST"/lib/"$d"/*.jar; do
38 [ -f "$j" ] || continue 38 [ -f "$j" ] || continue
39 CPLINE="$CPLINE lib/$d/$(basename "$j")" 39 CPLINE="$CPLINE lib/$d/$(basename "$j")"
40 done
40 done 41 done
42 write_manifest_attr "$TMP/$e-manifest.txt" "Class-Path" "$CPLINE"
43 echo " $e: $CPLINE"
41done 44done
42printf 'Class-Path: %s\n\n' "$CPLINE" >"$MF"
43echo " $CPLINE"
44 45
45echo "=== Packaging ===" 46echo "=== Packaging ==="
46for m in $MODULES; do 47for m in $MODULES; do
47 if [ "$m" = ui-console ]; then 48 case " $EXECUTABLES " in
48 "$JAR" --create --file "$DIST/$m.jar" \ 49 *" $m "*)
49 --main-class "$MAIN_CLASS" --manifest "$MF" -C "build/classes/$m" . 50 "$JAR" --create --file "$DIST/$m.jar" --main-class "$(mainclass_of "$m")" \
50 else 51 --manifest "$TMP/$m-manifest.txt" -C "build/classes/$m" .
52 ;;
53 *)
51 "$JAR" --create --file "$DIST/$m.jar" -C "build/classes/$m" . 54 "$JAR" --create --file "$DIST/$m.jar" -C "build/classes/$m" .
52 fi 55 ;;
56 esac
53 echo " $DIST/$m.jar" 57 echo " $DIST/$m.jar"
54done 58done
55 59
56cat >"$DIST/run.bat" <<'EOF' 60for e in $EXECUTABLES; do
61 cat >"$DIST/run-${e#ui-}.bat" <<EOF
57@echo off 62@echo off
58cd /d "%~dp0" 63cd /d "%~dp0"
59java -jar "%~dp0ui-console.jar" 64java -jar "%~dp0$e.jar"
60if errorlevel 1 pause 65if errorlevel 1 pause
61EOF 66EOF
67done
62 68
63[ -f README.pdf ] && cp README.pdf "$DIST/" 69[ -f README.pdf ] && cp README.pdf "$DIST/"
64 70
65echo "=== Manifest as it actually landed in the jar ===" 71echo "=== Manifest as it actually landed in the jar ==="
66# Cheapest check that prevents a Level-0: if Main-Class or Class-Path didn't 72# Cheapest check that prevents a Level-0: if Main-Class or Class-Path didn't
67# survive, it surfaces here instead of on the grader's machine. 73# survive, it surfaces here instead of on the grader's machine.
68rm -rf "$TMP/mf" && mkdir -p "$TMP/mf" 74for e in $EXECUTABLES; do
69(cd "$TMP/mf" && "$JAR" -xf "$OLDPWD/$DIST/ui-console.jar" META-INF/MANIFEST.MF) 75 rm -rf "$TMP/mf" && mkdir -p "$TMP/mf"
70sed 's/^/ /' "$TMP/mf/META-INF/MANIFEST.MF" 76 (cd "$TMP/mf" && "$JAR" -xf "$OLDPWD/$DIST/$e.jar" META-INF/MANIFEST.MF)
77 echo "-- $e.jar --"
78 sed 's/^/ /' "$TMP/mf/META-INF/MANIFEST.MF"
71 79
72grep -q '^Main-Class:' "$TMP/mf/META-INF/MANIFEST.MF" || { 80 grep -q '^Main-Class:' "$TMP/mf/META-INF/MANIFEST.MF" || {
73 echo "*** Main-Class missing ***" 81 echo "*** Main-Class missing in $e.jar ***"
74 exit 1 82 exit 1
75} 83 }
76grep -q 'Class-Path:' "$TMP/mf/META-INF/MANIFEST.MF" || { 84 grep -q 'Class-Path:' "$TMP/mf/META-INF/MANIFEST.MF" || {
77 echo "*** Class-Path missing ***" 85 echo "*** Class-Path missing in $e.jar ***"
78 exit 1 86 exit 1
79} 87 }
88done
80 89
81echo "======================================" 90echo "======================================"
82echo "Self-contained output in $DIST" 91echo "Self-contained output in $DIST"
83echo " cd $DIST && java -jar ui-console.jar" 92for e in $EXECUTABLES; do
93 echo " cd $DIST && java -jar $e.jar"
94done
84echo "======================================" 95echo "======================================"