Repository navigation
Expand file tree
/
Copy pathtypecheck.sh
More file actions
executable file
·117 lines (107 loc) · 5.14 KB
/
Copy pathtypecheck.sh
File metadata and controls
executable file
·117 lines (107 loc) · 5.14 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
# Runs the Checker Framework's Nullness Checker over Beam, using a locally built Checker Framework.
# The Checker Framework's continuous integration jobs run this script.
#
# Usage: ./typecheck.sh GROUP
# where GROUP is one of:
# part1, part2 type-check one group of modules
# all type-check every module
# list print each group's compileJava tasks, without running them
#
# The modules are every Java project that applies the Checker Framework Gradle plugin without
# skipping it. They are discovered at run time, so modules that are added to Beam are type-checked
# without changes to this script.
#
# Environment:
# CHECKERFRAMEWORK a Checker Framework checkout in which `./gradlew assembleForJavac` has run.
# Defaults to ../checker-framework.
#
# Run Gradle on JDK 21: Beam's Gradle version cannot run on JDK 25. Do not pass -Pjava21Home or
# -Pjava25Home, which make BeamModulePlugin skip the Checker Framework.
set -e
set -o pipefail
# Patterns matched against Gradle project paths, in which `*` matches any sequence of characters.
# part1 is the Dataflow runner and the chain of modules it depends on (:sdks:java:core,
# :sdks:java:io:google-cloud-platform), which must be type-checked one after another and so bounds
# the time of any group that contains them. Any module that no pattern in PART1 matches is in
# part2. With 4 Gradle workers, part1 takes about 36 minutes and part2 about 31 minutes. More
# groups would not be faster, because every group type-checks :sdks:java:core and part1's chain
# cannot be split.
PART1=(
':sdks:java:core'
':sdks:java:io:google-cloud-platform'
':runners:google-cloud-dataflow-java*'
)
GROUP="$1"
case "$GROUP" in
part1 | part2 | all | list) ;;
*)
echo "Usage: $0 {part1|part2|all|list}" >&2
exit 2
;;
esac
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
cd "$SCRIPT_DIR"
if [ -z "${CHECKERFRAMEWORK}" ]; then
CHECKERFRAMEWORK="$(cd .. && pwd -P)/checker-framework"
fi
for jar in checker.jar checker-qual.jar; do
if [ ! -f "${CHECKERFRAMEWORK}/checker/dist/${jar}" ]; then
echo "$0: ${CHECKERFRAMEWORK}/checker/dist/${jar} does not exist." >&2
echo "Set CHECKERFRAMEWORK and run \`./gradlew assembleForJavac\` there." >&2
exit 1
fi
done
export CHECKERFRAMEWORK
# Every project must be configured in order to discover which ones run the Checker Framework.
GRADLE_ARGS=(-PcfVersion=local --console=plain --no-configure-on-demand)
# Runs "./gradlew" with the arguments after the first, retrying if the failure looks like a
# transient network problem. The first argument is a space-separated list of the delays, in
# seconds, before successive retries; its last element must be 0, which means "do not retry again".
gradle_retry() {
local log status delay
local -a delays
read -r -a delays <<< "$1"
shift
log="$(mktemp -t beam-gradle-retry.XXXXXX)"
for delay in "${delays[@]}"; do
set +e
./gradlew "$@" 2>&1 | tee "$log"
status="${PIPESTATUS[0]}"
set -e
if [ "$status" -eq 0 ]; then
rm -f "$log"
return 0
fi
# The failure looks like a transient network problem if it is HTTP status code 429 or 403, which
# Maven Central returns when it is throttling a client, or a network error. It also looks
# transient if Gradle searched the Gradle Plugin Portal in vain for an artifact ("Could not
# find" followed by a location under https://plugins.gradle.org/m2/): the portal serves the
# Maven Central artifacts that buildSrc's plugins depend on, such as slf4j-api, and it sometimes
# fails to find them. (A dependency that is genuinely missing from the portal is retried too,
# but only once.) Otherwise, the pattern does not match Gradle's "Could not resolve" or "Could
# not find", so a missing dependency or a Checker Framework crash is not retried.
if [ "$delay" -eq 0 ] \
|| ! grep -q -E '(status|response) code:? (403|429|5[0-9][0-9])|HTTP Status:? (403|429|5[0-9][0-9])|Connect(ion)? timed out|Connection (reset|refused)|Read timed out|Network is unreachable|UnknownHostException|Temporary failure in name resolution|Premature end of Content-Length|Remote host terminated the handshake|^[[:space:]]*- https://plugins\.gradle\.org/m2/' "$log"; then
rm -f "$log"
return "$status"
fi
echo "$0: \"./gradlew $*\" failed for an apparent network reason; retrying in ${delay} seconds." >&2
sleep "$delay"
done
}
# The init script registers a typecheckCheckerFramework task that type-checks the projects in
# $GROUP.
INIT_SCRIPT="$SCRIPT_DIR/typecheck-init.gradle"
GRADLE_ARGS+=(-I "$INIT_SCRIPT" -PtypecheckGroup="$GROUP" -PtypecheckPart1="$(IFS=,; echo "${PART1[*]}")")
if [ "$GROUP" = list ]; then
# Print only the list, without Gradle's progress output.
GRADLE_ARGS+=(-q)
else
# Type-check every module whose dependencies type-check, even after a module fails.
GRADLE_ARGS+=(--continue)
fi
# Retry once: a longer sequence could exceed the CI job's time limit. When type-checking,
# dependencies are resolved as the compileJava tasks run, and a retry re-runs only the tasks that
# did not succeed.
gradle_retry "60 0" "${GRADLE_ARGS[@]}" typecheckCheckerFramework