diff options
Diffstat (limited to 'tools/package.sh')
| -rw-r--r-- | tools/package.sh | 75 |
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)" |
| 23 | done | 23 | done |
| 24 | 24 | ||
| 25 | echo "=== Generating console manifest ===" | 25 | echo "=== 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. |
| 30 | MF="$TMP/console-manifest.txt" | 30 | for e in $EXECUTABLES; do |
| 31 | CPLINE="" | 31 | CPLINE="" |
| 32 | for 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" |
| 35 | done | 35 | done |
| 36 | for 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" | ||
| 41 | done | 44 | done |
| 42 | printf 'Class-Path: %s\n\n' "$CPLINE" >"$MF" | ||
| 43 | echo " $CPLINE" | ||
| 44 | 45 | ||
| 45 | echo "=== Packaging ===" | 46 | echo "=== Packaging ===" |
| 46 | for m in $MODULES; do | 47 | for 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" |
| 54 | done | 58 | done |
| 55 | 59 | ||
| 56 | cat >"$DIST/run.bat" <<'EOF' | 60 | for e in $EXECUTABLES; do |
| 61 | cat >"$DIST/run-${e#ui-}.bat" <<EOF | ||
| 57 | @echo off | 62 | @echo off |
| 58 | cd /d "%~dp0" | 63 | cd /d "%~dp0" |
| 59 | java -jar "%~dp0ui-console.jar" | 64 | java -jar "%~dp0$e.jar" |
| 60 | if errorlevel 1 pause | 65 | if errorlevel 1 pause |
| 61 | EOF | 66 | EOF |
| 67 | done | ||
| 62 | 68 | ||
| 63 | [ -f README.pdf ] && cp README.pdf "$DIST/" | 69 | [ -f README.pdf ] && cp README.pdf "$DIST/" |
| 64 | 70 | ||
| 65 | echo "=== Manifest as it actually landed in the jar ===" | 71 | echo "=== 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. |
| 68 | rm -rf "$TMP/mf" && mkdir -p "$TMP/mf" | 74 | for 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" |
| 70 | sed '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 | ||
| 72 | grep -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 | } |
| 76 | grep -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 | } |
| 88 | done | ||
| 80 | 89 | ||
| 81 | echo "======================================" | 90 | echo "======================================" |
| 82 | echo "Self-contained output in $DIST" | 91 | echo "Self-contained output in $DIST" |
| 83 | echo " cd $DIST && java -jar ui-console.jar" | 92 | for e in $EXECUTABLES; do |
| 93 | echo " cd $DIST && java -jar $e.jar" | ||
| 94 | done | ||
| 84 | echo "======================================" | 95 | echo "======================================" |