forked from ZacSweers/metro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetrow
More file actions
executable file
·401 lines (346 loc) · 12.8 KB
/
Copy pathmetrow
File metadata and controls
executable file
·401 lines (346 loc) · 12.8 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
#!/usr/bin/env bash
set -euo pipefail
# Subprojects that can be targeted with -p flag
ALL_SUBPROJECTS=("samples" "benchmark" "ide-integration-tests" "idea-plugin")
# Run a gradle command across root and specified subprojects
# Usage: run_gradle_all "command args" [subprojects...]
# If no subprojects specified, runs on root + all subprojects
run_gradle_all() {
local cmd="$1"
shift
local subprojects=("$@")
if [[ ${#subprojects[@]} -eq 0 ]]; then
subprojects=("${ALL_SUBPROJECTS[@]}")
fi
# Run on root project
# shellcheck disable=SC2086 # Word splitting is intentional
./gradlew $cmd
# Run on each subproject
for project in "${subprojects[@]}"; do
# shellcheck disable=SC2086
./gradlew -p "$project" $cmd
done
}
# Function to run checks with optional compiler version
run_checks() {
local compiler_version="$1"
local version_flag=""
if [[ -n "$compiler_version" ]]; then
version_flag="-Pmetro.testCompilerVersion=$compiler_version"
echo "Running checks with Kotlin version $compiler_version..."
else
echo "Running checks..."
fi
./gradlew check -x dokkaGeneratePublicationHtml $version_flag
}
# Function to run tests with optional compiler version
run_tests() {
local compiler_version="$1"
local version_flag=""
if [[ -n "$compiler_version" ]]; then
version_flag="-Pmetro.testCompilerVersion=$compiler_version"
echo "Running tests with Kotlin version $compiler_version..."
else
echo "Running tests..."
fi
./gradlew :compiler:test :compiler-tests:test :gradle-plugin:functionalTest :runtime:allTests :runtime-coroutines:allTests $version_flag --quiet -x logLinkDokkaGeneratePublicationHtml -x dokkaGeneratePublicationHtml
# We have to regen package locks because the kotlin yarn/node/etc build tooling is brittle
./gradlew -p samples kotlinWasmUpgradePackageLock kotlinUpgradePackageLock --rerun-tasks --no-build-cache --no-configuration-cache --quiet
./gradlew -p samples :integration-tests:allTests --quiet
}
case "$1" in
"publish")
version=""
local=false
while [[ $# -gt 1 ]]; do
case "$2" in
--version)
version="$3"
shift 2
;;
--local)
local=true
shift
;;
*)
echo "Unknown publish argument: $2"
exit 1
;;
esac
done
export PUBLISHING=true
if [[ "$local" = true ]]; then
if [[ -z "$version" ]]; then
echo "Version required for local publish"
exit 1
fi
echo "Publishing version $version locally..."
./gradlew publishToMavenLocal -x dokkaGeneratePublicationHtml -PVERSION_NAME="${version}" -PRELEASE_SIGNING_ENABLED=false --rerun-tasks
else
echo "Publishing version $version..."
./gradlew publish -x dokkaGeneratePublicationHtml
fi
;;
"publish-idea-plugin")
version=""
dry_run=false
local=false
while [[ $# -gt 1 ]]; do
case "$2" in
--version)
version="$3"
shift 2
;;
--dry-run)
dry_run=true
shift
;;
--local)
local=true
shift
;;
*)
echo "Unknown publish-idea-plugin argument: $2"
exit 1
;;
esac
done
publish_args=()
if [[ -n "$version" ]]; then
publish_args+=("-PVERSION_NAME=${version}")
echo "Publishing idea-plugin version $version..."
else
echo "Publishing idea-plugin version from idea-plugin/gradle.properties..."
fi
if [[ "$dry_run" = true ]]; then
publish_args+=("--dry-run")
fi
if [[ "$local" = true ]]; then
./gradlew -p idea-plugin buildPlugin --quiet "${publish_args[@]}"
else
./gradlew -p idea-plugin publishPlugin --quiet "${publish_args[@]}"
fi
;;
"check")
all=false
version=""
while [[ $# -gt 1 ]]; do
case "$2" in
--all)
all=true
shift
;;
--version)
version="$3"
shift 2
;;
*)
echo "Unknown check argument: $2"
exit 1
;;
esac
done
if [[ "$all" = true ]]; then
echo "Running checks against all compiler versions..."
# Get all available versions using the CI script
if [[ ! -f "scripts/generate-ci-matrix.sh" ]]; then
echo "Error: scripts/generate-ci-matrix.sh not found"
exit 1
fi
# Get versions using the script's --versions-only mode
versions=$(./scripts/generate-ci-matrix.sh --versions-only | tr '\n' ' ')
echo "Testing against versions: $versions"
for ver in $versions; do
echo "=== Testing with Kotlin $ver ==="
run_checks "$ver" || exit 1
done
else
run_checks "$version"
fi
# Run samples last
./gradlew -p samples check
;;
"test")
all=false
version=""
while [[ $# -gt 1 ]]; do
case "$2" in
--all)
all=true
shift
;;
--version)
version="$3"
shift 2
;;
*)
echo "Unknown test argument: $2"
exit 1
;;
esac
done
if [[ "$all" = true ]]; then
echo "Running tests against all compiler versions..."
if [[ ! -f "scripts/generate-ci-matrix.sh" ]]; then
echo "Error: scripts/generate-ci-matrix.sh not found"
exit 1
fi
versions=$(./scripts/generate-ci-matrix.sh --versions-only | tr '\n' ' ')
echo "Testing against versions: $versions"
for ver in $versions; do
echo "=== Testing with Kotlin $ver ==="
run_tests "$ver" || exit 1
done
else
run_tests "$version"
fi
;;
"clean")
echo "Cleaning..."
run_gradle_all "clean --quiet"
rm -rf out .gradle .kotlin
;;
"format")
kempt format --all
;;
"regen")
version=""
locks_only=false
release_baselines=false
while [[ $# -gt 1 ]]; do
case "$2" in
--version)
version="$3"
shift 2
;;
--locks-only)
locks_only=true
shift
;;
--release-baselines)
release_baselines=true
shift
;;
*)
echo "Unknown regen argument: $2"
exit 1
;;
esac
done
if [[ "$locks_only" = true && "$release_baselines" = true ]]; then
echo "Cannot combine --locks-only with --release-baselines"
exit 1
fi
version_flag=""
if [[ -n "$version" ]]; then
version_flag="-Pmetro.testCompilerVersion=$version"
fi
# Annoyingly, the apiDump and package lock tasks have caching issues
# https://youtrack.jetbrains.com/issue/KT-69684
rm -rf kotlin-js-store samples/kotlin-js-store
if [[ "$locks_only" = false ]]; then
echo "Applying formatting and API gen..."
find . -type d -name "api" -exec find {} -name "*.api" -delete \;
run_gradle_all "clean --quiet"
kempt format --all
# apiDump only exists in root project
echo "Running apiDump..."
# shellcheck disable=SC2086 # Word splitting is intentional so empty version_flag drops out
./gradlew apiDump --rerun-tasks --no-build-cache --no-configuration-cache --quiet $version_flag
echo "Generating diagnostics docs, dependency guard baselines..."
./gradlew :compiler:generateDiagnosticsDocs dependencyGuardBaseline --quiet
if [[ "$release_baselines" = true ]]; then
echo "Promoting Metalava release baselines..."
./gradlew metalavaGenerateSignature metalavaGenerateSignatureRelease --quiet
fi
else
echo "Regenerating package locks only..."
fi
# Yarn locks only in root and samples
echo "Upgrading root package locks..."
# shellcheck disable=SC2086
./gradlew kotlinWasmUpgradePackageLock kotlinUpgradePackageLock --rerun-tasks --no-build-cache --no-configuration-cache --quiet $version_flag
echo "Upgrading samples package locks..."
# shellcheck disable=SC2086
./gradlew -p samples kotlinWasmUpgradePackageLock kotlinUpgradePackageLock --rerun-tasks --no-build-cache --no-configuration-cache --quiet $version_flag
;;
"gen-compat")
if [[ $# -lt 2 ]]; then
echo "Usage: metrow gen-compat <kotlin-version>"
exit 1
fi
./compiler-compat/generate-compat-module.sh "$2"
;;
"trace")
# Delegate to the script so the logic lives in one place.
# Script takes: <project-dir> <gradle-task> [version]
if [[ $# -lt 3 ]]; then
echo "Usage: metrow trace <project-dir> <gradle-task> [version]"
echo ""
echo "Examples:"
echo " metrow trace ~/dev/android/personal/CatchUp :app-scaffold:compileDebugKotlin"
echo " metrow trace ~/dev/MyApp :app:compileKotlinJvm 1.0.0-LOCAL500"
exit 1
fi
shift
exec ./scripts/trace-project.sh "$@"
;;
"update-gradle")
if [[ $# -lt 2 ]]; then
echo "Usage: metrow update-gradle <gradle-version>"
exit 1
fi
gradle_version="$2"
echo "Updating Gradle wrappers to version $gradle_version..."
# Update root wrapper first
echo "=== Updating . ==="
./gradlew wrapper --gradle-version="$gradle_version"
# Run twice
./gradlew wrapper --gradle-version="$gradle_version"
# Copy updated wrapper files to all other wrapper locations
while IFS= read -r wrapper; do
dir="$(dirname "$wrapper")"
if [[ "$dir" == "." ]]; then
continue
fi
echo "=== Updating $dir ==="
cp gradlew gradlew.bat "$dir/"
cp gradle/wrapper/gradle-wrapper.jar gradle/wrapper/gradle-wrapper.properties "$dir/gradle/wrapper/"
done < <(find . -name gradlew -not -path './.gradle/*' | sort)
;;
*)
echo "Usage: metrow (publish|publish-idea-plugin|check|test|clean|format|regen|gen-compat|trace|update-gradle)"
echo ""
echo "publish options:"
echo " --version <version> Specify version for publishing"
echo " --local Publish locally"
echo ""
echo "publish-idea-plugin options:"
echo " --version <version> Specify IDE plugin version for publishing"
echo " --local Build the IDE plugin ZIP locally instead of publishing"
echo " --dry-run Preview publish tasks without publishing"
echo ""
echo "check options:"
echo " --all Test against all available compiler versions"
echo " --version <version> Test against specific compiler version"
echo ""
echo "test options:"
echo " --all Test against all available compiler versions"
echo " --version <version> Test against specific compiler version"
echo ""
echo "regen options:"
echo " --version <version> Regenerate against a specific compiler version"
echo " --locks-only Only regenerate package locks (skip format/apiDump/clean)"
echo " --release-baselines Promote the current APIs to Metalava's release baselines"
echo ""
echo "trace options:"
echo " <project-dir> <gradle-task> [version] Publish metro locally, pin it in"
echo " the target project, force-rerun the"
echo " compile, and copy the produced"
echo " perfetto trace into .claude/traces/."
echo ""
echo "update-gradle options:"
echo " <gradle-version> Gradle version to update all wrappers to"
exit 1
;;
esac