[system/kjar] /: Rip out debug stuff.

Hadi Chokr <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 6bac4331c3257386879637797323866a05e6303a by Hadi Chokr.
Committed on 03/08/2026 at 10:50.
Pushed by silverhadch into branch 'master'.

Rip out debug stuff.

Signed-off-by: Hadi Chokr <[email protected]>

M  +9    -1    .flatpak-manifest.json
A  +99   -0    strip-jmods.sh

https://invent.kde.org/system/kjar/-/commit/6bac4331c3257386879637797323866a05e6303a

diff --git a/.flatpak-manifest.json b/.flatpak-manifest.json
index 2308b49..0961aa5 100644
--- a/.flatpak-manifest.json
+++ b/.flatpak-manifest.json
@@ -26,7 +26,15 @@
       "name": "openjdk",
       "buildsystem": "simple",
       "build-commands": [
-        "/usr/lib/sdk/openjdk25/installjdk.sh"
+        "/usr/lib/sdk/openjdk25/installjdk.sh",
+        "rm -f /app/jdk/lib/src.zip",
+        "sh strip-jmods.sh"
+      ],
+      "sources": [
+        {
+          "type": "file",
+          "path": "strip-jmods.sh"
+        }
       ]
     },
     {
diff --git a/strip-jmods.sh b/strip-jmods.sh
new file mode 100644
index 0000000..541a2ad
--- /dev/null
+++ b/strip-jmods.sh
@@ -0,0 +1,99 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
+# SPDX-FileCopyrightText: 2026 Hadi Chokr <[email protected]>
+#
+# Discard native debug symbols from /app/jdk/jmods.
+#
+
+set -e
+
+JDK=/app/jdk
+JMOD="$JDK/bin/jmod"
+MODULES="${1:-java.base}"
+
+command -v objcopy >/dev/null || { echo "strip-jmods: objcopy not found"; exit 1; }
+[ -d "$JDK/jmods" ] || { echo "strip-jmods: $JDK/jmods missing"; exit 1; }
+[ -x "$JMOD" ] || { echo "strip-jmods: $JMOD missing"; exit 1; }
+
+WORK=$(mktemp -d)
+trap 'rm -rf "$WORK"' EXIT
+
+before=$(du -sk "$JDK/jmods" | cut -f1)
+touched_non_base=0
+
+for name in $MODULES; do
+    jm="$JDK/jmods/$name.jmod"
+    if [ ! -f "$jm" ]; then
+        echo "strip-jmods: ERROR: $jm not found"
+        exit 1
+    fi
+    [ "$name" = "java.base" ] || touched_non_base=1
+
+    kb=$(du -k "$jm" | cut -f1)
+    d="$WORK/$name"
+
+    # Per-module invariant: version, target platform, main class, requires and
+    # exports must all survive the round-trip.
+    "$JMOD" describe "$jm" > "$WORK/$name.before"
+
+    "$JMOD" extract --dir "$d" "$jm"
+
+    # --strip-debug
+    find "$d" -type f \( -name '*.so' -o -name '*.so.*' \) \
+        -exec objcopy --strip-debug {} \; 2>/dev/null || true
+    [ -d "$d/bin" ] && find "$d/bin" -type f \
+        -exec objcopy --strip-debug {} \; 2>/dev/null || true
+
+    set -- create
+    [ -d "$d/classes" ] && set -- "$@" --class-path    "$d/classes"
+    [ -d "$d/bin" ]     && set -- "$@" --cmds          "$d/bin"
+    [ -d "$d/lib" ]     && set -- "$@" --libs          "$d/lib"
+    [ -d "$d/conf" ]    && set -- "$@" --config        "$d/conf"
+    [ -d "$d/include" ] && set -- "$@" --header-files  "$d/include"
+    [ -d "$d/legal" ]   && set -- "$@" --legal-notices "$d/legal"
+    [ -d "$d/man" ]     && set -- "$@" --man-pages     "$d/man"
+
+    rm -f "$jm"
+    "$JMOD" "$@" "$jm"
+    rm -rf "$d"
+
+    "$JMOD" describe "$jm" > "$WORK/$name.after"
+    if ! diff -q "$WORK/$name.before" "$WORK/$name.after" >/dev/null; then
+        echo "strip-jmods: ERROR: descriptor changed for $name"
+        diff "$WORK/$name.before" "$WORK/$name.after" || true
+        exit 1
+    fi
+
+    printf 'strip-jmods:   %-22s %5s MB -> %5s MB\n' "$name" \
+        "$((kb / 1024))" "$(( $(du -k "$jm" | cut -f1) / 1024 ))"
+done
+
+if [ "$touched_non_base" -eq 1 ]; then
+    echo "strip-jmods: recomputing recorded module hashes"
+    if ! "$JMOD" hash --module-path "$JDK/jmods" --hash-modules '.*'; then
+        echo "strip-jmods: ERROR: jmod hash failed -- see the note at the top"
+        echo "strip-jmods:        of this script; rerun with java.base only."
+        exit 1
+    fi
+fi
+
+after=$(du -sk "$JDK/jmods" | cut -f1)
+echo "strip-jmods: total $((before / 1024)) MB -> $((after / 1024)) MB"
+
+# Smoke test
+echo "strip-jmods: verifying jlink against the rewritten jmods"
+
+if ! "$JDK/bin/jlink" --module-path "$JDK/jmods" \
+        --add-modules java.base,java.desktop,java.xml,jdk.compiler \
+        --output "$WORK/verify"; then
+    echo "strip-jmods: ERROR: jlink failed against the rewritten jmods"
+    exit 1
+fi
+
+if ! "$WORK/verify/bin/java" -version; then
+    echo "strip-jmods: ERROR: linked runtime does not run"
+    exit 1
+fi
+
+rm -rf "$WORK/verify"
+echo "strip-jmods: OK"
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.