facebook / buck

A fast build system that encourages the creation of small, reusable modules over a variety of platforms and languages.
https://buck.build
Apache License 2.0
8.56k stars 1.16k forks source link

Confusion around kapt's generated option #1891

Open ZacSweers opened 6 years ago

ZacSweers commented 6 years ago

Trying to use Moshi's new Kotlin code gen feature, it seems that while the processor runs, the code it generates is going into a black hole somewhere.

It uses kapt's generated option to know where to generate code. In gradle, this ends up roughly in $buildDir/generated/source/kaptKotlin/main. For kotlin, this seems to go nowhere. Not sure if the option just isn't being set or what.

Option is normally accessed via processingEnv.options["kapt.kotlin.generated"]

See: https://kotlinlang.org/docs/reference/kapt.html#generating-kotlin-sources

ZacSweers commented 6 years ago

CC @tyvsmith @kageiit

ZacSweers commented 6 years ago

I do see it wired in

https://github.com/facebook/buck/blob/06ecade50006cfb4b0a5e63a04eea0d63792b91c/src/com/facebook/buck/jvm/kotlin/KotlincToJarStepFactory.java#L88

https://github.com/facebook/buck/blob/06ecade50006cfb4b0a5e63a04eea0d63792b91c/src/com/facebook/buck/jvm/kotlin/KotlincToJarStepFactory.java#L137-L138

And those directories are getting generated, but there's no output in them

ZacSweers commented 6 years ago

After some grep magic, I'm seeing them, but in really random places

If I have a project under /libraries/foundation/modelgen/thrift-utilities

they end up duplicated in several places, and none of them are linked in buck project

./buck-out/gen/libraries/foundation/modelgen/thrifty-utilities/lib__src_main____working_directory/com/uber/thrifty/ThriftFieldJsonAdapter.kt
./buck-out/annotation/libraries/foundation/modelgen/thrifty-utilities/__src_main_kapt_generated__/com/uber/thrifty/ThriftFieldJsonAdapter.kt
./buck-out/bin/libraries/foundation/modelgen/thrifty-utilities/__src_main_gen_sources__/com/uber/thrifty/ThriftFieldJsonAdapter.kt
./build/buildScript/project-build/libraries/foundation/modelgen/thrifty-utilities/build/generated/source/kaptKotlin/main/com/uber/thrifty/ThriftFieldJsonAdapter.kt
./build/buildScript2/project-build/libraries/foundation/modelgen/thrifty-utilities/build/generated/source/kaptKotlin/main/com/uber/thrifty/ThriftFieldJsonAdapter.kt

Does this imply the processor is being invoked multiple times with different output locations?

ZacSweers commented 6 years ago

One of them does appear on the classpath, but not sure how to see which

ZacSweers commented 6 years ago

CC @thalescm

thalescm commented 6 years ago

Hey @hzsweers , Kapt can pottentially generate stuff in three different directories: kapt.kotlin.generated option path, which kotlin APs should point out to. sources, which is normally where java APs output appears classes, if you're generating class or resources files Check more out here.

What happens on buck is that kapt has four steps for running (decribed in the link). But you can not know for sure, while on buck, if it will, or will not generate anything.

We should probably delete both files at annotation and bin directories at the and of the step, would be cleaner. To make IDE see the files generated by buck kapt, you could add a config for gradle that src files contain buck-out/path/to/your/project/gen/kapt. The other two paths where they appear are gradle outputs.

Hopefully that cleared how the flow works, but anything else please ask. Answering the final question, that doesn't mean the processor is being called multiple times. But it does indicate you're running kapt both with buck and with gradle.

ZacSweers commented 6 years ago

Agreed on deleting being the best path forward to clear up confusion. Will try the gradle config (I'm a bit worried we'd have to end up pointing somewhere in buck-out), but shouldn't buck project pick this up correctly in native buck?

thalescm commented 6 years ago

You mean a buck project in the AS? I don't think so, don't know and I'm not that familiar to how buck will generate the project files. But when implementing kapt I didn't touched on that part, so probably the IDE won't recognize those files for autocomplete and etc... Probably a good idea the create an issue specific for that, if that's the case

ZacSweers commented 5 years ago

Hey - it would be great if someone from the buck team could acknowledge this. It's a major blocker for kotlin-first annotation processors