From e7ad22515e1d79f02f8cf2c88435e26854552a46 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Sat, 7 Nov 2026 11:00:16 +0100 Subject: Bump kotlin to 2.4.21 Support --- .gitignore | 3 +- CLAUDE.md | 141 ++-- Makefile | 40 +- README.md | 130 +++- docs/opcodes.html | 1249 ++++++++++++++++++++++++++++++++ jars/defs.txt | 54 +- jars/fallback.txt | 14 +- jars/scan.txt | 6 +- test_project/app/build.gradle.kts | 41 +- test_project/build.gradle.kts | 8 +- test_project/gradle/libs.versions.toml | 1 + tools/gen_class.py | 59 +- tools/gen_jar_lists.py | 235 ++++++ 13 files changed, 1820 insertions(+), 161 deletions(-) create mode 100644 docs/opcodes.html create mode 100644 tools/gen_jar_lists.py diff --git a/.gitignore b/.gitignore index 7773828..889fe2d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -dist/ \ No newline at end of file +dist/ +.stamp diff --git a/CLAUDE.md b/CLAUDE.md index 1bfdfac..f4d1d92 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -21,43 +21,48 @@ table). Read it before changing generation behavior. - `tools/gen_class.py` — self-contained Python stub generator (the core). Emits `.class` files **directly** (not Java source) by copying the real class's erased structure verbatim. +- `tools/gen_jar_lists.py` — regenerates the `jars/*.txt` lists from the local + Gradle cache (see Building). +- `docs/opcodes.html` — JVM bytecode opcode reference. **Consult it whenever + hand-rolling bytecode in `gen_class.py`** — opcodes like `putstatic` (0xb3) + and stack peaks are easy to get wrong, and the JVM only complains with an + inscrutable `VerifyError`. - `stubs/src/kotlin/proxy/KotlinProxyLog.java` — the logger every generated stub calls into. - `stubs/src/kotlin/proxy/KotlinProxyOverrides.java` — per-method custom return values: the extension point for actually *implementing* stub methods. - `stubs/src/kotlin/proxy/ProxyPerformanceManager.java` — override support class (per-compiler-instance perf manager) returned by the overrides. -- `jars/defs.txt`, `jars/scan.txt`, `jars/fallback.txt` — jar list files feeding - the generator (one jar path per line, `#` = comment). +- `jars/defs.txt`, `jars/scan.txt`, `jars/fallback.txt`, `jars/.stamp` — + auto-generated jar list files feeding the generator (one jar path per line, + `#` = comment); `.stamp` records the versions the lists were generated for. - `dist/kotlin-proxy-compiler-stubs.jar` — the build artifact (gitignored). -- `test_project/` — a minimal AGP app (AGP 9.4.1, Gradle 9.8.1, single file - `Hello.kt`) that consumes the jar to prove the stub runs in the daemon. +- `test_project/` — a minimal AGP app (AGP 9.4.1, Gradle 9.8.1, Kotlin 2.4.21, + single file `Hello.kt`) that consumes the jar to prove the stub runs in the + daemon. -## Building (3 steps, from repo root; JDK 11+ and Python 3) +## Building (from repo root; JDK 11+ and Python 3) ```bash -# 1. Generate the stub classes (WIPES --out first — put nothing you need there) -python3 tools/gen_class.py \ - --scan-jars jars/scan.txt --def-jars jars/defs.txt --fallback-jars jars/fallback.txt \ - --seed-only --no-closure \ - --seed 'org/jetbrains/kotlin/cli/jvm/K2JVMCompiler,org/jetbrains/kotlin/cli/jvm/K2JVMCompiler$Companion,org/jetbrains/kotlin/cli/jvm/K2JVMCompilerKt' \ - --out stubs/classes_min - -# 2. Compile the real classes into the SAME tree (MUST run after step 1, which -# wiped it). The -cp lets KotlinProxyOverrides import real compiler types. -javac -nowarn -proc:none -d stubs/classes_min \ - -cp "$(grep -v '^[[:space:]]*#' jars/defs.txt | tr '\n' ':')" \ - stubs/src/kotlin/proxy/KotlinProxyLog.java \ - stubs/src/kotlin/proxy/KotlinProxyOverrides.java \ - stubs/src/kotlin/proxy/ProxyPerformanceManager.java - -# 3. Package -jar cf dist/kotlin-proxy-compiler-stubs.jar -C stubs/classes_min . +make ``` -The result is 6 class files + manifest: the three seeded stubs plus -`kotlin/proxy/KotlinProxyLog`, `kotlin/proxy/KotlinProxyOverrides`, and -`kotlin/proxy/ProxyPerformanceManager`. The +The Makefile runs the 3 real steps in order: + +1. Regenerate `jars/*.txt` via `tools/gen_jar_lists.py` when the pinned + versions (Makefile vars `KOTLIN_VERSION` / `AGP_VERSION`, kept in sync with + `test_project/gradle/libs.versions.toml`) drift from `jars/.stamp`. The + Gradle cache must already hold those versions — run the test_project once + first (even a red build resolves everything). +2. Generate the stub classes (`tools/gen_class.py`, **wipes** `stubs/classes_min` + first — put nothing you need there): + `--seed-only --no-closure --seed '…K2JVMCompiler,…K2JVMCompiler$Companion,…K2JVMCompilerKt'`. +3. Compile the `kotlin.proxy.*` classes into the same tree (the `-cp` lets + `KotlinProxyOverrides` import real compiler types), then package the jar. + +The result is 7 class files + manifest: the three seeded stubs plus +`kotlin/proxy/KotlinProxyLog`, `kotlin/proxy/KotlinProxyOverrides` +(+ inner `$Compiler`), and `kotlin/proxy/ProxyPerformanceManager`. The seed trio are **the only** classes stubbed (the "trio" mode); their superclasses/interfaces (`CLICompiler`, `K2JVMCompilerArguments`, …) are *not* stubbed and resolve from the real jars on the daemon classpath. @@ -70,19 +75,31 @@ The "test" is the test project. From `test_project/`: ./gradlew :app:compileDebugKotlin ``` -Expected outcome: **red** (the stub returns defaults, so the real `CLICompiler` -machinery NPEs after calling into the stub). That is the intended state. To -confirm the stub actually ran *inside the out-of-process daemon*, read the marker -file `/tmp/kotlin-proxy-marker.txt` — a daemon run shows thread names -`RMI TCP Connection(N)` and `LOAD …/dist/kotlin-proxy-compiler-stubs.jar` lines. -An `OVERRIDE . inst=0x… -> ` line shows a +Expected outcome: **red** (`compileDebugKotlin FAILED`, "Internal compiler +error" — the stub returns defaults, so the real compiler machinery fails +after calling into the stub). That is the intended state. To confirm the stub +actually ran *inside the out-of-process daemon*, read the marker file +`/tmp/kotlin-proxy-marker.txt` — a daemon run shows thread names +`RMI TCP Connection(N)` and `LOAD …/dist/kotlin-proxy-compiler-stubs.jar` +lines (the trio's ``s also `LOAD` `…$Companion`). An +`OVERRIDE . inst=0x… -> ` line shows a `KotlinProxyOverrides.invoke` implementation supplied the return value (`inst` is the receiver instance the method was called on — omitted for -statics). -The marker path is fixed regardless of the daemon's working dir or missing -`-Dkotlin.proxy.log`, so it is the reliable proof. - -Sanity-check generated bytecode with `javap -c stubs/classes_min/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.class`. +statics). The marker path is fixed regardless of the daemon's working dir, +so it is the reliable proof. The daemon's full argument dump ("Starting +compilation with args: …") lands in `/tmp/kotlin-daemon.*.log`. + +Sanity-check generated bytecode with +`javap -c stubs/classes_min/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.class`. +Verify every hand-rolled opcode number and the declared `max_stack` against +`docs/opcodes.html` — the JVM only complains with an inscrutable +`VerifyError`. A small `java -cp dist/…jar:` main that does +`Class.forName` on the trio and constructs it catches verification/linkage +failures in seconds, without a full Gradle build. + +Stale daemons hold stale classpaths: `pkill -f 'KotlinCompile[D]aemon'` +(bracket trick so the pattern doesn't match your own shell) before +re-verifying, and `rm /tmp/kotlin-proxy-marker.txt` for a fresh marker. ## Architecture notes (why it works) @@ -94,8 +111,12 @@ Sanity-check generated bytecode with `javap -c stubs/classes_min/org/jetbrains/k the `Signature` attribute entirely (no generics, no clashes). The JVM links by name + erased descriptor, both copied verbatim, so the stub is ABI-identical. - **Straight-line bodies only:** method bodies have no branches, so no - `StackMapTable` frames are needed. `` calls `KotlinProxyLog.loaded`; - constructors call `super()` (enums call `Enum.("stub",0)`); concrete + `StackMapTable` frames are needed. `` calls `KotlinProxyLog.loaded` + and — when the class has a Kotlin companion object — mirrors the real + ``'s `new Companion; dup; aconst_null; invokespecial; putstatic` + (leaving the static null makes real code touching `.Companion` NPE + before any stub method is ever called). Constructors call `super()` (enums + call `Enum.("stub",0)`); concrete methods log and then return a default — but reference-class returns (except `String`) build an `Object[]` of the call's arguments (primitives boxed; `null` when param-less) and ask `KotlinProxyLog.returnValue`, which @@ -108,31 +129,37 @@ Sanity-check generated bytecode with `javap -c stubs/classes_min/org/jetbrains/k yields a real `K2JVMCompilerArguments`). Param-less erasure bridges forward to their concrete sibling instead of logging+null (the daemon dispatches through bridges). -- **Classpath shadowing (the subtle part):** KGP seeds the daemon classpath from - the `kotlinCompilerClasspath` configuration via hidden `defaultDependencies`. - Adding *any* regular dependency to that configuration suppresses those - defaults. So `test_project/app/build.gradle.kts` re-declares the real compiler - modules as regular deps **with the stub jar first**, making the daemon load - `K2JVMCompiler` from the stub. The root `build.gradle.kts` also puts the stub - first on the *buildscript* classpath. Both are intentional. +- **Classpath shadowing (the subtle part):** KGP ≥ 2.3.20 runs JVM compilation + through the **Build Tools API** by default, and the daemon's JVM classpath is + the resolved **`kotlinBuildToolsApiClasspath`** configuration (default deps: + `kotlin-build-tools-compat` + `kotlin-build-tools-impl`, whose transitive + closure *is* the compiler). Like any `defaultDependencies`-seeded + configuration, adding *any* regular dependency suppresses the defaults — so + `test_project/app/build.gradle.kts` re-declares the stub jar **first** plus + those two modules as regular deps, and the daemon loads `K2JVMCompiler` + from the stub. The older `kotlinCompilerClasspath` (legacy + `runViaBuildToolsApi=false` path, deprecated, removed in KGP 2.5) is shadowed + the same way for completeness. The root `build.gradle.kts` also puts the stub + first on the *buildscript* classpath, and pins KGP explicitly — AGP 9.x's + built-in Kotlin would otherwise apply its own pinned KGP version (AGP 9.0 + release notes, "Runtime dependency on Kotlin Gradle plugin"). + All intentional. ## Gotchas -- **Machine-specific absolute paths.** `jars/defs.txt`, `jars/scan.txt`, - `jars/fallback.txt` point into this machine's Gradle cache - (`/home/the_jk/.gradle/caches/…`), and `test_project/app/build.gradle.kts:51` - hardcodes `/home/the_jk/source/kotlin_proxy/dist/…`. On another machine or a - fresh checkout you must regenerate the jar lists and fix that path, or the - build will find no jars / no stub. -- **Version coupling.** The Kotlin version is pinned in three places and must - all match: `jars/defs.txt` (the 2.2.10 set), `jars/fallback.txt` (newer KGP - variants, def-lookup only), and the `realCompilerJars` list in - `test_project/app/build.gradle.kts`. Bumping the version means updating all - three (and re-seeding the daemon classpath list). +- **Machine-specific absolute paths.** The `jars/*.txt` lists point into this + machine's Gradle cache — regenerate them with `tools/gen_jar_lists.py` + (or `make jars`) on another machine or fresh checkout, and fix the hardcoded + `/home/the_jk/source/kotlin_proxy/dist/…` in `test_project/app/build.gradle.kts`. +- **Version coupling.** The Kotlin/AGP versions live in + `test_project/gradle/libs.versions.toml` (what the build uses) and + `KOTLIN_VERSION` / `AGP_VERSION` in the Makefile (what the jar lists are + generated for) — keep them in sync. The lists themselves are generated, and + `jars/.stamp` lets the Makefile detect drift and regenerate. - **`--seed-only` + `--no-closure`** produces exactly the seed set (the daemon jar). The default mode is a full transitive closure from the AGP scan jars + KGP plugin entry points — a much larger jar; only use it when you actually want to stub a broader surface. - **Build artifacts are gitignored:** `dist/` (whole dir) and `stubs/classes_min/` are not tracked. If you need the jar and it's missing, - run the 3 build steps above. + run `make`. diff --git a/Makefile b/Makefile index 7f4f548..d80c617 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,50 @@ -.PHONY: all clean compileStubs +.PHONY: all clean compileStubs jars + +# Versions the jar lists (jars/*.txt) are generated for — see +# tools/gen_jar_lists.py. Keep in sync with test_project/gradle/ +# libs.versions.toml (agp / kotlin). +KOTLIN_VERSION ?= 2.4.21 +AGP_VERSION ?= 9.4.1 all: dist/kotlin-proxy-compiler-stubs.jar +# Regenerate jars/defs.txt + scan.txt + fallback.txt + .stamp from the +# Gradle cache (the cache must already hold these versions - run the +# test_project once first, even a red build resolves everything). +# jars/.stamp is a REAL prerequisite: bumping KOTLIN_VERSION/AGP_VERSION +# above (or editing the tool) makes it stale, which rewrites the lists, +# which cascades the whole stub rebuild. +jars: jars/.stamp + +jars/.stamp: tools/gen_jar_lists.py Makefile + python3 tools/gen_jar_lists.py --kotlin-version $(KOTLIN_VERSION) \ + --agp-version $(AGP_VERSION) --out-dir jars + clean: rm -f dist/kotlin-proxy-compiler-stubs.jar rm -rf stubs/classes_min/* + rm -f jars/.stamp -stubs/classes_min/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.class: tools/gen_class.py jars/scan.txt jars/defs.txt jars/fallback.txt +stubs/classes_min/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.class: \ + tools/gen_class.py jars/scan.txt jars/defs.txt jars/fallback.txt \ + jars/.stamp python3 tools/gen_class.py \ --scan-jars jars/scan.txt \ --def-jars jars/defs.txt \ --fallback-jars jars/fallback.txt \ --seed-only --no-closure \ - --seed 'org/jetbrains/kotlin/cli/jvm/K2JVMCompiler,org/jetbrains/kotlin/cli/jvm/K2JVMCompiler$Companion,org/jetbrains/kotlin/cli/jvm/K2JVMCompilerKt' \ + --seed 'org/jetbrains/kotlin/cli/jvm/K2JVMCompiler,org/jetbrains/kotlin/cli/jvm/K2JVMCompiler$$Companion,org/jetbrains/kotlin/cli/jvm/K2JVMCompilerKt' \ --out stubs/classes_min -DEFS = $(shell grep -v '^[[:space:]]*#' jars/defs.txt | tr '\n' ':') - -compileStubs: stubs/classes_min/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.class jars/defs.txt stubs/src/kotlin/proxy/*.java +compileStubs: stubs/classes_min/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.class \ + jars/defs.txt stubs/src/kotlin/proxy/*.java + # DEFS is computed at recipe time: defs.txt may have been rewritten + # earlier in this same make run (via jars/.stamp), and a $(shell) + # variable would still hold the pre-rewrite contents. + DEFS=$$(grep -v '^[[:space:]]*#' jars/defs.txt | tr '\n' ':'); \ javac -nowarn -proc:none -d stubs/classes_min \ - -cp "$(DEFS)" \ - stubs/src/kotlin/proxy/*.java + -cp "$$DEFS" \ + stubs/src/kotlin/proxy/*.java dist/kotlin-proxy-compiler-stubs.jar: compileStubs jar cf $@ -C stubs/classes_min . diff --git a/README.md b/README.md index 2c14965..0a6e7d5 100644 --- a/README.md +++ b/README.md @@ -9,23 +9,38 @@ compile inside the stub. **Pure replacement: no passthrough, no fallback.** ``` kotlin-proxy/ +├── Makefile # builds everything (see below) ├── tools/gen_class.py # bytecode stub generator (self-contained) +├── tools/gen_jar_lists.py # regenerates the jars/*.txt lists from the Gradle cache +├── docs/opcodes.html # JVM bytecode opcode reference (for gen_class.py work) ├── stubs/ │ ├── src/kotlin/proxy/KotlinProxyLog.java # the logger the stubs call │ ├── src/kotlin/proxy/KotlinProxyOverrides.java # per-method custom return values │ ├── src/kotlin/proxy/ProxyPerformanceManager.java # override support class │ └── classes_min/ # generated .class files (build output) ├── jars/ -│ ├── defs.txt # 28 kotlin-2.2.10 jars (definition lookup) -│ ├── scan.txt # 6 AGP-9.4.1 jars (which kotlin classes AGP touches) -│ └── fallback.txt # newer KGP variants (definition lookup only) +│ ├── defs.txt # all kotlin- jars, sorted (definition lookup) +│ ├── scan.txt # AGP core jars (which kotlin classes AGP touches) +│ ├── fallback.txt # other cached KGP versions (definition lookup only) +│ └── .stamp # versions the lists were generated for (drift detection) ├── dist/kotlin-proxy-compiler-stubs.jar # the artifact └── test_project/ # AGP test app that consumes the jar ``` ## Building `dist/kotlin-proxy-compiler-stubs.jar` -Three steps, from the repo root. Requires JDK 11+ and Python 3. +```bash +make +``` + +from the repo root (requires JDK 11+ and Python 3). The Makefile regenerates +`jars/*.txt` via `tools/gen_jar_lists.py` whenever the pinned versions (its +`KOTLIN_VERSION` / `AGP_VERSION` vars — keep in sync with +`test_project/gradle/libs.versions.toml`) drift from `jars/.stamp`, then runs +the three steps below. The Gradle cache must already hold the pinned versions +— run `test_project` once first (even a red build resolves everything). + +The three steps, manually: ### 1. Generate the stub classes with `gen_class.py` @@ -74,13 +89,14 @@ classpath so your overrides may import compiler types (`CommonCompilerArguments` jar cf dist/kotlin-proxy-compiler-stubs.jar -C stubs/classes_min . ``` -Result: 6 class files + manifest +Result: 7 class files + manifest ``` $ jar tf dist/kotlin-proxy-compiler-stubs.jar | grep -v '/$' META-INF/MANIFEST.MF kotlin/proxy/KotlinProxyLog.class kotlin/proxy/KotlinProxyOverrides.class +kotlin/proxy/KotlinProxyOverrides$Compiler.class kotlin/proxy/ProxyPerformanceManager.class org/jetbrains/kotlin/cli/jvm/K2JVMCompiler$Companion.class org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.class @@ -111,9 +127,13 @@ Bodies are straight-line (no branches), so no `StackMapTable` frames are needed. The list files contain one jar path per line; `#` starts a comment. - `--def-jars` / `--fallback-jars` — the definition source. Every `.class` in - these jars is parsed into a `name → info` map (first jar wins). `defs.txt` - holds the full 2.2.10 set (KGP first for priority); `fallback.txt` adds newer - KGP variants for definitions not present in 2.2.10. + these jars is parsed into a `name → info` map (first jar wins). Both files + are auto-generated by `tools/gen_jar_lists.py`: `defs.txt` holds every + `org.jetbrains.kotlin` jar at the pinned Kotlin version, sorted by jar name — + the sort keeps `kotlin-compiler-*` ahead of `kotlin-gradle-plugin`, which + bundles its own byte-different copies of some compiler classes (the compiler + jar must win, it's what the daemon loads); `fallback.txt` adds other cached + KGP versions, newest first, for definitions missing from the pinned set. - `--scan-jars` — AGP jars. Only used when **not** in `--seed-only` mode: their Kotlin class references form the seed set S0. @@ -147,7 +167,11 @@ The list files contain one jar path per line; `#` starts a comment. ### What each generated member does - **``** (classes only): calls `KotlinProxyLog.loaded(dotname)` — proves - the stub shadowed the real class. + the stub shadowed the real class — and, when the class has a Kotlin companion + object, mirrors the real ``'s companion init (`new Companion; dup; + aconst_null; invokespecial; putstatic` — Kotlin builds the companion in the + enclosing class's static initializer; leaving the static null makes real code + touching `.Companion` NPE before any stub method is ever called). - **Constructors:** `super()` (or `Enum.("stub", 0)` for enums), then log. A public no-arg ctor is synthesized if the real class lacks one, so child stubs can `invokespecial super()`. @@ -224,32 +248,48 @@ the jars from `jars/defs.txt` on `javac`'s classpath if you import them. ## Using the jar in a build -The daemon is a separate JVM. Its compiler classpath comes from the Gradle -configuration `kotlinCompilerClasspath`, which KGP seeds via hidden -`defaultDependencies` (0 declared deps → 7 resolved jars). Adding **any** -regular dependency suppresses those defaults, so re-declare the real compiler -modules as regular dependencies **with the stub jar first** — the daemon then -loads `K2JVMCompiler` from the stub: +The daemon is a separate JVM. Since **KGP ≥ 2.3.20** it runs JVM compilation +through the **Build Tools API (BTA) by default**, and the daemon's JVM +classpath is the resolved **`kotlinBuildToolsApiClasspath`** configuration +(default deps: `kotlin-build-tools-compat` + `kotlin-build-tools-impl`, whose +transitive closure *is* the compiler — 15 jars at 2.4.21). Like any +`defaultDependencies`-seeded configuration, adding **any** regular dependency +suppresses the defaults, so re-declare the same modules as regular +dependencies **with the stub jar first** — the daemon then loads +`K2JVMCompiler` from the stub: ```kotlin // app/build.gradle.kts val proxyStub = file("/home/the_jk/source/kotlin_proxy/dist/kotlin-proxy-compiler-stubs.jar") -val realCompilerJars = listOf( - "org.jetbrains.kotlin:kotlin-compiler-embeddable:2.2.10", - "org.jetbrains.kotlin:kotlin-stdlib:2.2.10", - "org.jetbrains.kotlin:kotlin-script-runtime:2.2.10", - "org.jetbrains.kotlin:kotlin-reflect:1.6.10", - "org.jetbrains.kotlin:kotlin-daemon-embeddable:2.2.10", - "org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.8.0", - "org.jetbrains:annotations:13.0", -) +val kotlinVersion = "2.4.21" // from libs.versions.toml in the test project afterEvaluate { - val cfg = configurations.getByName("kotlinCompilerClasspath") - cfg.dependencies.add(dependencies.create(files(proxyStub))) - realCompilerJars.forEach { cfg.dependencies.add(dependencies.create(it)) } + // BTA path (the default since KGP 2.3.20): the daemon classpath + val bta = configurations.getByName("kotlinBuildToolsApiClasspath") + bta.dependencies.add(dependencies.create(files(proxyStub))) + bta.dependencies.add(dependencies.create( + "org.jetbrains.kotlin:kotlin-build-tools-compat:$kotlinVersion")) + bta.dependencies.add(dependencies.create( + "org.jetbrains.kotlin:kotlin-build-tools-impl:$kotlinVersion")) + // legacy path (kotlin.compiler.runViaBuildToolsApi=false; deprecated, + // removed in KGP 2.5.0) — shadow it the same way, with the full + // kotlinCompilerClasspath default closure re-declared } ``` +The legacy `kotlinCompilerClasspath` (what the daemon used before 2.3.20) +still exists; its closure is the classic `kotlin-compiler-embeddable` + +transitives set (`kotlin-stdlib`, `kotlin-script-runtime`, +`kotlin-reflect:1.6.10`, `kotlin-daemon-embeddable`, +`kotlinx-coroutines-core-jvm:1.8.0`, `org.jetbrains:annotations:13.0`) and the +test project shadows it too. + +Two more pins, both in the root `build.gradle.kts` buildscript: the stub jar +is declared **before** AGP/KGP on the buildscript classpath, and KGP is +declared explicitly (`org.jetbrains.kotlin:kotlin-gradle-plugin:`) +because **AGP 9.x's built-in Kotlin** applies its own pinned KGP version — an +explicit buildscript classpath dep upgrades it (AGP 9.0 release notes, +"Runtime dependency on Kotlin Gradle plugin"). + and in `gradle.properties`: ```properties @@ -258,10 +298,15 @@ kotlin.compiler.execution.strategy=daemon kotlin.daemon.useFallbackStrategy=false ``` -Expected outcome: `:app:compileDebugKotlin` **fails** (the stub returns -defaults/null, so the real `CLICompiler` machinery NPEs after calling into the -stub) — that's the point. The stub is the only compiler; the build goes green -only once the stub implements its own compile. +Expected outcome: `:app:compileDebugKotlin` **fails** (under BTA: "Internal +compiler error" — the stub returns defaults/null, so the real compiler +machinery fails after calling into the stub) — that's the point. The stub is +the only compiler; the build goes green only once the stub implements its own +compile. (A *green* build means the stub is not being loaded — that's a +failure state, not success.) The daemon's full argument dump ("Starting +compilation with args: …") is in `/tmp/kotlin-daemon.*.log`; stale daemons hold +stale classpaths, so kill them (`pkill -f 'KotlinCompile[D]aemon'`) and +`rm /tmp/kotlin-proxy-marker.txt` when re-verifying. ## Reading the log @@ -280,11 +325,18 @@ daemon's working directory or missing `-Dkotlin.proxy.log`: ``` RMI TCP Connection(2)-127.0.0.1 | LOAD org.jetbrains.kotlin.cli.jvm.K2JVMCompiler <- file:…/dist/kotlin-proxy-compiler-stubs.jar +RMI TCP Connection(2)-127.0.0.1 | LOAD org.jetbrains.kotlin.cli.jvm.K2JVMCompiler$Companion <- file:…/dist/kotlin-proxy-compiler-stubs.jar +RMI TCP Connection(2)-127.0.0.1 | CALL org.jetbrains.kotlin.cli.jvm.K2JVMCompiler$Companion. RMI TCP Connection(2)-127.0.0.1 | CALL org.jetbrains.kotlin.cli.jvm.K2JVMCompiler. -RMI TCP Connection(2)-127.0.0.1 | CALL org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.createArguments -RMI TCP Connection(2)-127.0.0.1 | CALL org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.createPerformanceManager arg=K2JVMCompilerArguments{destination=… classpath=… freeArgs=[…/Hello.kt] …} ``` +(Under the BTA flow the daemon drives compilation through its own +`CompileServiceImpl` with arguments it builds itself, so the stub's +`createArguments`/`execute` may never be *called* — the crash happens in the +real incremental machinery after construction. Under the legacy +`runViaBuildToolsApi=false` path you additionally see `CALL …createArguments` +and friends, with the boundary args dumped.) + - `LOAD <- ` — the stub class was initialized, from our jar. - `CALL .` — the stub member was invoked. - `CALL . arg=` — boundary argument: compiler-argument @@ -302,8 +354,12 @@ that method returned `null` — expected diagnostic noise, not an error. ## Regenerating after changes -- Changed the seeded class set or a stub's behavior → re-run steps 1–3. -- Changed `KotlinProxyLog.java` → re-run steps 2–3 (or all three; step 1 is +- Changed the seeded class set or a stub's behavior → `make` (steps 1–3). +- Changed `KotlinProxyLog.java` → steps 2–3 (or all three; step 1 is idempotent). -- Changed a kotlin version → update the jars in `jars/defs.txt` (and the - `realCompilerJars` versions in the build script). +- Bumped the Kotlin/AGP version → update `test_project/gradle/libs.versions.toml` + (what the build uses) and the Makefile's `KOTLIN_VERSION` / `AGP_VERSION` + (what the jar lists are generated for), run the test_project once so Gradle + primes the cache with the new jars (even a red build), then `make` — it + detects the drift against `jars/.stamp` and regenerates `jars/*.txt` via + `tools/gen_jar_lists.py` before regenerating the stubs. diff --git a/docs/opcodes.html b/docs/opcodes.html new file mode 100644 index 0000000..0f3e534 --- /dev/null +++ b/docs/opcodes.html @@ -0,0 +1,1249 @@ + + + + + + All Opcodes by Opcode Value - javaalmanac.io + + + + + + + + + + + + + + +
+
+ + GitHub +
+ +
+
+ The Java Version Almanac
+ javaalmanac.io +
+
+
+

