rules_kotlin icon indicating copy to clipboard operation
rules_kotlin copied to clipboard

Crash with data binding and annotation processor

Open pswaminathan opened this issue 4 years ago • 1 comments

Sample project found at https://github.com/pswaminathan/bazel-kt-databinding-crash

If you build this project as-is, you'll get a Bazel crash:

$ bazel build //...
Starting local Bazel server and connecting to it...
Analyzing: 6 targets (49 packages loaded, 975 targets configured)
    Fetching @remotejdk11_macos_aarch64; fetching
    Fetching ...cos_aarch64; Extracting /private/var/tmp/_bazel_p/a48d838470da09ddcc3c8b96c3b3efad/external/remotejdk11_macos_aarch64/temp9776662442558441540/zulu11.45.27-ca-jdk11.0.10-macosx_aarch64.tar.gz
FATAL: bazel crashed due to an internal error. Printing stack trace:
java.lang.RuntimeException: Unrecoverable error while evaluating node 'ConfiguredTargetKey{label=//:app_lib_base, config=BuildConfigurationValue.Key[1054a2250c4245b865962919778764c4f205786ff7dd6c61ef877b456d4f1e39]}' (requested by nodes 'ConfiguredTargetKey{label=//:app_lib, config=BuildConfigurationValue.Key[1054a2250c4245b865962919778764c4f205786ff7dd6c61ef877b456d4f1e39]}', 'ConfiguredTargetKey{label=//:app_lib_kt, config=BuildConfigurationValue.Key[1054a2250c4245b865962919778764c4f205786ff7dd6c61ef877b456d4f1e39]}')
	at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:563)
	at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:398)
	at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(Unknown Source)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)
	at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)
Caused by: java.lang.NullPointerException
	at com.google.devtools.build.lib.rules.java.JavaCompilationHelper.usesAnnotationProcessing(JavaCompilationHelper.java:530)
	at com.google.devtools.build.lib.rules.java.JavaCompilationHelper.createOutputs(JavaCompilationHelper.java:187)
	at com.google.devtools.build.lib.rules.android.AndroidCommon.initJava(AndroidCommon.java:580)
	at com.google.devtools.build.lib.rules.android.AndroidCommon.init(AndroidCommon.java:517)
	at com.google.devtools.build.lib.rules.android.AndroidLibrary.create(AndroidLibrary.java:196)
	at com.google.devtools.build.lib.rules.android.AndroidLibrary.create(AndroidLibrary.java:41)
	at com.google.devtools.build.lib.analysis.ConfiguredTargetFactory.createRule(ConfiguredTargetFactory.java:385)
	at com.google.devtools.build.lib.analysis.ConfiguredTargetFactory.createConfiguredTarget(ConfiguredTargetFactory.java:195)
	at com.google.devtools.build.lib.skyframe.SkyframeBuildView.createConfiguredTarget(SkyframeBuildView.java:940)
	at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.createConfiguredTarget(ConfiguredTargetFunction.java:1031)
	at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.compute(ConfiguredTargetFunction.java:371)
	at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:477)
	... 7 more

If you comment out the enable_data_binding = True lines, you no longer get a Bazel crash, but the project of course doesn't build.

pswaminathan avatar Dec 10 '21 19:12 pswaminathan

I think this is not related to Kotlin rules at the moment.

Databinding requires few additional config to successfully compile, I have just created https://github.com/pswaminathan/bazel-kt-databinding-crash/pull/1 in which the app can be successfully built.

The only exception is supporting @BindingAdapters written in Kotlin as described here. We have implemented a solution that helps solve the problem by translating Kotlin to Java files during build but that is just a band-aid and does not address the root problem i.e Bazel's databinding annotation processor is coupled inside Bazel's android_tools hence can't be run on *.kt files. Our motivation for building this to support same project structure as Gradle.

@restingbull Do you suppose we can track @BindingAdapter Kotlin support can be tracked in a separate issue? From my understanding android.databinding.annotationprocessor.ProcessDataBinding also requires couple of arguments and it is setup as part of native resourcing flow. Maybe once Starlark APIs for resource processing is available, it could be built as part of rules_koltin and kt_android_library.

That being said, @BindingAdapter in Java works and this might be only an issue when folks migrate from Gradle project structure to Bazel.

arunkumar9t2 avatar Dec 11 '21 08:12 arunkumar9t2