48
48
import com .google .devtools .build .lib .packages .Type ;
49
49
import com .google .devtools .build .lib .rules .android .ZipFilterBuilder .CheckHashMismatchMode ;
50
50
import com .google .devtools .build .lib .rules .android .databinding .DataBindingContext ;
51
+ import com .google .devtools .build .lib .rules .android .databinding .DataBindingV2Provider ;
51
52
import com .google .devtools .build .lib .rules .cpp .CcInfo ;
52
53
import com .google .devtools .build .lib .rules .cpp .CcLinkingContext ;
53
54
import com .google .devtools .build .lib .rules .cpp .CcLinkingContext .LinkOptions ;
@@ -438,6 +439,7 @@ public JavaTargetAttributes init(
438
439
boolean addCoverageSupport ,
439
440
boolean collectJavaCompilationArgs ,
440
441
boolean isBinary ,
442
+ boolean shouldCompileJavaSrcs ,
441
443
NestedSet <Artifact > excludedRuntimeArtifacts ,
442
444
boolean generateExtensionRegistry )
443
445
throws InterruptedException , RuleErrorException {
@@ -462,22 +464,26 @@ public JavaTargetAttributes init(
462
464
ImmutableList .Builder <String > javacopts = ImmutableList .builder ();
463
465
javacopts .addAll (androidSemantics .getCompatibleJavacOptions (ruleContext ));
464
466
465
- resourceApk
466
- .asDataBindingContext ()
467
- .supplyJavaCoptsUsing (ruleContext , isBinary , javacopts ::addAll );
467
+ if (shouldCompileJavaSrcs ) {
468
+ resourceApk
469
+ .asDataBindingContext ()
470
+ .supplyJavaCoptsUsing (ruleContext , isBinary , javacopts ::addAll );
471
+ }
468
472
JavaTargetAttributes .Builder attributesBuilder =
469
473
javaCommon
470
474
.initCommon (idlHelper .getIdlGeneratedJavaSources (), javacopts .build ())
471
475
.setBootClassPath (bootClassPathInfo );
472
476
473
- resourceApk
474
- .asDataBindingContext ()
475
- .supplyAnnotationProcessor (
476
- ruleContext ,
477
- (plugin , additionalOutputs ) -> {
478
- attributesBuilder .addPlugin (plugin );
479
- attributesBuilder .addAdditionalOutputs (additionalOutputs );
480
- });
477
+ if (shouldCompileJavaSrcs ) {
478
+ resourceApk
479
+ .asDataBindingContext ()
480
+ .supplyAnnotationProcessor (
481
+ ruleContext ,
482
+ (plugin , additionalOutputs ) -> {
483
+ attributesBuilder .addPlugin (plugin );
484
+ attributesBuilder .addAdditionalOutputs (additionalOutputs );
485
+ });
486
+ }
481
487
482
488
if (excludedRuntimeArtifacts != null ) {
483
489
attributesBuilder .addExcludedArtifacts (excludedRuntimeArtifacts );
@@ -505,9 +511,19 @@ public JavaTargetAttributes init(
505
511
jarsProducedForRuntime .add (resourceApk .getResourceJavaClassJar ());
506
512
}
507
513
508
- // Databinding metadata that the databinding annotation processor reads.
509
- ImmutableList <Artifact > additionalJavaInputsFromDatabinding =
510
- resourceApk .asDataBindingContext ().processDeps (ruleContext , isBinary );
514
+ ImmutableList <Artifact > additionalJavaInputsFromDatabinding = null ;
515
+ if (shouldCompileJavaSrcs ) {
516
+ // Databinding metadata that the databinding annotation processor reads.
517
+ additionalJavaInputsFromDatabinding =
518
+ resourceApk .asDataBindingContext ().processDeps (ruleContext , isBinary );
519
+ } else {
520
+ ImmutableList .Builder <Artifact > outputs = ImmutableList .<Artifact >builder ();
521
+ DataBindingV2Provider p =
522
+ ruleContext .getPrerequisite ("application_resources" , DataBindingV2Provider .PROVIDER );
523
+ outputs .addAll (p .getSetterStores ());
524
+ outputs .addAll (p .getTransitiveBRFiles ().toList ());
525
+ additionalJavaInputsFromDatabinding = outputs .build ();
526
+ }
511
527
512
528
JavaCompilationHelper helper =
513
529
initAttributes (attributesBuilder , javaSemantics , additionalJavaInputsFromDatabinding );
0 commit comments