All Opcodes by Opcode Value

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OpcodeMnemonicDescription
0nopDo nothing
1aconst_nullPush null
2iconst_m1Push int constant -1
3iconst_0Push int constant 0
4iconst_1Push int constant 1
5iconst_2Push int constant 2
6iconst_3Push int constant 3
7iconst_4Push int constant 4
8iconst_5Push int constant 5
9lconst_0Push long constant
10lconst_1Push long constant
11fconst_0Push float value 0.0
12fconst_1Push float value 1.0
13fconst_2Push float value 2.0
14dconst_0Push double value 0.0
15dconst_1Push double value 1.0
16bipushPush byte
17sipushPush short
18ldcPush item from constant pool
19ldc_wPush item from constant pool (wide index)
20ldc2_wPush long or double from constant pool (wide index)
21iloadLoad int from local variable
22lloadLoad long from local variable
23floadLoad float from local variable
24dloadLoad double from local variable
25aloadLoad reference from local variable
26iload_0Load int from local variable
27iload_1Load int from local variable
28iload_2Load int from local variable
29iload_3Load int from local variable
30lload_0Load long from local variable 0
31lload_1Load long from local variable 1
32lload_2Load long from local variable 2
33lload_3Load long from local variable 3
34fload_0Load float from local variable 0
35fload_1Load float from local variable 1
36fload_2Load float from local variable 2
37fload_3Load float from local variable 3
38dload_0Load double from local variable 0
39dload_1Load double from local variable 1
40dload_2Load double from local variable 2
41dload_3Load double from local variable 3
42aload_0Load reference from local variable 0
43aload_1Load reference from local variable 1
44aload_2Load reference from local variable 2
45aload_3Load reference from local variable 3
46ialoadLoad int from array
47laloadLoad long from array
48faloadLoad float from array
49daloadLoad double from array
50aaloadLoad reference from array
51baloadLoad byte or boolean from array
52caloadLoad char from array
53saloadLoad short from array
54istoreStore int into local variable
55lstoreStore long into local variable
56fstoreStore float into local variable
57dstoreStore double into local variable
58astoreStore reference into local variable
59istore_0Store int into local variable 0
60istore_1Store int into local variable 1
61istore_2Store int into local variable 2
62istore_3Store int into local variable 3
63lstore_0Store long into local variable 0
64lstore_1Store long into local variable 1
65lstore_2Store long into local variable 2
66lstore_3Store long into local variable 3
67fstore_0Store float into local variable 0
68fstore_1Store float into local variable 1
69fstore_2Store float into local variable 2
70fstore_3Store float into local variable 3
71dstore_0Store double into local variable 0
72dstore_1Store double into local variable 1
73dstore_2Store double into local variable 2
74dstore_3Store double into local variable 3
75astore_0Store reference into local variable 0
76astore_1Store reference into local variable 1
77astore_2Store reference into local variable 2
78astore_3Store reference into local variable 3
79iastoreStore into int array
80lastoreStore into long array
81fastoreStore into float array
82dastoreStore into double array
83aastoreStore into reference array
84bastoreStore into byte or boolean array
85castoreStore into char array
86sastoreStore into short array
87popPop the top operand stack value
88pop2Pop the top one or two operand stack values
89dupDuplicate the top operand stack value
90dup_x1Duplicate the top operand stack value and insert two values down
91dup_x2Duplicate the top operand stack value and insert two or three values down
92dup2Duplicate the top one or two operand stack values
93dup2_x1Duplicate the top one or two operand stack values and insert two or three values down
94dup2_x2Duplicate the top one or two operand stack values and insert two, three, or four values down
95swapSwap the top two operand stack values
96iaddAdd int
97laddAdd long
98faddAdd float
99daddAdd double
100isubSubtract int
101lsubSubtract long
102fsubSubtract float
103dsubSubtract double
104imulMultiply int
105lmulMultiply long
106fmulMultiply float
107dmulMultiply double
108idivDivide int
109ldivDivide long
110fdivDivide float
111ddivDivide double
112iremRemainder int
113lremRemainder long
114fremRemainder float
115dremRemainder double
116inegNegate int
117lnegNegate long
118fnegNegate float
119dnegNegate double
120ishlShift left int
121lshlShift left long
122ishrArithmetic shift right int
123lshrArithmetic shift right long
124iushrLogical shift right int
125lushrLogical shift right long
126iandBoolean AND int
127landBoolean AND long
128iorBoolean OR int
129lorBoolean OR long
130ixorBoolean XOR int
131lxorBoolean XOR long
132iincIncrement local variable by constant
133i2lConvert int to long
134i2fConvert int to float
135i2dConvert int to double
136l2iConvert long to int
137l2fConvert long to float
138l2dConvert long to double
139f2iConvert float to int
140f2lConvert float to long
141f2dConvert float to double
142d2iConvert double to int
143d2lConvert double to long
144d2fConvert double to float
145i2bConvert int to byte
146i2cConvert int to char
147i2sConvert int to short
148lcmpCompare long
149fcmplCompare float
150fcmpgCompare float
151dcmplCompare double
152dcmpgCompare double
153ifeqJump if int comparison with zero succeeds
154ifneJump if int comparison with zero succeeds
155ifltJump if int comparison with zero succeeds
156ifgeJump if int comparison with zero succeeds
157ifgtJump if int comparison with zero succeeds
158ifleJump if int comparison with zero succeeds
159if_icmpeqJump if int comparison succeeds
160if_icmpneJump if int comparison succeeds
161if_icmpltJump if int comparison succeeds
162if_icmpgeJump if int comparison succeeds
163if_icmpgtJump if int comparison succeeds
164if_icmpleJump if int comparison succeeds
165if_acmpeqJump if reference comparison succeeds
166if_acmpneJump if reference comparison succeeds
167gotoUnconditional jump
168jsrJump subroutine
169retReturn from subroutine
170tableswitchAccess jump table by index and jump
171lookupswitchAccess jump table by key match and jump
172ireturnReturn int from method
173lreturnReturn long from method
174freturnReturn float from method
175dreturnReturn double from method
176areturnReturn reference from method
177returnReturn void from method
178getstaticGet static field from class
179putstaticSet static field in class
180getfieldFetch field from object
181putfieldSet field in object
182invokevirtualInvoke instance method, dispatch based on class
183invokespecialDirectly invoke instance (initialization) method of the current class or its supertypes
184invokestaticInvoke static method
185invokeinterfaceInvoke interface method
186invokedynamicInvoke a dynamically-computed call site
187newCreate new object
188newarrayCreate new array
189anewarrayCreate new array of reference
190arraylengthGet length of array
191athrowThrow Throwable reference
192checkcastCheck whether reference is of given type
193instanceofDetermine if reference is of given type
194monitorenterEnter monitor for object
195monitorexitExit monitor for object
196wideExtend local variable index by additional bytes
197multianewarrayCreate new multidimensional array
198ifnullJump if reference is null
199ifnonnullJump if reference not null
200goto_wUnconditional jump (wide index)
201jsr_wJump subroutine (wide index)
202breakpointReserved for internal usage in debuggers
254impdep1Reserved for internal usage in JVM
255impdep2Reserved for internal usage in JVM
+ + +
+ + + +
\ No newline at end of file diff --git a/jars/defs.txt b/jars/defs.txt index 26903ec..0759586 100644 --- a/jars/defs.txt +++ b/jars/defs.txt @@ -1,29 +1,25 @@ -# auto-generated: all org.jetbrains.kotlin 2.2.10 jars (priority order: KGP first) -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/abi-tools-api/2.2.10/d3d684d1dfec17b0c9f0fda875da938d5f304328/abi-tools-api-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-build-statistics/2.2.10/e826d07e18ad23dc3894d40113fd5e79a94f83b3/kotlin-build-statistics-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-build-tools-api/2.2.10/eac607420801deb9abcf71e250ab1ea11b049c06/kotlin-build-tools-api-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-build-tools-impl/2.2.10/6bf34d03b713e0536300b0d507bdd701ba53318c/kotlin-build-tools-impl-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-compiler-embeddable/2.2.10/6882d39ef03b18879c1a5d2a83c2212361bed5fe/kotlin-compiler-embeddable-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-compiler-runner/2.2.10/aee5165d5829687acee89311747076622a05d664/kotlin-compiler-runner-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-daemon-client/2.2.10/9de9722b2ab63b00fed168c924c41ea3b2f7d9c5/kotlin-daemon-client-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-daemon-embeddable/2.2.10/212fd3c2c6e4e5d0f4db3c4191233e2b622380cc/kotlin-daemon-embeddable-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-gradle-plugin/2.2.10/5b7032e3454baa99627177ef48a324dbf33d42a3/kotlin-gradle-plugin-2.2.10-gradle813.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-gradle-plugin-annotations/2.2.10/45152dbad91398d945afff472498c8610cef5ae5/kotlin-gradle-plugin-annotations-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-gradle-plugin-api/2.2.10/8b990c8b8a53b5179f6a7a43718079cabac9d4c9/kotlin-gradle-plugin-api-2.2.10-gradle813.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-gradle-plugin-api/2.2.10/8b990c8b8a53b5179f6a7a43718079cabac9d4c9/kotlin-gradle-plugin-api-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-gradle-plugin-idea/2.2.10/a07b350797aa4fe6d4bc6e1be2feecb638e94b13/kotlin-gradle-plugin-idea-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-gradle-plugin-idea-proto/2.2.10/2caef57b02e64afbcbb276e4f1edb5d9807d8fa4/kotlin-gradle-plugin-idea-proto-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-gradle-plugin-model/2.2.10/530a4cac0ce3ac72ad548f9128cbae8b5bb22d3e/kotlin-gradle-plugin-model-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-klib-commonizer-api/2.2.10/e7a9a8f5ca3d6027fb86f1df5bb2ce2812b1486a/kotlin-klib-commonizer-api-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-native-utils/2.2.10/6c6650142c8ddaf921ffc46f9757b39681c0c02e/kotlin-native-utils-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/2.2.10/98d0ca9819d98cb3aa5c0a25793830b6659feee2/kotlin-reflect-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-scripting-common/2.2.10/87769c03c5456d7c827fc950063664907b192c1c/kotlin-scripting-common-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-scripting-compiler-embeddable/2.2.10/25d0e9a886551d4a46ae85d4d5d0088829ef9/kotlin-scripting-compiler-embeddable-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-scripting-compiler-impl-embeddable/2.2.10/3f1bcab651be1ab86e8d240b797b1a05dd8b0027/kotlin-scripting-compiler-impl-embeddable-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-scripting-jvm/2.2.10/beecd90e2b145845581e953ba8420f1b30cac848/kotlin-scripting-jvm-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-script-runtime/2.2.10/712f9bc08f378c13a4a00f0bbb28c76e59183e83/kotlin-script-runtime-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/2.2.10/30de6faa127a4a012db8e71bf1b9c0a99b1402b2/kotlin-stdlib-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-tooling-core/2.2.10/685151c03e638207a3b5045002411fbef78fdeb/kotlin-tooling-core-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-util-io/2.2.10/aa4dc86feb1b0d99f14f0510892ddecf6f6139fd/kotlin-util-io-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-util-klib/2.2.10/82e5679f8609ebd439f96fd708cc8644b5f06f0/kotlin-util-klib-2.2.10.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-util-klib-metadata/2.2.10/aae4449834d66cddf14f0fb5b8867eb422bb52f0/kotlin-util-klib-metadata-2.2.10.jar +# auto-generated by tools/gen_jar_lists.py - all org.jetbrains.kotlin 2.4.21 jars, sorted by jar name. +# First jar wins for duplicate class names; the sort keeps kotlin-compiler-* ahead of kotlin-gradle-plugin (which bundles its own copies of some compiler classes - the compiler jar must win, it is what the daemon loads). +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/fus-statistics-gradle-plugin/2.4.21/7c681b78d0a55042d8fbcb0cf71f9b6e9f096690/fus-statistics-gradle-plugin-2.4.21-gradle96.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-build-statistics/2.4.21/b30a5c617e48175fd04a595a5a4043bc5de51a4c/kotlin-build-statistics-2.4.21.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-build-tools-api/2.4.21/f5fd68c20ba38519b91ab2411b004a1730453d6f/kotlin-build-tools-api-2.4.21.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-build-tools-compat/2.4.21/cb4697b622ca0fbc5bfd5ac5521d8603e21dc219/kotlin-build-tools-compat-2.4.21.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-build-tools-cri-impl/2.4.21/f4d2161fc6a0a6f727bc673b8c90ebb0cad4c479/kotlin-build-tools-cri-impl-2.4.21.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-build-tools-impl/2.4.21/898086a64b68b1e9131900909e0fc056a782f37f/kotlin-build-tools-impl-2.4.21.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-compiler-embeddable/2.4.21/3cd9c37c505fb9879e03ebeaf91d9c9500ab6eca/kotlin-compiler-embeddable-2.4.21.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-compiler-runner/2.4.21/74c995efdbc8e7347b42d33af076920daee81064/kotlin-compiler-runner-2.4.21.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-daemon-client/2.4.21/6fc0b01cd07b02b22ec967a50f6aa7677ea9c0c9/kotlin-daemon-client-2.4.21.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-daemon-embeddable/2.4.21/5d9b0394b3ff65cd3dd33c6c31a2956b1d59885a/kotlin-daemon-embeddable-2.4.21.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-gradle-plugin/2.4.21/d2b2862980453fbeb168a03dddd488d6191924df/kotlin-gradle-plugin-2.4.21-gradle96.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-gradle-plugin-annotations/2.4.21/5d64348c7dd8f3736555f3cac0556a177d1d3d5d/kotlin-gradle-plugin-annotations-2.4.21.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-gradle-plugin-api/2.4.21/8789c5d15e46b4e76829f7e6eafaed0857874b3b/kotlin-gradle-plugin-api-2.4.21-gradle96.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-gradle-plugin-idea/2.4.21/905431b905fbd7c516de862a1179d7ab5fae3955/kotlin-gradle-plugin-idea-2.4.21.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-gradle-plugin-idea-proto/2.4.21/c4c011b9b4faea9fef5ee3621d1077e7cd00133e/kotlin-gradle-plugin-idea-proto-2.4.21.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-klib-commonizer-api/2.4.21/7c86237fb33c50e8528f8647545dab82b6960ebb/kotlin-klib-commonizer-api-2.4.21.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-native-utils/2.4.21/99bf50b458106ba2be3e3ff2fdf8595a29222009/kotlin-native-utils-2.4.21.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-script-runtime/2.4.21/abc7ff9f7e229cb6bdfadad81e93c871e6cdde41/kotlin-script-runtime-2.4.21.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/2.4.21/c343e135bd1e7dd94b7ed76b4159068d888d09db/kotlin-stdlib-2.4.21.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-tooling-core/2.4.21/a92e365882e147d1054b6245d2aa822cbaa77ad6/kotlin-tooling-core-2.4.21.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-util-io/2.4.21/da0390f54b55e09143cf7bd70be6ad96c81a07e/kotlin-util-io-2.4.21.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-util-klib/2.4.21/13ee113384a48115a7c9d62f17c308c3d8646ab0/kotlin-util-klib-2.4.21.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-util-klib-metadata/2.4.21/f9877e1572694cae3c27125624cd7a5a753140e/kotlin-util-klib-metadata-2.4.21.jar diff --git a/jars/fallback.txt b/jars/fallback.txt index 915693a..a9e3713 100644 --- a/jars/fallback.txt +++ b/jars/fallback.txt @@ -1,7 +1,11 @@ -# fallback: newer variants for definition lookup only -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-gradle-plugin/2.4.0/18bfb59ea7d01e0ae925f5a5535e61a98624ed3f/kotlin-gradle-plugin-2.4.0-gradle813.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-gradle-plugin/2.4.10/54e85b6639aa6819abc9985612e470576540e8ec/kotlin-gradle-plugin-2.4.10-gradle813.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-gradle-plugin-api/2.4.0/75cef3ce6f6086fd3943cc614158c889b84ce5d1/kotlin-gradle-plugin-api-2.4.0-gradle813.jar +# auto-generated by tools/gen_jar_lists.py - org.jetbrains.kotlin KGP-plugin-family jars at other cached versions, newest first. Definition lookup only (fallback.txt is scanned after defs.txt). +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-tooling-core/2.4.10/75970f5a2a9cb4d25557965bbec0a7ccd55bfbcf/kotlin-tooling-core-2.4.10.jar /home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-gradle-plugin-api/2.4.10/57abfa0230a1ffc31556110bff4b946b55967ba3/kotlin-gradle-plugin-api-2.4.10-gradle813.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-gradle-plugin/2.4.10/54e85b6639aa6819abc9985612e470576540e8ec/kotlin-gradle-plugin-2.4.10-gradle813.jar /home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-tooling-core/2.4.0/75970f5a2a9cb4d25557965bbec0a7ccd55bfbcf/kotlin-tooling-core-2.4.0.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-tooling-core/2.4.10/75970f5a2a9cb4d25557965bbec0a7ccd55bfbcf/kotlin-tooling-core-2.4.10.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-gradle-plugin-api/2.4.0/75cef3ce6f6086fd3943cc614158c889b84ce5d1/kotlin-gradle-plugin-api-2.4.0-gradle813.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-gradle-plugin/2.4.0/18bfb59ea7d01e0ae925f5a5535e61a98624ed3f/kotlin-gradle-plugin-2.4.0-gradle813.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-tooling-core/2.2.10/685151c03e638207a3b5045002411fbef78fdeb/kotlin-tooling-core-2.2.10.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-gradle-plugin-api/2.2.10/8b990c8b8a53b5179f6a7a43718079cabac9d4c9/kotlin-gradle-plugin-api-2.2.10.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-gradle-plugin-api/2.2.10/8b990c8b8a53b5179f6a7a43718079cabac9d4c9/kotlin-gradle-plugin-api-2.2.10-gradle813.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-gradle-plugin/2.2.10/5b7032e3454baa99627177ef48a324dbf33d42a3/kotlin-gradle-plugin-2.2.10-gradle813.jar diff --git a/jars/scan.txt b/jars/scan.txt index ed6fc9a..8cb7bb9 100644 --- a/jars/scan.txt +++ b/jars/scan.txt @@ -1,7 +1,7 @@ -# AGP 9.4.1 jars on the buildscript classpath (the classes "AGP uses") +# auto-generated by tools/gen_jar_lists.py - AGP 9.4.1 core jars on the buildscript classpath (the classes AGP uses; seed source for full-closure mode). +/home/the_jk/.gradle/caches/modules-2/files-2.1/com.android.tools.build/builder/9.4.1/af1135b3a2fd9c7606e2f0e301348147953e49ef/builder-9.4.1.jar +/home/the_jk/.gradle/caches/modules-2/files-2.1/com.android.tools.build/builder-model/9.4.1/9dd0f1cd71305a2ea484adfc223535ab88aeb72e/builder-model-9.4.1.jar /home/the_jk/.gradle/caches/modules-2/files-2.1/com.android.tools.build/gradle/9.4.1/41c81edd76f786e79cb4807c3435aba3857eca18/gradle-9.4.1.jar /home/the_jk/.gradle/caches/modules-2/files-2.1/com.android.tools.build/gradle-api/9.4.1/ce1f7c278ac4af318446d43fcec073752a84a00a/gradle-api-9.4.1.jar /home/the_jk/.gradle/caches/modules-2/files-2.1/com.android.tools.build/gradle-common-api/9.4.1/188fc42710d4072ae7f02415b497fe311041b555/gradle-common-api-9.4.1.jar /home/the_jk/.gradle/caches/modules-2/files-2.1/com.android.tools.build/gradle-settings-api/9.4.1/fcfedf9a56578511894c869f71eaecafbf5e49e6/gradle-settings-api-9.4.1.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/com.android.tools.build/builder/9.4.1/af1135b3a2fd9c7606e2f0e301348147953e49ef/builder-9.4.1.jar -/home/the_jk/.gradle/caches/modules-2/files-2.1/com.android.tools.build/builder-model/9.4.1/9dd0f1cd71305a2ea484adfc223535ab88aeb72e/builder-model-9.4.1.jar diff --git a/test_project/app/build.gradle.kts b/test_project/app/build.gradle.kts index 7a9492d..8938318 100644 --- a/test_project/app/build.gradle.kts +++ b/test_project/app/build.gradle.kts @@ -42,29 +42,44 @@ dependencies { } // ---- kotlin-proxy: force our compiler stub to the FRONT of the daemon classpath ---- -// KGP seeds the daemon classpath via `kotlinCompilerClasspath` using -// defaultDependencies (kotlin-compiler-embeddable + transitives). Adding ANY -// regular dependency suppresses those defaults - so we re-declare the real -// compiler modules as regular deps WITH our stub jar FIRST. The daemon then -// loads org.jetbrains.kotlin.cli.jvm.K2JVMCompiler from OUR stub, replacing -// the real compiler with our alternative. +// KGP seeds the daemon classpath with hidden defaultDependencies; adding ANY +// regular dependency suppresses those defaults - so we re-declare the same +// modules as regular deps WITH our stub jar FIRST. The daemon then loads +// org.jetbrains.kotlin.cli.jvm.K2JVMCompiler from OUR stub, replacing the +// real compiler with our alternative. +// +// KGP >= 2.3.20 runs JVM compilation through the Build Tools API by default: +// the daemon classpath is the resolved `kotlinBuildToolsApiClasspath` +// (defaults: kotlin-build-tools-compat + kotlin-build-tools-impl, whose +// closure IS the compiler). The older `kotlinCompilerClasspath` still +// feeds the legacy path (kotlin.compiler.runViaBuildToolsApi=false, +// deprecated, removed in KGP 2.5.0). We shadow both. val proxyStub = file("/home/the_jk/source/kotlin_proxy/dist/kotlin-proxy-compiler-stubs.jar") -val realCompilerJars = listOf( - "org.jetbrains.kotlin:kotlin-compiler-embeddable:2.2.10", - "org.jetbrains.kotlin:kotlin-stdlib:2.2.10", - "org.jetbrains.kotlin:kotlin-script-runtime:2.2.10", +val kotlinVersion = libs.versions.kotlin.get() +// legacy path: the kotlinCompilerClasspath default (kotlin-compiler-embeddable +// + its transitive deps). reflect stays at 1.6.10 - the POM pin. +val legacyCompilerJars = listOf( + "org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinVersion", + "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion", + "org.jetbrains.kotlin:kotlin-script-runtime:$kotlinVersion", "org.jetbrains.kotlin:kotlin-reflect:1.6.10", - "org.jetbrains.kotlin:kotlin-daemon-embeddable:2.2.10", + "org.jetbrains.kotlin:kotlin-daemon-embeddable:$kotlinVersion", "org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.8.0", "org.jetbrains:annotations:13.0", ) afterEvaluate { try { + val bta = configurations.getByName("kotlinBuildToolsApiClasspath") + bta.dependencies.add(dependencies.create(files(proxyStub))) + bta.dependencies.add(dependencies.create( + "org.jetbrains.kotlin:kotlin-build-tools-compat:$kotlinVersion")) + bta.dependencies.add(dependencies.create( + "org.jetbrains.kotlin:kotlin-build-tools-impl:$kotlinVersion")) val cfg = configurations.getByName("kotlinCompilerClasspath") cfg.dependencies.add(dependencies.create(files(proxyStub))) - realCompilerJars.forEach { cfg.dependencies.add(dependencies.create(it)) } + legacyCompilerJars.forEach { cfg.dependencies.add(dependencies.create(it)) } logger.lifecycle("kotlin-proxy: AGP stub present=" + proxyStub.exists() + - " ORDER=" + cfg.files.joinToString(",") { it.name }) + " BTA ORDER=" + bta.files.joinToString(",") { it.name }) } catch (t: Throwable) { logger.lifecycle("kotlin-proxy: AGP injection FAILED: " + t) } diff --git a/test_project/build.gradle.kts b/test_project/build.gradle.kts index da8ee01..196c760 100644 --- a/test_project/build.gradle.kts +++ b/test_project/build.gradle.kts @@ -13,8 +13,12 @@ buildscript { dependencies { // 1) kotlin-proxy compiler stubs — must come before AGP/KGP classpath(files("../dist/kotlin-proxy-compiler-stubs.jar")) - // 2) AGP (pulls kotlin-gradle-plugin 2.2.10 transitively) - classpath("com.android.tools.build:gradle:9.4.1") + // 2) KGP — AGP 9.x's built-in Kotlin pins its own KGP version; an + // explicit buildscript classpath dep upgrades it (AGP 9.0 release + // notes: "Runtime dependency on Kotlin Gradle plugin") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${libs.versions.kotlin.get()}") + // 3) AGP + classpath("com.android.tools.build:gradle:${libs.versions.agp.get()}") } } diff --git a/test_project/gradle/libs.versions.toml b/test_project/gradle/libs.versions.toml index 0d165ea..fa1d089 100644 --- a/test_project/gradle/libs.versions.toml +++ b/test_project/gradle/libs.versions.toml @@ -1,5 +1,6 @@ [versions] agp = "9.4.1" +kotlin = "2.4.21" coreKtx = "1.19.1" junit = "4.13.2" junitVersion = "1.3.0" diff --git a/tools/gen_class.py b/tools/gen_class.py index 8e1e0f4..ba0a92f 100755 --- a/tools/gen_class.py +++ b/tools/gen_class.py @@ -495,11 +495,52 @@ def ctor_body(cp, super_name, member, dotname, desc, call_ref, is_enum): return code_attr(cp, max_stack, count_locals(desc, False), b) -def clinit_body(cp, dotname, loaded_ref): +def clinit_body(cp, dotname, loaded_ref, internal, companion=None): b = ldc(cp.string(dotname)) b += bytes([0xb8]) + struct.pack(">H", loaded_ref) + max_stack = 2 + if companion: + # new; dup; aconst_null -> 3 on the stack before invokespecial pops + max_stack = 3 + # mirror the real 's companion-object init: + # new Companion; dup; aconst_null; invokespecial Companion.; + # putstatic Companion + # (leaving the static null makes real code touching + # .Companion NPE before any stub method is ever called) + fname, fdesc, cname, ctor = companion + b += bytes([0xbb]) + struct.pack(">H", cp.cls(cname)) # new + b += b"\x59" # dup + b += b"\x01" # aconst_null + b += bytes([0xb7]) + struct.pack( + ">H", cp.methodref(cname, "", ctor)) # invokespecial + b += bytes([0xb3]) + struct.pack( + ">H", cp.fieldref(internal, fname, fdesc)) # putstatic b += b"\xb1" # return - return code_attr(cp, 2, 0, b) + return code_attr(cp, max_stack, 0, b) + + +def companion_init(name, info, defs): + """If class `name` (internal) declares a static `$Companion` field, + describe how to instantiate it in . Returns + (field_name, field_desc, companion_internal, ctor_desc) or None. + Kotlin companion objects are built by the enclosing class's real + through the synthetic DefaultConstructorMarker ctor.""" + marker_ctor = "(Lkotlin/jvm/internal/DefaultConstructorMarker;)V" + for f in info.get("fields", []): + if not (f["access"] & A_STATIC): + continue + t = f["desc"][1:-1] + if t != name + "$Companion" or len(f["desc"]) <= 2: + continue + cname = t + ce = defs.get(cname) + ctors = {mm["desc"] for mm in ce[1].get("methods", []) + if mm["name"] == ""} if ce else set() + if marker_ctor in ctors: + return (f["name"], f["desc"], cname, marker_ctor) + if "()V" in ctors: + return (f["name"], f["desc"], cname, "()V") + return None def bridge_body(cp, dotname, name, target_desc, is_static): @@ -538,7 +579,7 @@ def field_bytes(cp, name, desc, access): # ---------------------------------------------------------------------- # class emission # ---------------------------------------------------------------------- -def emit_class(cp, name, info, is_iface, dotname): +def emit_class(cp, name, info, is_iface, dotname, companion=None): this_idx = cp.cls(name) super_name = (info.get("super") or OBJ) if not is_iface else OBJ super_idx = cp.cls(super_name) @@ -604,10 +645,12 @@ def emit_class(cp, name, info, is_iface, dotname): call_ref, is_enum) methods.append(method_bytes(cp, "", "()V", A_PUBLIC, body)) - # synthesized static initializer -> KotlinProxyLog.loaded(name) + # synthesized static initializer -> KotlinProxyLog.loaded(name), + # plus the companion-object init when the class has one methods.append(method_bytes(cp, "", "()V", A_STATIC | A_PRIVATE, - clinit_body(cp, dotname, loaded_ref))) + clinit_body(cp, dotname, loaded_ref, + name, companion))) out = bytearray() out += struct.pack(">IHH", MAGIC, MINOR, MAJOR) @@ -727,6 +770,9 @@ def main(): pass for s in seeds: s0.add(s) + bad = sorted(s for s in seeds if s not in defs) + if bad: + sys.exit("error: seed(s) not found in def jars:\n " + "\n ".join(bad)) # transitive closure (skipped with --no-closure: emit exactly the seed set) closure = set(s0) @@ -782,7 +828,8 @@ def main(): else: _, info = e is_iface = bool(info["access"] & A_INTERFACE) - data = emit_class(cp, name, info, is_iface, dot) + companion = None if is_iface else companion_init(name, info, defs) + data = emit_class(cp, name, info, is_iface, dot, companion) n_full += 1 if is_iface: n_iface += 1 diff --git a/tools/gen_jar_lists.py b/tools/gen_jar_lists.py new file mode 100644 index 0000000..06ab026 --- /dev/null +++ b/tools/gen_jar_lists.py @@ -0,0 +1,235 @@ +#!/usr/bin/env python3 +""" +Regenerate the jar list files in jars/ (the input to gen_class.py). + +These files used to be written by hand; this script scans the local Gradle +module cache and rewrites them deterministically, so a Kotlin/AGP upgrade is: + + 1. bump the version in test_project (gradle/libs.versions.toml) and + Makefile (KOTLIN_VERSION / AGP_VERSION), + 2. run the test_project once so Gradle populates the cache with the new + jars (even a red build resolves everything), + 3. run this script (or just `make` - it regenerates the lists when the + pinned versions drift from jars/.stamp). + +Files written (one jar path per line, '#' comments allowed downstream): + + defs.txt every org.jetbrains.kotlin jar at the pinned Kotlin version, + sorted by jar name. gen_class.py takes the FIRST jar that + contains a class (first-wins), and the KGP jar bundles its + own copies of some compiler classes (e.g. K2JVMCompiler) + that DIFFER from the ones in kotlin-compiler-embeddable; + alphabetical order keeps kotlin-compiler-* ahead of + kotlin-gradle-plugin, which is the ordering the daemon + actually sees. + scan.txt the AGP core jars at the pinned AGP version (the classes + "AGP uses" - seed source for the full-closure mode). + fallback.txt KGP-plugin-family jars at OTHER cached versions, newest + first - definition lookup only, for classes missing from + the pinned set. + +Also writes /.stamp as " " so the +Makefile can detect version drift without parsing the lists. +""" + +import argparse +import os +import re +import sys + +# AGP core jars on the buildscript classpath (seed sources for +# gen_class.py's full-closure mode). A fixed allowlist rather than "every +# com.android.tools.build jar" so aaptcompiler/lint/... don't bloat S0. +SCAN_ARTIFACTS = [ + "gradle", + "gradle-api", + "gradle-common-api", + "gradle-settings-api", + "builder", + "builder-model", +] + +# KGP plugin family used for fallback definition lookup (other versions of +# the plugin that the build actually runs with). +FALLBACK_ARTIFACTS = [ + "kotlin-gradle-plugin", + "kotlin-gradle-plugin-api", + "kotlin-tooling-core", +] + +KOTLIN_GROUP = "org.jetbrains.kotlin" +AGP_GROUP = "com.android.tools.build" + + +def ver_key(v): + """Sortable key for a version string: numeric parts first, then text + (so 2.4.10 > 2.4.9 and 2.4.21-rc1 sorts near 2.4.21).""" + m = re.match(r"(\d+(?:\.\d+)*)", v) + nums = [int(p) for p in m.group(1).split(".")] if m else [] + return (nums, v) + + +def find_jars(cache, group, artifact, version): + """All .jar files for group:artifact:version in the cache layout + /////.jar.""" + base = os.path.join(cache, group, artifact, version) + if not os.path.isdir(base): + return [] + out = [] + for sha in os.listdir(base): + d = os.path.join(base, sha) + if not os.path.isdir(d): + continue + for f in os.listdir(d): + # binary jars only - skip -sources.jar / -javadoc.jar + if (f.endswith(".jar") and os.path.isfile(os.path.join(d, f)) + and "-sources" not in f and "-javadoc" not in f): + out.append(os.path.join(d, f)) + return out + + +def all_versions(cache, group, artifact): + base = os.path.join(cache, group, artifact) + if not os.path.isdir(base): + return [] + return sorted( + (v for v in os.listdir(base) + if os.path.isdir(os.path.join(base, v)) and v[0].isdigit()), + key=ver_key, + ) + + +def write_if_changed(path, lines): + content = "\n".join(lines) + "\n" + old = None + if os.path.exists(path): + with open(path) as fh: + old = fh.read() + if old == content: + print(f"unchanged {os.path.basename(path)} ({len(lines)} lines)") + return False + with open(path, "w") as fh: + fh.write(content) + print(f"wrote {os.path.basename(path)} ({len(lines)} lines)") + return True + + +def main(): + ap = argparse.ArgumentParser( + description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + ap.add_argument("--kotlin-version", required=True, + help="pinned Kotlin/KGP version, e.g. 2.4.21") + ap.add_argument("--agp-version", required=True, + help="pinned AGP version, e.g. 9.4.1") + ap.add_argument("--gradle-cache", + default=os.path.expanduser( + "~/.gradle/caches/modules-2/files-2.1"), + help="Gradle module cache root " + "(default: %(default)s)") + ap.add_argument("--out-dir", default="jars", + help="directory for defs.txt/scan.txt/fallback.txt " + "(default: %(default)s)") + args = ap.parse_args() + cache = args.gradle_cache + if not os.path.isdir(cache): + sys.exit(f"error: Gradle cache not found: {cache}") + + # ---- defs.txt: all org.jetbrains.kotlin jars at the pinned version ---- + defs = [] + missing = [] + for artifact in sorted(os.listdir(os.path.join(cache, KOTLIN_GROUP)) + if os.path.isdir(os.path.join(cache, KOTLIN_GROUP)) + else []): + jars = find_jars(cache, KOTLIN_GROUP, artifact, args.kotlin_version) + if not jars: + continue + defs.extend(jars) + # Sanity-check the core artifacts (we can't know the full expected + # artifact set; these three must be there or the lists are useless). + for core in ("kotlin-compiler-embeddable", "kotlin-gradle-plugin", + "kotlin-stdlib"): + if not find_jars(cache, KOTLIN_GROUP, core, args.kotlin_version): + missing.append(f"{KOTLIN_GROUP}:{core}:{args.kotlin_version}") + defs.sort(key=os.path.basename) + if missing: + sys.exit( + "error: cache is missing " + + ", ".join(missing) + + f"\n run the test_project once with Kotlin {args.kotlin_version} " + "so Gradle downloads the jars, then re-run this script.") + + defs_lines = [ + f"# auto-generated by tools/gen_jar_lists.py - all {KOTLIN_GROUP} " + f"{args.kotlin_version} jars, sorted by jar name.", + "# First jar wins for duplicate class names; the sort keeps " + "kotlin-compiler-* ahead of kotlin-gradle-plugin (which bundles " + "its own copies of some compiler classes - the compiler jar must " + "win, it is what the daemon loads).", + *defs, + ] + + # ---- scan.txt: AGP core jars at the pinned AGP version ---- + scan = [] + missing_scan = [] + for artifact in SCAN_ARTIFACTS: + jars = find_jars(cache, AGP_GROUP, artifact, args.agp_version) + if jars: + scan.extend(jars) + else: + missing_scan.append(f"{AGP_GROUP}:{artifact}:{args.agp_version}") + scan.sort(key=os.path.basename) + if missing_scan: + sys.exit( + "error: cache is missing " + + ", ".join(missing_scan) + + f"\n run the test_project once with AGP {args.agp_version} " + "so Gradle downloads the jars, then re-run this script.") + + scan_lines = [ + f"# auto-generated by tools/gen_jar_lists.py - AGP " + f"{args.agp_version} core jars on the buildscript classpath " + "(the classes AGP uses; seed source for full-closure mode).", + *scan, + ] + + # ---- fallback.txt: KGP family at other versions, newest first ---- + fb = [] + for artifact in FALLBACK_ARTIFACTS: + for v in all_versions(cache, KOTLIN_GROUP, artifact): + if v == args.kotlin_version: + continue + fb.extend((v, j) for j in + find_jars(cache, KOTLIN_GROUP, artifact, v)) + fb.sort(key=lambda t: (t[0], os.path.basename(t[1])), reverse=True) + fb_lines = [ + f"# auto-generated by tools/gen_jar_lists.py - {KOTLIN_GROUP} " + f"KGP-plugin-family jars at other cached versions, newest first. " + f"Definition lookup only (fallback.txt is scanned after defs.txt).", + *(j for _, j in fb), + ] + if not fb: + print("note: no other KGP-plugin versions in cache; " + "fallback.txt will be empty") + + # ---- write ---- + os.makedirs(args.out_dir, exist_ok=True) + write_if_changed(os.path.join(args.out_dir, "defs.txt"), defs_lines) + write_if_changed(os.path.join(args.out_dir, "scan.txt"), scan_lines) + write_if_changed(os.path.join(args.out_dir, "fallback.txt"), fb_lines) + + stamp = os.path.join(args.out_dir, ".stamp") + stamp_content = f"{args.kotlin_version} {args.agp_version}\n" + old = None + if os.path.exists(stamp): + with open(stamp) as fh: + old = fh.read() + if old != stamp_content: + with open(stamp, "w") as fh: + fh.write(stamp_content) + print(f"wrote .stamp ({stamp_content.strip()})") + else: + print("unchanged .stamp") + + +if __name__ == "__main__": + main() -- cgit v1.3.1