Skip to content

Commit 68d19d2

Browse files
phvegaguillerodriguez
authored andcommitted
feat: Bootclasspath patch generator tool
Signed-off-by: Pedro Hernández <pedrohdezmlg@gmail.com>
1 parent cd75fc1 commit 68d19d2

2 files changed

Lines changed: 213 additions & 0 deletions

File tree

scripts/build-patch.sh

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
help() {
6+
cat <<EOF
7+
Usage: $0 [OPTION]... [SOURCES-FILE]
8+
9+
Build a glibj patch ZIP archive from a list of changed Java source files.
10+
Reads source paths from SOURCES-FILE, or from standard input if omitted.
11+
12+
Options:
13+
-o, --output FILE
14+
write patch archive to FILE (default: lib/glibj-patch.zip)
15+
-h, --help display this help and exit
16+
EOF
17+
exit 0
18+
}
19+
20+
OUTPUT_PATH=""
21+
22+
while [ "$#" -gt 0 ]; do
23+
case "$1" in
24+
-o|--output) OUTPUT_PATH="$2"; shift 2 ;;
25+
-h|--help) help ;;
26+
-*) echo "$0: unknown option: $1" >&2; exit 1 ;;
27+
*) break ;;
28+
esac
29+
done
30+
31+
if [ "$#" -gt 1 ]; then
32+
echo "$0: too many arguments" >&2
33+
exit 1
34+
fi
35+
SOURCES_FILE="${1:-}"
36+
37+
REPO_ROOT="$(git rev-parse --show-toplevel)"
38+
39+
if [ -z "$OUTPUT_PATH" ]; then
40+
OUTPUT_PATH="${REPO_ROOT}/lib/glibj-patch.zip"
41+
elif [ "${OUTPUT_PATH#/}" = "$OUTPUT_PATH" ]; then
42+
OUTPUT_PATH="$PWD/$OUTPUT_PATH"
43+
fi
44+
45+
if [ -n "$SOURCES_FILE" ]; then
46+
CHANGED_SOURCES=$(cat "$SOURCES_FILE")
47+
else
48+
if [ -t 0 ]; then
49+
# true if stdin is a terminal (i.e. no pipe or redirect)
50+
echo "$0: expected list of .java paths on stdin or as a file argument" >&2
51+
exit 1
52+
fi
53+
54+
CHANGED_SOURCES=$(cat)
55+
fi
56+
57+
if [ -z "$CHANGED_SOURCES" ]; then
58+
echo "No modified Java sources to build."
59+
exit 0
60+
fi
61+
62+
source_base() {
63+
src=$1
64+
65+
awk -v root="$REPO_ROOT" -v src="$src" '
66+
{
67+
full = $2 "/" $3
68+
prefix = root "/"
69+
70+
if (index(full, prefix) == 1) {
71+
full = substr(full, length(prefix) + 1)
72+
}
73+
74+
if (full == src) {
75+
sub(/\.java$/, "", $3)
76+
print $3
77+
exit
78+
}
79+
}
80+
' "$REPO_ROOT/lib/classes.1"
81+
}
82+
83+
PATCH_LIST="$(mktemp "${TMPDIR:-/tmp}/build-patch-archive.XXXXXX")"
84+
85+
cleanup() {
86+
rm -f "$PATCH_LIST"
87+
}
88+
trap cleanup EXIT
89+
trap 'exit 1' HUP INT QUIT TERM
90+
91+
printf '%s\n' "$CHANGED_SOURCES" |
92+
while IFS= read -r src; do
93+
base=$(source_base "$src")
94+
95+
[ -n "$base" ] || continue
96+
97+
if [ -f "${REPO_ROOT}/lib/${base}.class" ]; then
98+
printf '%s\n' "${base}.class"
99+
fi
100+
101+
for inner in "${REPO_ROOT}/lib/${base}"\$*.class; do
102+
[ -f "$inner" ] || continue
103+
printf '%s\n' "${inner#${REPO_ROOT}/lib/}"
104+
done
105+
done > "$PATCH_LIST"
106+
107+
if [ ! -s "$PATCH_LIST" ]; then
108+
echo "$0: no compiled class files found for modified Java sources" >&2
109+
exit 1
110+
fi
111+
112+
rm -f "$OUTPUT_PATH"
113+
114+
(
115+
cd "${REPO_ROOT}/lib"
116+
jar cf "$OUTPUT_PATH" @"$PATCH_LIST"
117+
)
118+
119+
echo "Patch archive created: $OUTPUT_PATH"

scripts/list-changed-classes.sh

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
help() {
6+
cat <<EOF
7+
Usage: $0 [OPTION]... <old-ref>
8+
9+
List glibj Java source files changed between <old-ref> and HEAD.
10+
11+
Options:
12+
-e, --exclude FILE
13+
exclude sources listed in FILE
14+
-h, --help display this help and exit
15+
EOF
16+
exit 0
17+
}
18+
19+
EXCLUDE_PATH=""
20+
21+
while [ "$#" -gt 0 ]; do
22+
case "$1" in
23+
-e|--exclude) EXCLUDE_PATH="$2"; shift 2 ;;
24+
-h|--help) help ;;
25+
-*) echo "$0: unknown option: $1" >&2; exit 1 ;;
26+
*) break ;;
27+
esac
28+
done
29+
30+
if [ "$#" -ne 1 ]; then
31+
echo "$0: expected exactly one argument" >&2
32+
exit 1
33+
fi
34+
OLD_REF=$1
35+
NEW_REF=HEAD
36+
37+
if [ -n "$EXCLUDE_PATH" ] && [ ! -e "$EXCLUDE_PATH" ]; then
38+
echo "error: exclude file not found: $EXCLUDE_PATH" >&2
39+
exit 1
40+
fi
41+
42+
is_excluded() {
43+
src=$1
44+
45+
while IFS= read -r exclude; do
46+
exclude=$(printf '%s\n' "$exclude" | sed 's/^[[:space:]]*//; s/[[:space:]]*$//')
47+
48+
case "$exclude" in
49+
''|\#*) continue ;;
50+
*/) exclude=${exclude%/} ;;
51+
esac
52+
53+
case "$exclude" in
54+
*.java)
55+
[ "$src" = "$exclude" ] && return 0
56+
;;
57+
*)
58+
case "$src" in
59+
"$exclude"/*) return 0 ;;
60+
esac
61+
;;
62+
esac
63+
done < "$EXCLUDE_PATH"
64+
65+
return 1
66+
}
67+
68+
is_glibj_source() {
69+
# Source dirs mirror what gen-classlist.sh scans
70+
case "$1" in
71+
java/*|javax/*|gnu/*|org/*|sun/*|external/*|vm/reference/*) return 0 ;;
72+
*) return 1 ;;
73+
esac
74+
}
75+
76+
CHANGED_SOURCES=$(
77+
git diff --name-only --diff-filter=ACMR "$OLD_REF" "$NEW_REF" -- '*.java' |
78+
while IFS= read -r src; do
79+
is_glibj_source "$src" || continue
80+
81+
if [ -n "$EXCLUDE_PATH" ] && is_excluded "$src"; then
82+
continue
83+
fi
84+
85+
printf '%s\n' "$src"
86+
done
87+
)
88+
89+
if [ -z "$CHANGED_SOURCES" ]; then
90+
echo "No modified glibj Java sources found between ${OLD_REF} and ${NEW_REF}."
91+
exit 0
92+
fi
93+
94+
printf '%s\n' "$CHANGED_SOURCES"

0 commit comments

Comments
 (0)