Repository navigation
Expand file tree
/
Copy pathcheck-cast-semantics.sh
More file actions
executable file
·87 lines (79 loc) · 3.28 KB
/
Copy pathcheck-cast-semantics.sh
File metadata and controls
executable file
·87 lines (79 loc) · 3.28 KB
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
#!/usr/bin/env bash
#
# Fails when our own code relies on a failing cast throwing ClassCastException.
# ParparVM's CHECKCAST is unchecked, so such a handler never runs on iOS and the
# wrong object is used instead (issue #5531). See CastSemanticsVerifier.
#
# scripts/check-cast-semantics.sh [--write-baseline] [--require-all] [class-dir-or-jar ...]
#
# With no paths, checks every module that is already built. A module that has not
# been compiled is skipped with a note, so a partial local tree still gives a
# useful answer -- but CI passes --require-all, because there a missing module
# means the gate silently stopped covering it.
#
# NOTE: regenerate the baseline only against a FRESH build of every module. A
# stale target/classes produces a baseline that is missing methods, and the gate
# then fails on CI for code that was never new.
set -euo pipefail
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
REPO_ROOT="$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd)"
BASELINE="$SCRIPT_DIR/cast-semantics-baseline.txt"
TRANSLATOR="$REPO_ROOT/vm/ByteCodeTranslator/target/classes"
# The modules whose bytecode ParparVM translates and that we own. A translation
# sees maven/core, maven/ios and vm/JavaAPI, and -- in an application with
# Android sources -- maven/android-compat, whose runtime the build relocates into
# the application's own classes. Nothing else of ours.
# Deliberately NOT covered, for the one reason: the code runs on a VM whose
# CHECKCAST does throw, so its catch(ClassCastException) handlers are live and
# correct and demanding an instanceof there buys nothing.
# - maven/android (Ports/Android) runs on ART. It is not translated -- an iOS
# build never loads a line of it -- and ART implements CHECKCAST to spec.
# - maven/java-runtime (Ports/CLDC11) runs on a real JVM -- the simulator and
# desktop. ParparVM's runtime is vm/JavaAPI.
DEFAULT_ROOTS=(
"vm/JavaAPI/target/classes"
"maven/core/target/classes"
"maven/ios/target/classes"
"maven/android-compat/target/classes"
)
write_baseline=0
require_all=0
roots=()
for arg in "$@"; do
case "$arg" in
--write-baseline) write_baseline=1 ;;
--require-all) require_all=1 ;;
*) roots+=("$arg") ;;
esac
done
if [[ ! -f "$TRANSLATOR/com/codename1/tools/translator/CastSemanticsVerifier.class" ]]; then
echo "check-cast-semantics: building the translator" >&2
(cd "$REPO_ROOT/vm" && mvn -q -B -pl ByteCodeTranslator -am package -DskipTests)
fi
if [[ ${#roots[@]} -eq 0 ]]; then
missing=0
for candidate in "${DEFAULT_ROOTS[@]}"; do
if [[ -d "$REPO_ROOT/$candidate" ]]; then
roots+=("$REPO_ROOT/$candidate")
else
echo "check-cast-semantics: skipping $candidate (not built)" >&2
missing=1
fi
done
if [[ "$require_all" -eq 1 && "$missing" -eq 1 ]]; then
echo "check-cast-semantics: --require-all was passed but a module is not built;" >&2
echo " the gate would have covered less than it claims. Build it and re-run." >&2
exit 2
fi
fi
if [[ ${#roots[@]} -eq 0 ]]; then
echo "check-cast-semantics: nothing to check -- no module is built" >&2
exit 2
fi
args=()
if [[ "$write_baseline" -eq 1 ]]; then
args+=(--write-baseline "$BASELINE")
fi
args+=(--baseline "$BASELINE")
exec java -cp "$TRANSLATOR" \
com.codename1.tools.translator.CastSemanticsVerifier "${args[@]}" "${roots[@]}"