google / ksp

Kotlin Symbol Processing API
https://github.com/google/ksp
Apache License 2.0
2.89k stars 274 forks source link

Support generated JVM bytecode #95

Closed ting-yuan closed 3 years ago

ting-yuan commented 4 years ago

While KSP doesn't have any facility to support generating bytecode, it should pick up bytecode generated solely by processors and add them to compile classpath, so as to participate in later compilation.

ZacSweers commented 4 years ago

Put up a prototype to test with here: https://github.com/ZacSweers/MoshiX/pull/43

ting-yuan commented 4 years ago

Fixed in #138.

ZacSweers commented 4 years ago

I don't think this is resolved. I updated my bytecode generation branch linked above, and while the classes themselves do get generated, they don't link at compile-time

e: /Users/zsweers/dev/kotlin/personal/moshi-sealed/moshi-ksp/tests/build/generated/ksp/src/test/kotlin/dev/zacsweers/moshix/ksp/codegen/UntypedNestedPersonResponseJsonAdapter.kt: (83, 63): Cannot access class 'dev.zacsweers.moshix.ksp.codegen.UntypedNestedPersonResponse'. Check your module classpath for missing or conflicting dependencies
e: /Users/zsweers/dev/kotlin/personal/moshi-sealed/moshi-ksp/tests/build/generated/ksp/src/test/kotlin/dev/zacsweers/moshix/ksp/codegen/UntypedNestedPersonResponseJsonAdapter.kt: (87, 5): Cannot access class 'dev.zacsweers.moshix.ksp.codegen.UntypedNestedPersonResponse'. Check your module classpath for missing or conflicting dependencies
e: /Users/zsweers/dev/kotlin/personal/moshi-sealed/moshi-ksp/tests/build/generated/ksp/src/test/kotlin/dev/zacsweers/moshix/ksp/codegen/UntypedNestedPersonResponseJsonAdapter.kt: (87, 12): Unresolved reference: `data`
e: /Users/zsweers/dev/kotlin/personal/moshi-sealed/moshi-ksp/tests/build/generated/ksp/src/test/kotlin/dev/zacsweers/moshix/ksp/codegen/UntypedNestedPersonResponseJsonAdapter.kt: (87, 45): Cannot access class 'dev.zacsweers.moshix.ksp.codegen.UntypedNestedPersonResponse'. Check your module classpath for missing or conflicting dependencies
e: /Users/zsweers/dev/kotlin/personal/moshi-sealed/moshi-ksp/tests/build/generated/ksp/src/test/kotlin/dev/zacsweers/moshix/ksp/codegen/UntypedNestedPersonResponseJsonAdapter.kt: (87, 52): Unresolved reference: `data`
e: /Users/zsweers/dev/kotlin/personal/moshi-sealed/moshi-ksp/tests/build/generated/ksp/src/test/kotlin/dev/zacsweers/moshix/ksp/codegen/UntypedNestedPersonResponseJsonAdapter.kt: (88, 5): Cannot access class 'dev.zacsweers.moshix.ksp.codegen.UntypedNestedPersonResponse'. Check your module classpath for missing or conflicting dependencies
e: /Users/zsweers/dev/kotlin/personal/moshi-sealed/moshi-ksp/tests/build/generated/ksp/src/test/kotlin/dev/zacsweers/moshix/ksp/codegen/UntypedNestedPersonResponseJsonAdapter.kt: (88, 12): Unresolved reference: data2
e: /Users/zsweers/dev/kotlin/personal/moshi-sealed/moshi-ksp/tests/build/generated/ksp/src/test/kotlin/dev/zacsweers/moshix/ksp/codegen/UntypedNestedPersonResponseJsonAdapter.kt: (88, 45): Cannot access class 'dev.zacsweers.moshix.ksp.codegen.UntypedNestedPersonResponse'. Check your module classpath for missing or conflicting dependencies
e: /Users/zsweers/dev/kotlin/personal/moshi-sealed/moshi-ksp/tests/build/generated/ksp/src/test/kotlin/dev/zacsweers/moshix/ksp/codegen/UntypedNestedPersonResponseJsonAdapter.kt: (88, 52): Unresolved reference: data2
e: /Users/zsweers/dev/kotlin/personal/moshi-sealed/moshi-ksp/tests/build/generated/ksp/src/test/kotlin/dev/zacsweers/moshix/ksp/codegen/UntypedNestedPersonResponseJsonAdapter.kt: (89, 5): Cannot access class 'dev.zacsweers.moshix.ksp.codegen.UntypedNestedPersonResponse'. Check your module classpath for missing or conflicting dependencies
e: /Users/zsweers/dev/kotlin/personal/moshi-sealed/moshi-ksp/tests/build/generated/ksp/src/test/kotlin/dev/zacsweers/moshix/ksp/codegen/UntypedNestedPersonResponseJsonAdapter.kt: (89, 12): Unresolved reference: data3
e: /Users/zsweers/dev/kotlin/personal/moshi-sealed/moshi-ksp/tests/build/generated/ksp/src/test/kotlin/dev/zacsweers/moshix/ksp/codegen/UntypedNestedPersonResponseJsonAdapter.kt: (89, 45): Cannot access class 'dev.zacsweers.moshix.ksp.codegen.UntypedNestedPersonResponse'. Check your module classpath for missing or conflicting dependencies
e: /Users/zsweers/dev/kotlin/personal/moshi-sealed/moshi-ksp/tests/build/generated/ksp/src/test/kotlin/dev/zacsweers/moshix/ksp/codegen/UntypedNestedPersonResponseJsonAdapter.kt: (89, 52): Unresolved reference: data3
e: /Users/zsweers/dev/kotlin/personal/moshi-sealed/moshi-ksp/tests/build/generated/ksp/src/test/kotlin/dev/zacsweers/moshix/ksp/codegen/UntypedNestedPersonResponseJsonAdapter.kt: (90, 12): Cannot access class 'dev.zacsweers.moshix.ksp.codegen.UntypedNestedPersonResponse'. Check your module classpath for missing or conflicting dependencies
e: /Users/zsweers/dev/kotlin/personal/moshi-sealed/moshi-ksp/tests/build/generated/ksp/src/test/kotlin/dev/zacsweers/moshix/ksp/codegen/UntypedNestedPersonResponseJsonAdapter.kt: (90, 12): Type mismatch: inferred type is UntypedNestedPersonResponse! but UntypedNestedPersonResponse<T> was expected

image

image

ZacSweers commented 4 months ago

Trying to revisit this in github.com/square/moshi and finding the above remains an issue. I'm also finding that KSP2 completely doesn't link generated code against class files, let alone class files against source files.

ZacSweers commented 4 months ago

Reference where I've been working on this https://github.com/square/moshi/pull/1858. You can reproduce it there by running the JsonClassSymbolProcessorTest tests. Note I'm able to reproduce this in both the kotlin-compile-testing programmatic runner as well as in Gradle (if you run the DualKotlinTest file with KSP mode enabled in that subproject's build)