use of com.google.devtools.build.lib.rules.java.JavaTargetAttributes in project bazel by bazelbuild.
the class AndroidBinary method init.
private static RuleConfiguredTargetBuilder init(RuleContext ruleContext, NestedSetBuilder<Artifact> filesBuilder, ResourceDependencies resourceDeps, JavaCommon javaCommon, AndroidCommon androidCommon, JavaSemantics javaSemantics, AndroidSemantics androidSemantics) throws InterruptedException, RuleErrorException {
validateRuleContext(ruleContext);
// TODO(bazel-team): Find a way to simplify this code.
// treeKeys() means that the resulting map sorts the entries by key, which is necessary to
// ensure determinism.
Multimap<String, TransitiveInfoCollection> depsByArchitecture = MultimapBuilder.treeKeys().arrayListValues().build();
AndroidConfiguration androidConfig = ruleContext.getFragment(AndroidConfiguration.class);
for (Map.Entry<Optional<String>, ? extends List<? extends TransitiveInfoCollection>> entry : ruleContext.getSplitPrerequisites("deps").entrySet()) {
String cpu = entry.getKey().or(androidConfig.getCpu());
depsByArchitecture.putAll(cpu, entry.getValue());
}
Map<String, BuildConfiguration> configurationMap = new LinkedHashMap<>();
Map<String, CcToolchainProvider> toolchainMap = new LinkedHashMap<>();
for (Map.Entry<Optional<String>, ? extends List<? extends TransitiveInfoCollection>> entry : ruleContext.getSplitPrerequisites(":cc_toolchain_split").entrySet()) {
String cpu = entry.getKey().or(androidConfig.getCpu());
TransitiveInfoCollection dep = Iterables.getOnlyElement(entry.getValue());
CcToolchainProvider toolchain = CppHelper.getToolchain(ruleContext, dep);
configurationMap.put(cpu, dep.getConfiguration());
toolchainMap.put(cpu, toolchain);
}
NativeLibs nativeLibs = NativeLibs.fromLinkedNativeDeps(ruleContext, androidSemantics.getNativeDepsFileName(), depsByArchitecture, toolchainMap, configurationMap);
// TODO(bazel-team): Resolve all the different cases of resource handling so this conditional
// can go away: recompile from android_resources, and recompile from android_binary attributes.
ApplicationManifest applicationManifest;
ResourceApk resourceApk;
ResourceApk incrementalResourceApk;
ResourceApk instantRunResourceApk;
ResourceApk splitResourceApk;
if (LocalResourceContainer.definesAndroidResources(ruleContext.attributes())) {
// Retrieve and compile the resources defined on the android_binary rule.
LocalResourceContainer.validateRuleContext(ruleContext);
ApplicationManifest ruleManifest = androidSemantics.getManifestForRule(ruleContext);
applicationManifest = ruleManifest.mergeWith(ruleContext, resourceDeps);
resourceApk = applicationManifest.packWithDataAndResources(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_APK), ruleContext, false, /* isLibrary */
resourceDeps, ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_R_TXT), null, /* Artifact symbolsTxt */
ResourceConfigurationFilter.fromRuleContext(ruleContext), ruleContext.getTokenizedStringListAttr("nocompress_extensions"), ruleContext.attributes().get("crunch_png", Type.BOOLEAN), ruleContext.getTokenizedStringListAttr("densities"), false, /* incremental */
ProguardHelper.getProguardConfigArtifact(ruleContext, ""), createMainDexProguardSpec(ruleContext), ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_PROCESSED_MANIFEST), ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_ZIP), DataBinding.isEnabled(ruleContext) ? DataBinding.getLayoutInfoFile(ruleContext) : null);
ruleContext.assertNoErrors();
incrementalResourceApk = applicationManifest.addMobileInstallStubApplication(ruleContext).packWithDataAndResources(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_INCREMENTAL_RESOURCES_APK), ruleContext, false, /* isLibrary */
resourceDeps, null, /* Artifact rTxt */
null, /* Artifact symbolsTxt */
ResourceConfigurationFilter.fromRuleContext(ruleContext), ruleContext.getTokenizedStringListAttr("nocompress_extensions"), ruleContext.attributes().get("crunch_png", Type.BOOLEAN), ruleContext.getTokenizedStringListAttr("densities"), true, /* incremental */
ProguardHelper.getProguardConfigArtifact(ruleContext, "incremental"), null, /* mainDexProguardCfg */
null, /* manifestOut */
null, /* mergedResourcesOut */
null);
ruleContext.assertNoErrors();
instantRunResourceApk = applicationManifest.addInstantRunStubApplication(ruleContext).packWithDataAndResources(getDxArtifact(ruleContext, "android_instant_run.ap_"), ruleContext, false, /* isLibrary */
resourceDeps, null, /* Artifact rTxt */
null, /* Artifact symbolsTxt */
ResourceConfigurationFilter.fromRuleContext(ruleContext), ruleContext.getTokenizedStringListAttr("nocompress_extensions"), ruleContext.attributes().get("crunch_png", Type.BOOLEAN), ruleContext.getTokenizedStringListAttr("densities"), true, /* incremental */
ProguardHelper.getProguardConfigArtifact(ruleContext, "instant_run"), null, /* mainDexProguardCfg */
null, /* manifestOut */
null, /* mergedResourcesOut */
null);
ruleContext.assertNoErrors();
splitResourceApk = applicationManifest.createSplitManifest(ruleContext, "android_resources", false).packWithDataAndResources(getDxArtifact(ruleContext, "android_resources.ap_"), ruleContext, false, /* isLibrary */
resourceDeps, null, /* Artifact rTxt */
null, /* Artifact symbolsTxt */
ResourceConfigurationFilter.fromRuleContext(ruleContext), ruleContext.getTokenizedStringListAttr("nocompress_extensions"), ruleContext.attributes().get("crunch_png", Type.BOOLEAN), ruleContext.getTokenizedStringListAttr("densities"), true, /* incremental */
ProguardHelper.getProguardConfigArtifact(ruleContext, "incremental_split"), null, /* mainDexProguardCfg */
null, /* manifestOut */
null, /* mergedResourcesOut */
null);
ruleContext.assertNoErrors();
} else {
if (!ruleContext.attributes().get("crunch_png", Type.BOOLEAN)) {
ruleContext.throwWithRuleError("Setting crunch_png = 0 is not supported for android_binary" + " rules which depend on android_resources rules.");
}
// Retrieve the resources from the resources attribute on the android_binary rule
// and recompile them if necessary.
ApplicationManifest resourcesManifest = ApplicationManifest.fromResourcesRule(ruleContext);
if (resourcesManifest == null) {
throw new RuleErrorException();
}
applicationManifest = resourcesManifest.mergeWith(ruleContext, resourceDeps);
// Always recompiling resources causes AndroidTest to fail in certain circumstances.
if (shouldRegenerate(ruleContext, resourceDeps)) {
resourceApk = applicationManifest.packWithResources(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_APK), ruleContext, resourceDeps, true, /* createSource */
ProguardHelper.getProguardConfigArtifact(ruleContext, ""), createMainDexProguardSpec(ruleContext));
ruleContext.assertNoErrors();
} else {
resourceApk = applicationManifest.useCurrentResources(ruleContext, ProguardHelper.getProguardConfigArtifact(ruleContext, ""), createMainDexProguardSpec(ruleContext));
ruleContext.assertNoErrors();
}
incrementalResourceApk = applicationManifest.addMobileInstallStubApplication(ruleContext).packWithResources(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_INCREMENTAL_RESOURCES_APK), ruleContext, resourceDeps, false, /* createSource */
ProguardHelper.getProguardConfigArtifact(ruleContext, "incremental"), null);
ruleContext.assertNoErrors();
instantRunResourceApk = applicationManifest.addInstantRunStubApplication(ruleContext).packWithResources(getDxArtifact(ruleContext, "android_instant_run.ap_"), ruleContext, resourceDeps, false, /* createSource */
ProguardHelper.getProguardConfigArtifact(ruleContext, "instant_run"), null);
ruleContext.assertNoErrors();
splitResourceApk = applicationManifest.createSplitManifest(ruleContext, "android_resources", false).packWithResources(getDxArtifact(ruleContext, "android_resources.ap_"), ruleContext, resourceDeps, false, /* createSource */
ProguardHelper.getProguardConfigArtifact(ruleContext, "incremental_split"), null);
ruleContext.assertNoErrors();
}
boolean shrinkResources = shouldShrinkResources(ruleContext);
JavaTargetAttributes resourceClasses = androidCommon.init(javaSemantics, androidSemantics, resourceApk, ruleContext.getConfiguration().isCodeCoverageEnabled(), true, /* collectJavaCompilationArgs */
true);
ruleContext.assertNoErrors();
Function<Artifact, Artifact> derivedJarFunction = collectDesugaredJars(ruleContext, androidCommon, androidSemantics, resourceClasses);
Artifact deployJar = createDeployJar(ruleContext, javaSemantics, androidCommon, resourceClasses, derivedJarFunction);
Artifact proguardMapping = ruleContext.getPrerequisiteArtifact("proguard_apply_mapping", Mode.TARGET);
return createAndroidBinary(ruleContext, filesBuilder, deployJar, derivedJarFunction, /* isBinaryJarFiltered */
false, javaCommon, androidCommon, javaSemantics, androidSemantics, nativeLibs, applicationManifest, resourceApk, incrementalResourceApk, instantRunResourceApk, splitResourceApk, shrinkResources, resourceClasses, ImmutableList.<Artifact>of(), ImmutableList.<Artifact>of(), proguardMapping);
}
use of com.google.devtools.build.lib.rules.java.JavaTargetAttributes in project bazel by bazelbuild.
the class AndroidCommon method initJava.
private void initJava(JavaSemantics javaSemantics, JavaCompilationHelper helper, JavaCompilationArtifacts.Builder javaArtifactsBuilder, boolean collectJavaCompilationArgs, NestedSetBuilder<Artifact> filesBuilder, boolean isBinary) throws InterruptedException {
JavaTargetAttributes attributes = helper.getAttributes();
if (ruleContext.hasErrors()) {
// Avoid leaving filesToBuild set to null, otherwise we'll get a NullPointerException masking
// the real error.
filesToBuild = filesBuilder.build();
return;
}
Artifact jar = null;
if (attributes.hasSourceFiles() || attributes.hasSourceJars() || attributes.hasResources()) {
// We only want to add a jar to the classpath of a dependent rule if it has content.
javaArtifactsBuilder.addRuntimeJar(classJar);
jar = classJar;
}
filesBuilder.add(classJar);
manifestProtoOutput = helper.createManifestProtoOutput(classJar);
// it is null, and the source jar action will not depend on the compile action.
if (helper.usesAnnotationProcessing()) {
genClassJar = helper.createGenJar(classJar);
genSourceJar = helper.createGensrcJar(classJar);
helper.createGenJarAction(classJar, manifestProtoOutput, genClassJar);
}
srcJar = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_LIBRARY_SOURCE_JAR);
javaSourceJarsProviderBuilder.addSourceJar(srcJar).addAllTransitiveSourceJars(javaCommon.collectTransitiveSourceJars(srcJar));
helper.createSourceJarAction(srcJar, genSourceJar);
outputDepsProto = helper.createOutputDepsProtoArtifact(classJar, javaArtifactsBuilder);
helper.createCompileActionWithInstrumentation(classJar, manifestProtoOutput, genSourceJar, outputDepsProto, javaArtifactsBuilder);
if (isBinary) {
generatedExtensionRegistryProvider = javaSemantics.createGeneratedExtensionRegistry(ruleContext, javaCommon, filesBuilder, javaArtifactsBuilder, javaRuleOutputJarsProviderBuilder, javaSourceJarsProviderBuilder);
}
filesToBuild = filesBuilder.build();
if ((attributes.hasSourceFiles() || attributes.hasSourceJars()) && jar != null) {
iJar = helper.createCompileTimeJarAction(jar, javaArtifactsBuilder);
}
JavaCompilationArtifacts javaArtifacts = javaArtifactsBuilder.build();
compileTimeDependencyArtifacts = javaCommon.collectCompileTimeDependencyArtifacts(javaArtifacts.getCompileTimeDependencyArtifact());
javaCommon.setJavaCompilationArtifacts(javaArtifacts);
javaCommon.setClassPathFragment(new ClasspathConfiguredFragment(javaCommon.getJavaCompilationArtifacts(), attributes, asNeverLink, helper.getBootclasspathOrDefault()));
transitiveNeverlinkLibraries = collectTransitiveNeverlinkLibraries(ruleContext, javaCommon.getDependencies(), javaCommon.getJavaCompilationArtifacts().getRuntimeJars());
if (collectJavaCompilationArgs) {
boolean hasSources = attributes.hasSourceFiles() || attributes.hasSourceJars();
this.javaCompilationArgs = collectJavaCompilationArgs(exportDeps, asNeverLink, hasSources);
this.recursiveJavaCompilationArgs = collectJavaCompilationArgs(true, asNeverLink, /* hasSources */
true);
}
}
use of com.google.devtools.build.lib.rules.java.JavaTargetAttributes in project bazel by bazelbuild.
the class AndroidLibrary method create.
@Override
public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
validateRuleContext(ruleContext);
JavaSemantics javaSemantics = createJavaSemantics();
AndroidSemantics androidSemantics = createAndroidSemantics();
if (!AndroidSdkProvider.verifyPresence(ruleContext)) {
return null;
}
checkResourceInlining(ruleContext);
NestedSetBuilder<Aar> transitiveAars = collectTransitiveAars(ruleContext);
NestedSetBuilder<Artifact> proguardConfigsbuilder = NestedSetBuilder.stableOrder();
proguardConfigsbuilder.addTransitive(new ProguardLibrary(ruleContext).collectProguardSpecs());
AndroidIdlHelper.addSupportLibProguardConfigs(ruleContext, proguardConfigsbuilder);
NestedSet<Artifact> transitiveProguardConfigs = proguardConfigsbuilder.build();
JavaCommon javaCommon = AndroidCommon.createJavaCommonWithAndroidDataBinding(ruleContext, javaSemantics, true);
javaSemantics.checkRule(ruleContext, javaCommon);
AndroidCommon androidCommon = new AndroidCommon(javaCommon);
boolean definesLocalResources = LocalResourceContainer.definesAndroidResources(ruleContext.attributes());
if (definesLocalResources) {
LocalResourceContainer.validateRuleContext(ruleContext);
}
final ResourceApk resourceApk;
if (definesLocalResources) {
ApplicationManifest applicationManifest = androidSemantics.getManifestForRule(ruleContext).renamePackage(ruleContext, AndroidCommon.getJavaPackage(ruleContext));
resourceApk = applicationManifest.packWithDataAndResources(null, /* resourceApk -- not needed for library */
ruleContext, true, /* isLibrary */
ResourceDependencies.fromRuleDeps(ruleContext, JavaCommon.isNeverLink(ruleContext)), ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_R_TXT), ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_SYMBOLS), ResourceConfigurationFilter.empty(ruleContext), ImmutableList.<String>of(), /* uncompressedExtensions */
false, /* crunchPng */
ImmutableList.<String>of(), /* densities */
false, /* incremental */
null, /* proguardCfgOut */
null, /* mainDexProguardCfg */
ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_PROCESSED_MANIFEST), ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_ZIP), DataBinding.isEnabled(ruleContext) ? DataBinding.getLayoutInfoFile(ruleContext) : null);
if (ruleContext.hasErrors()) {
return null;
}
} else {
resourceApk = ResourceApk.fromTransitiveResources(ResourceDependencies.fromRuleResourceAndDeps(ruleContext, false));
}
if (!ruleContext.getFragment(AndroidConfiguration.class).allowSrcsLessAndroidLibraryDeps() && !definesLocalResources && ruleContext.attributes().get("srcs", BuildType.LABEL_LIST).isEmpty() && ruleContext.attributes().get("idl_srcs", BuildType.LABEL_LIST).isEmpty() && !ruleContext.attributes().get("deps", BuildType.LABEL_LIST).isEmpty()) {
ruleContext.attributeError("deps", "deps not allowed without srcs; move to exports?");
}
JavaTargetAttributes javaTargetAttributes = androidCommon.init(javaSemantics, androidSemantics, resourceApk, false, /* addCoverageSupport */
true, /* collectJavaCompilationArgs */
false);
if (javaTargetAttributes == null) {
return null;
}
Artifact classesJar = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_LIBRARY_CLASS_JAR);
Artifact aarOut = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_LIBRARY_AAR);
final ResourceContainer primaryResources;
final Aar aar;
if (definesLocalResources) {
primaryResources = resourceApk.getPrimaryResource();
// applicationManifest has already been checked for nullness above in this method
ApplicationManifest applicationManifest = androidSemantics.getManifestForRule(ruleContext);
aar = Aar.create(aarOut, applicationManifest.getManifest());
transitiveAars.add(aar);
} else if (AndroidCommon.getAndroidResources(ruleContext) != null) {
primaryResources = Iterables.getOnlyElement(AndroidCommon.getAndroidResources(ruleContext).getDirectAndroidResources());
aar = Aar.create(aarOut, primaryResources.getManifest());
transitiveAars.add(aar);
} else {
// there are no local resources and resources attribute was not specified either
aar = null;
ApplicationManifest applicationManifest = ApplicationManifest.generatedManifest(ruleContext).renamePackage(ruleContext, AndroidCommon.getJavaPackage(ruleContext));
String javaPackage = AndroidCommon.getJavaPackage(ruleContext);
ResourceContainer resourceContainer = ResourceContainer.builder().setLabel(ruleContext.getLabel()).setJavaPackageFromString(javaPackage).setManifest(applicationManifest.getManifest()).setJavaSourceJar(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_JAVA_SOURCE_JAR)).setManifestExported(ruleContext.attributes().get("exports_manifest", Type.BOOLEAN)).setRTxt(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_R_TXT)).build();
primaryResources = new AndroidResourcesProcessorBuilder(ruleContext).setLibrary(true).setRTxtOut(resourceContainer.getRTxt()).setManifestOut(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_PROCESSED_MANIFEST)).setSourceJarOut(resourceContainer.getJavaSourceJar()).setJavaPackage(resourceContainer.getJavaPackage()).withPrimary(resourceContainer).withDependencies(resourceApk.getResourceDependencies()).setDebug(ruleContext.getConfiguration().getCompilationMode() != CompilationMode.OPT).build(ruleContext);
}
new AarGeneratorBuilder(ruleContext).withPrimary(primaryResources).withManifest(aar != null ? aar.getManifest() : primaryResources.getManifest()).withRtxt(primaryResources.getRTxt()).withClasses(classesJar).setAAROut(aarOut).build(ruleContext);
RuleConfiguredTargetBuilder builder = new RuleConfiguredTargetBuilder(ruleContext);
androidCommon.addTransitiveInfoProviders(builder, androidSemantics, aarOut, resourceApk, null, ImmutableList.<Artifact>of());
androidSemantics.addTransitiveInfoProviders(builder, ruleContext, javaCommon, androidCommon, null);
NestedSetBuilder<Artifact> transitiveResourcesJars = collectTransitiveResourceJars(ruleContext);
if (androidCommon.getResourceClassJar() != null) {
transitiveResourcesJars.add(androidCommon.getResourceClassJar());
}
builder.addProvider(NativeLibsZipsProvider.class, new NativeLibsZipsProvider(AndroidCommon.collectTransitiveNativeLibsZips(ruleContext).build())).add(JavaNeverlinkInfoProvider.class, new JavaNeverlinkInfoProvider(androidCommon.isNeverLink())).add(JavaSourceInfoProvider.class, JavaSourceInfoProvider.fromJavaTargetAttributes(javaTargetAttributes, javaSemantics)).add(AndroidCcLinkParamsProvider.class, AndroidCcLinkParamsProvider.create(androidCommon.getCcLinkParamsStore())).add(JavaPluginInfoProvider.class, JavaCommon.getTransitivePlugins(ruleContext)).add(ProguardSpecProvider.class, new ProguardSpecProvider(transitiveProguardConfigs)).addOutputGroup(OutputGroupProvider.HIDDEN_TOP_LEVEL, transitiveProguardConfigs).add(AndroidLibraryResourceClassJarProvider.class, AndroidLibraryResourceClassJarProvider.create(transitiveResourcesJars.build()));
if (!JavaCommon.isNeverLink(ruleContext)) {
builder.add(AndroidLibraryAarProvider.class, AndroidLibraryAarProvider.create(aar, transitiveAars.build()));
}
return builder.build();
}
use of com.google.devtools.build.lib.rules.java.JavaTargetAttributes in project bazel by bazelbuild.
the class AndroidBinary method getStubDex.
private static Artifact getStubDex(RuleContext ruleContext, JavaSemantics javaSemantics, boolean split) throws InterruptedException {
String attribute = split ? "$incremental_split_stub_application" : "$incremental_stub_application";
TransitiveInfoCollection dep = ruleContext.getPrerequisite(attribute, Mode.TARGET);
if (dep == null) {
ruleContext.attributeError(attribute, "Stub application cannot be found");
return null;
}
JavaCompilationArgsProvider provider = dep.getProvider(JavaCompilationArgsProvider.class);
if (provider == null) {
ruleContext.attributeError(attribute, "'" + dep.getLabel() + "' should be a Java target");
return null;
}
JavaTargetAttributes attributes = new JavaTargetAttributes.Builder(javaSemantics).addRuntimeClassPathEntries(provider.getJavaCompilationArgs().getRuntimeJars()).build();
Function<Artifact, Artifact> desugaredJars = Functions.identity();
if (AndroidCommon.getAndroidConfig(ruleContext).desugarJava8()) {
desugaredJars = collectDesugaredJarsFromAttributes(ruleContext, ImmutableList.of(attribute)).build().collapseToFunction();
}
Artifact stubDeployJar = getDxArtifact(ruleContext, split ? "split_stub_deploy.jar" : "stub_deploy.jar");
new DeployArchiveBuilder(javaSemantics, ruleContext).setOutputJar(stubDeployJar).setAttributes(attributes).setDerivedJarFunction(desugaredJars).build();
Artifact stubDex = getDxArtifact(ruleContext, split ? "split_stub_application/classes.dex" : "stub_application/classes.dex");
AndroidCommon.createDexAction(ruleContext, stubDeployJar, stubDex, ImmutableList.<String>of(), false, null);
return stubDex;
}
use of com.google.devtools.build.lib.rules.java.JavaTargetAttributes in project bazel by bazelbuild.
the class AndroidCommon method init.
public JavaTargetAttributes init(JavaSemantics javaSemantics, AndroidSemantics androidSemantics, ResourceApk resourceApk, boolean addCoverageSupport, boolean collectJavaCompilationArgs, boolean isBinary) throws InterruptedException {
classJar = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_LIBRARY_CLASS_JAR);
idlHelper = new AndroidIdlHelper(ruleContext, classJar);
ImmutableList<Artifact> bootclasspath;
if (getAndroidConfig(ruleContext).desugarJava8()) {
bootclasspath = ImmutableList.<Artifact>builder().addAll(ruleContext.getPrerequisite("$desugar_java8_extra_bootclasspath", Mode.HOST).getProvider(FileProvider.class).getFilesToBuild()).add(AndroidSdkProvider.fromRuleContext(ruleContext).getAndroidJar()).build();
} else {
bootclasspath = ImmutableList.of(AndroidSdkProvider.fromRuleContext(ruleContext).getAndroidJar());
}
JavaTargetAttributes.Builder attributes = javaCommon.initCommon(idlHelper.getIdlGeneratedJavaSources(), androidSemantics.getJavacArguments(ruleContext)).setBootClassPath(bootclasspath);
if (DataBinding.isEnabled(ruleContext)) {
DataBinding.addAnnotationProcessor(ruleContext, attributes);
}
JavaCompilationArtifacts.Builder artifactsBuilder = new JavaCompilationArtifacts.Builder();
NestedSetBuilder<Artifact> jarsProducedForRuntime = NestedSetBuilder.<Artifact>stableOrder();
NestedSetBuilder<Artifact> filesBuilder = NestedSetBuilder.<Artifact>stableOrder();
Artifact resourcesJar = resourceApk.getResourceJavaSrcJar();
if (resourcesJar != null) {
filesBuilder.add(resourcesJar);
// Use a fast-path R class generator for android_binary with local resources, where there is
// a bottleneck. For legacy resources, the srcjar and R class compiler don't match up
// (the legacy srcjar requires the createJarJar step below).
boolean useRClassGenerator = isBinary && !resourceApk.isLegacy();
compileResources(javaSemantics, resourceApk, resourcesJar, artifactsBuilder, attributes, filesBuilder, jarsProducedForRuntime, useRClassGenerator);
if (resourceApk.isLegacy()) {
// Repackages the R.java for each dependency package and places the resultant jars before
// the dependency libraries to ensure that the generated resource ids are correct.
createJarJarActions(attributes, jarsProducedForRuntime, resourceApk.getResourceDependencies().getResources(), resourceApk.getPrimaryResource().getJavaPackage(), resourceClassJar);
}
}
JavaCompilationHelper helper = initAttributes(attributes, javaSemantics);
if (ruleContext.hasErrors()) {
return null;
}
if (addCoverageSupport) {
androidSemantics.addCoverageSupport(ruleContext, this, javaSemantics, true, attributes, artifactsBuilder);
if (ruleContext.hasErrors()) {
return null;
}
}
jackCompilationHelper = initJack(helper.getAttributes());
if (ruleContext.hasErrors()) {
return null;
}
initJava(javaSemantics, helper, artifactsBuilder, collectJavaCompilationArgs, filesBuilder, isBinary);
if (ruleContext.hasErrors()) {
return null;
}
if (generatedExtensionRegistryProvider != null) {
jarsProducedForRuntime.add(generatedExtensionRegistryProvider.getClassJar());
}
this.jarsProducedForRuntime = jarsProducedForRuntime.add(classJar).build();
return helper.getAttributes();
}
Aggregations