use of com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder in project bazel by bazelbuild.
the class JavaLiteProtoLibrary method create.
@Override
public ConfiguredTarget create(final RuleContext ruleContext) throws InterruptedException, RuleErrorException {
JavaCompilationArgsProvider dependencyArgsProviders = JavaCompilationArgsProvider.merge(Iterables.<JavaCompilationArgsAspectProvider, JavaCompilationArgsProvider>transform(getDeps(ruleContext, JavaCompilationArgsAspectProvider.class), JavaCompilationArgsAspectProvider.GET_PROVIDER));
if (!StrictDepsUtils.isStrictDepsJavaProtoLibrary(ruleContext)) {
dependencyArgsProviders = StrictDepsUtils.makeNonStrict(dependencyArgsProviders);
}
Runfiles runfiles = new Runfiles.Builder(ruleContext.getWorkspaceName()).addArtifacts(dependencyArgsProviders.getRecursiveJavaCompilationArgs().getRuntimeJars()).build();
JavaSourceJarsProvider sourceJarsProvider = JavaSourceJarsProvider.merge(Iterables.<JavaSourceJarsAspectProvider, JavaSourceJarsProvider>transform(getDeps(ruleContext, JavaSourceJarsAspectProvider.class), JavaSourceJarsAspectProvider.GET_PROVIDER));
NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.stableOrder();
filesToBuild.addAll(sourceJarsProvider.getSourceJars());
for (JavaProtoLibraryTransitiveFilesToBuildProvider provider : ruleContext.getPrerequisites("deps", Mode.TARGET, JavaProtoLibraryTransitiveFilesToBuildProvider.class)) {
filesToBuild.addTransitive(provider.getJars());
}
JavaRuleOutputJarsProvider javaRuleOutputJarsProvider = JavaRuleOutputJarsProvider.builder().build();
JavaSkylarkApiProvider.Builder skylarkApiProvider = JavaSkylarkApiProvider.builder().setRuleOutputJarsProvider(javaRuleOutputJarsProvider).setSourceJarsProvider(sourceJarsProvider).setCompilationArgsProvider(dependencyArgsProviders);
return new RuleConfiguredTargetBuilder(ruleContext).setFilesToBuild(filesToBuild.build()).addSkylarkTransitiveInfo(JavaSkylarkApiProvider.NAME, skylarkApiProvider.build()).addProvider(RunfilesProvider.class, RunfilesProvider.withData(Runfiles.EMPTY, runfiles)).addOutputGroup(OutputGroupProvider.DEFAULT, NestedSetBuilder.<Artifact>emptySet(STABLE_ORDER)).add(JavaCompilationArgsProvider.class, dependencyArgsProviders).add(JavaSourceJarsProvider.class, sourceJarsProvider).add(JavaRunfilesProvider.class, new JavaRunfilesProvider(runfiles)).add(ProguardSpecProvider.class, getJavaLiteRuntimeSpec(ruleContext)).add(JavaRuleOutputJarsProvider.class, javaRuleOutputJarsProvider).build();
}
use of com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder in project bazel by bazelbuild.
the class AndroidBinary method createAndroidBinary.
public static RuleConfiguredTargetBuilder createAndroidBinary(RuleContext ruleContext, NestedSetBuilder<Artifact> filesBuilder, Artifact binaryJar, Function<Artifact, Artifact> derivedJarFunction, boolean isBinaryJarFiltered, JavaCommon javaCommon, AndroidCommon androidCommon, JavaSemantics javaSemantics, AndroidSemantics androidSemantics, NativeLibs nativeLibs, ApplicationManifest applicationManifest, ResourceApk resourceApk, ResourceApk incrementalResourceApk, ResourceApk instantRunResourceApk, ResourceApk splitResourceApk, boolean shrinkResources, JavaTargetAttributes resourceClasses, ImmutableList<Artifact> apksUnderTest, ImmutableList<Artifact> additionalMergedManifests, Artifact proguardMapping) throws InterruptedException, RuleErrorException {
ImmutableList<Artifact> proguardSpecs = ProguardHelper.collectTransitiveProguardSpecs(ruleContext, ImmutableList.of(resourceApk.getResourceProguardConfig()));
boolean rexEnabled = ruleContext.getFragment(AndroidConfiguration.class).useRexToCompressDexFiles() || (ruleContext.attributes().get("rewrite_dexes_with_rex", Type.BOOLEAN));
// TODO(bazel-team): Verify that proguard spec files don't contain -printmapping directions
// which this -printmapping command line flag will override.
Artifact proguardOutputMap = null;
if (ProguardHelper.genProguardMapping(ruleContext.attributes()) || ProguardHelper.getJavaOptimizationMode(ruleContext).alwaysGenerateOutputMapping() || shrinkResources) {
if (rexEnabled) {
proguardOutputMap = ProguardHelper.getProguardTempArtifact(ruleContext, ProguardHelper.getJavaOptimizationMode(ruleContext).name().toLowerCase(), "proguard_output_for_rex.map");
} else {
proguardOutputMap = ruleContext.getImplicitOutputArtifact(JavaSemantics.JAVA_BINARY_PROGUARD_MAP);
}
}
ProguardOutput proguardOutput = applyProguard(ruleContext, androidCommon, javaSemantics, binaryJar, proguardSpecs, proguardMapping, proguardOutputMap);
if (shrinkResources) {
resourceApk = shrinkResources(ruleContext, resourceApk, proguardSpecs, proguardOutput, filesBuilder);
}
Artifact jarToDex = proguardOutput.getOutputJar();
DexingOutput dexingOutput = shouldDexWithJack(ruleContext) ? dexWithJack(ruleContext, androidCommon, proguardSpecs) : dex(ruleContext, androidSemantics, binaryJar, jarToDex, isBinaryJarFiltered, androidCommon, resourceApk.getMainDexProguardConfig(), resourceClasses, derivedJarFunction);
NestedSet<Artifact> nativeLibsZips = AndroidCommon.collectTransitiveNativeLibsZips(ruleContext).build();
Artifact finalDexes;
Artifact finalProguardMap;
if (rexEnabled) {
finalDexes = getDxArtifact(ruleContext, "rexed_dexes.zip");
Builder rexActionBuilder = new SpawnAction.Builder();
rexActionBuilder.setExecutable(ruleContext.getExecutablePrerequisite("$rex_wrapper", Mode.HOST)).setMnemonic("Rex").setProgressMessage("Rexing dex files").addArgument("--dex_input").addInputArgument(dexingOutput.classesDexZip).addArgument("--dex_output").addOutputArgument(finalDexes);
if (proguardOutput.getMapping() != null) {
finalProguardMap = ruleContext.getImplicitOutputArtifact(JavaSemantics.JAVA_BINARY_PROGUARD_MAP);
Artifact finalRexPackageMap = getDxArtifact(ruleContext, "rex_output_package.map");
rexActionBuilder.addArgument("--proguard_input_map").addInputArgument(proguardOutput.getMapping()).addArgument("--proguard_output_map").addOutputArgument(finalProguardMap).addArgument("--rex_output_package_map").addOutputArgument(finalRexPackageMap);
if (ruleContext.attributes().isAttributeValueExplicitlySpecified("rex_package_map")) {
Artifact rexPackageMap = ruleContext.getPrerequisiteArtifact("rex_package_map", Mode.TARGET);
rexActionBuilder.addArgument("--rex_input_package_map").addInputArgument(rexPackageMap);
}
} else {
finalProguardMap = proguardOutput.getMapping();
}
// determine whether or not to pass the flag to Rex
if (ruleContext.attributes().isAttributeValueExplicitlySpecified("main_dex_list")) {
rexActionBuilder.addArgument("--keep-main-dex");
}
ruleContext.registerAction(rexActionBuilder.build(ruleContext));
} else {
finalDexes = dexingOutput.classesDexZip;
finalProguardMap = proguardOutput.getMapping();
}
if (!proguardSpecs.isEmpty()) {
proguardOutput.addAllToSet(filesBuilder, finalProguardMap);
}
ApkSigningMethod signingMethod = ruleContext.getFragment(AndroidConfiguration.class).getApkSigningMethod();
Artifact unsignedApk = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_BINARY_UNSIGNED_APK);
Artifact zipAlignedApk = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_BINARY_APK);
ApkActionsBuilder.create("apk", signingMethod).setClassesDex(finalDexes).setResourceApk(resourceApk.getArtifact()).setJavaResourceZip(dexingOutput.javaResourceJar).setNativeLibsZips(nativeLibsZips).setNativeLibs(nativeLibs).setUnsignedApk(unsignedApk).setSignedApk(zipAlignedApk).setZipalignApk(true).registerActions(ruleContext, androidSemantics);
// Don't add blacklistedApk, so it's only built if explicitly requested.
filesBuilder.add(binaryJar);
filesBuilder.add(unsignedApk);
filesBuilder.add(zipAlignedApk);
NestedSet<Artifact> filesToBuild = filesBuilder.build();
Iterable<Artifact> dataDeps = ImmutableList.of();
if (ruleContext.attributes().has("data", BuildType.LABEL_LIST) && ruleContext.getAttributeMode("data") == Mode.DATA) {
dataDeps = ruleContext.getPrerequisiteArtifacts("data", Mode.DATA).list();
}
Artifact deployInfo = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.DEPLOY_INFO);
AndroidDeployInfoAction.createDeployInfoAction(ruleContext, deployInfo, resourceApk.getManifest(), additionalMergedManifests, Iterables.concat(ImmutableList.of(zipAlignedApk), apksUnderTest), dataDeps);
NestedSet<Artifact> coverageMetadata = (androidCommon.getInstrumentedJar() != null) ? NestedSetBuilder.create(Order.STABLE_ORDER, androidCommon.getInstrumentedJar()) : NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER);
RuleConfiguredTargetBuilder builder = new RuleConfiguredTargetBuilder(ruleContext);
Artifact incrementalApk = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_BINARY_INCREMENTAL_APK);
Artifact fullDeployMarker = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.FULL_DEPLOY_MARKER);
Artifact incrementalDeployMarker = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.INCREMENTAL_DEPLOY_MARKER);
Artifact splitDeployMarker = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.SPLIT_DEPLOY_MARKER);
Artifact incrementalDexManifest = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.DEX_MANIFEST);
ruleContext.registerAction(new SpawnAction.Builder().setMnemonic("AndroidDexManifest").setProgressMessage("Generating incremental installation manifest for " + ruleContext.getLabel()).setExecutable(ruleContext.getExecutablePrerequisite("$build_incremental_dexmanifest", Mode.HOST)).addOutputArgument(incrementalDexManifest).addInputArguments(dexingOutput.shardDexZips).useParameterFile(ParameterFileType.UNQUOTED).build(ruleContext));
Artifact stubData = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.MOBILE_INSTALL_STUB_APPLICATION_DATA);
Artifact stubDex = getStubDex(ruleContext, javaSemantics, false);
ruleContext.assertNoErrors();
ApkActionsBuilder incrementalActionsBuilder = ApkActionsBuilder.create("incremental apk", signingMethod).setClassesDex(stubDex).setResourceApk(incrementalResourceApk.getArtifact()).setJavaResourceZip(dexingOutput.javaResourceJar).setNativeLibsZips(nativeLibsZips).setJavaResourceFile(stubData).setSignedApk(incrementalApk);
if (!ruleContext.getFragment(AndroidConfiguration.class).useIncrementalNativeLibs()) {
incrementalActionsBuilder.setNativeLibs(nativeLibs);
}
incrementalActionsBuilder.registerActions(ruleContext, androidSemantics);
Artifact argsArtifact = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.MOBILE_INSTALL_ARGS);
ruleContext.registerAction(new WriteAdbArgsAction(ruleContext.getActionOwner(), argsArtifact));
createInstallAction(ruleContext, false, fullDeployMarker, argsArtifact, incrementalDexManifest, incrementalResourceApk.getArtifact(), incrementalApk, nativeLibs, stubData);
createInstallAction(ruleContext, true, incrementalDeployMarker, argsArtifact, incrementalDexManifest, incrementalResourceApk.getArtifact(), incrementalApk, nativeLibs, stubData);
Artifact incrementalDeployInfo = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.DEPLOY_INFO_INCREMENTAL);
AndroidDeployInfoAction.createDeployInfoAction(ruleContext, incrementalDeployInfo, resourceApk.getManifest(), additionalMergedManifests, ImmutableList.<Artifact>of(), dataDeps);
NestedSet<Artifact> fullInstallOutputGroup = NestedSetBuilder.<Artifact>stableOrder().add(fullDeployMarker).add(incrementalDeployInfo).build();
NestedSet<Artifact> incrementalInstallOutputGroup = NestedSetBuilder.<Artifact>stableOrder().add(incrementalDeployMarker).add(incrementalDeployInfo).build();
NestedSetBuilder<Artifact> splitApkSetBuilder = NestedSetBuilder.compileOrder();
// Put the Android resource APK first so that this split gets installed first.
//
// This avoids some logcat spam during installation, because otherwise the Android package
// manager would complain about references to missing resources in the manifest during the
// installation of each split (said references would eventually get installed, but it cannot
// know that in advance)
Artifact resourceSplitApk = getDxArtifact(ruleContext, "android_resources.apk");
ApkActionsBuilder.create("split Android resource apk", signingMethod).setResourceApk(splitResourceApk.getArtifact()).setSignedApk(resourceSplitApk).registerActions(ruleContext, androidSemantics);
splitApkSetBuilder.add(resourceSplitApk);
for (int i = 0; i < dexingOutput.shardDexZips.size(); i++) {
String splitName = "dex" + (i + 1);
Artifact splitApkResources = createSplitApkResources(ruleContext, applicationManifest, splitName, true);
Artifact splitApk = getDxArtifact(ruleContext, splitName + ".apk");
ApkActionsBuilder.create("split dex apk " + (i + 1), signingMethod).setClassesDex(dexingOutput.shardDexZips.get(i)).setResourceApk(splitApkResources).setSignedApk(splitApk).registerActions(ruleContext, androidSemantics);
splitApkSetBuilder.add(splitApk);
}
Artifact nativeSplitApkResources = createSplitApkResources(ruleContext, applicationManifest, "native", false);
Artifact nativeSplitApk = getDxArtifact(ruleContext, "native.apk");
ApkActionsBuilder.create("split native apk", signingMethod).setResourceApk(nativeSplitApkResources).setNativeLibs(nativeLibs).setSignedApk(nativeSplitApk).registerActions(ruleContext, androidSemantics);
splitApkSetBuilder.add(nativeSplitApk);
Artifact javaSplitApkResources = createSplitApkResources(ruleContext, applicationManifest, "java_resources", false);
Artifact javaSplitApk = getDxArtifact(ruleContext, "java_resources.apk");
ApkActionsBuilder.create("split Java resource apk", signingMethod).setResourceApk(javaSplitApkResources).setJavaResourceZip(dexingOutput.javaResourceJar).setSignedApk(javaSplitApk).registerActions(ruleContext, androidSemantics);
splitApkSetBuilder.add(javaSplitApk);
Artifact splitMainApkResources = getDxArtifact(ruleContext, "split_main.ap_");
ruleContext.registerAction(new SpawnAction.Builder().setMnemonic("AndroidStripResources").setProgressMessage("Stripping resources from split main apk").setExecutable(ruleContext.getExecutablePrerequisite("$strip_resources", Mode.HOST)).addArgument("--input_resource_apk").addInputArgument(resourceApk.getArtifact()).addArgument("--output_resource_apk").addOutputArgument(splitMainApkResources).build(ruleContext));
NestedSet<Artifact> splitApks = splitApkSetBuilder.build();
Artifact splitMainApk = getDxArtifact(ruleContext, "split_main.apk");
Artifact splitStubDex = getStubDex(ruleContext, javaSemantics, true);
ruleContext.assertNoErrors();
ApkActionsBuilder.create("split main apk", signingMethod).setClassesDex(splitStubDex).setResourceApk(splitMainApkResources).setNativeLibsZips(nativeLibsZips).setSignedApk(splitMainApk).registerActions(ruleContext, androidSemantics);
splitApkSetBuilder.add(splitMainApk);
NestedSet<Artifact> allSplitApks = splitApkSetBuilder.build();
createSplitInstallAction(ruleContext, splitDeployMarker, argsArtifact, splitMainApk, splitApks, stubData);
Artifact splitDeployInfo = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.DEPLOY_INFO_SPLIT);
AndroidDeployInfoAction.createDeployInfoAction(ruleContext, splitDeployInfo, resourceApk.getManifest(), additionalMergedManifests, ImmutableList.<Artifact>of(), dataDeps);
NestedSet<Artifact> splitInstallOutputGroup = NestedSetBuilder.<Artifact>stableOrder().addTransitive(allSplitApks).add(splitDeployMarker).add(splitDeployInfo).build();
Artifact debugKeystore = androidSemantics.getApkDebugSigningKey(ruleContext);
Artifact apkManifest = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.APK_MANIFEST);
createApkManifestAction(ruleContext, apkManifest, // text proto
false, androidCommon, resourceClasses, instantRunResourceApk, nativeLibs, debugKeystore);
Artifact apkManifestText = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.APK_MANIFEST_TEXT);
createApkManifestAction(ruleContext, apkManifestText, // text proto
true, androidCommon, resourceClasses, instantRunResourceApk, nativeLibs, debugKeystore);
androidCommon.addTransitiveInfoProviders(builder, androidSemantics, null, /* aar */
resourceApk, zipAlignedApk, apksUnderTest);
androidSemantics.addTransitiveInfoProviders(builder, ruleContext, javaCommon, androidCommon, jarToDex);
if (proguardOutput.getMapping() != null) {
builder.add(ProguardMappingProvider.class, ProguardMappingProvider.create(finalProguardMap));
}
return builder.setFilesToBuild(filesToBuild).add(RunfilesProvider.class, RunfilesProvider.simple(new Runfiles.Builder(ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles()).addRunfiles(ruleContext, RunfilesProvider.DEFAULT_RUNFILES).addTransitiveArtifacts(filesToBuild).build())).add(JavaSourceInfoProvider.class, JavaSourceInfoProvider.fromJavaTargetAttributes(resourceClasses, javaSemantics)).add(ApkProvider.class, ApkProvider.create(NestedSetBuilder.create(Order.STABLE_ORDER, zipAlignedApk), coverageMetadata, NestedSetBuilder.create(Order.STABLE_ORDER, applicationManifest.getManifest()))).add(AndroidPreDexJarProvider.class, AndroidPreDexJarProvider.create(jarToDex)).addOutputGroup("mobile_install_full" + INTERNAL_SUFFIX, fullInstallOutputGroup).addOutputGroup("mobile_install_incremental" + INTERNAL_SUFFIX, incrementalInstallOutputGroup).addOutputGroup("mobile_install_split" + INTERNAL_SUFFIX, splitInstallOutputGroup).addOutputGroup("apk_manifest", apkManifest).addOutputGroup("apk_manifest_text", apkManifestText).addOutputGroup("android_deploy_info", deployInfo);
}
use of com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder in project bazel by bazelbuild.
the class BazelPythonSemantics method createPythonZipAction.
private static void createPythonZipAction(RuleContext ruleContext, Artifact executable, Artifact zipFile, Artifact templateMain, FilesToRunProvider zipper, RunfilesSupport runfilesSupport) {
NestedSetBuilder<Artifact> inputsBuilder = NestedSetBuilder.stableOrder();
PathFragment workspaceName = runfilesSupport.getWorkspaceName();
CustomCommandLine.Builder argv = new CustomCommandLine.Builder();
inputsBuilder.add(templateMain);
argv.add("__main__.py=" + templateMain.getExecPathString());
// Creating __init__.py files under each directory
argv.add("__init__.py=");
argv.add(getZipRunfilesPath("__init__.py", workspaceName) + "=");
for (String path : runfilesSupport.getRunfiles().getEmptyFilenames()) {
argv.add(getZipRunfilesPath(path, workspaceName) + "=");
}
// Filter the executable file, cause we are building it.
for (Artifact artifact : runfilesSupport.getRunfilesArtifactsWithoutMiddlemen()) {
if (!artifact.equals(executable)) {
argv.add(getZipRunfilesPath(artifact.getRunfilesPath(), workspaceName) + "=" + artifact.getExecPathString());
inputsBuilder.add(artifact);
}
}
// zipper can only consume file list options from param file not other options,
// so write file list in the param file first.
Artifact paramFile = ruleContext.getDerivedArtifact(ParameterFile.derivePath(zipFile.getRootRelativePath()), zipFile.getRoot());
ruleContext.registerAction(new ParameterFileWriteAction(ruleContext.getActionOwner(), paramFile, argv.build(), ParameterFile.ParameterFileType.UNQUOTED, ISO_8859_1));
ruleContext.registerAction(new SpawnAction.Builder().addInput(paramFile).addTransitiveInputs(inputsBuilder.build()).addOutput(zipFile).setExecutable(zipper).useDefaultShellEnvironment().addArgument("cC").addArgument(zipFile.getExecPathString()).addArgument("@" + paramFile.getExecPathString()).setMnemonic("PythonZipper").build(ruleContext));
}
use of com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder in project bazel by bazelbuild.
the class AndroidStudioInfoAspect method create.
@Override
public ConfiguredAspect create(ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) {
ConfiguredAspect.Builder builder = new Builder(this, parameters, ruleContext);
AndroidStudioInfoFilesProvider.Builder providerBuilder = new AndroidStudioInfoFilesProvider.Builder();
DependenciesResult dependenciesResult = processDependencies(base, ruleContext, providerBuilder);
AndroidStudioInfoFilesProvider provider = createIdeBuildArtifact(base, ruleContext, dependenciesResult, providerBuilder);
NestedSetBuilder<Artifact> ideCompileArtifacts = NestedSetBuilder.stableOrder();
// Add artifacts required for compilation
OutputGroupProvider outputGroupProvider = base.getProvider(OutputGroupProvider.class);
if (outputGroupProvider != null) {
ideCompileArtifacts.addTransitive(outputGroupProvider.getOutputGroup(OutputGroupProvider.FILES_TO_COMPILE));
}
builder.addOutputGroup(IDE_INFO, provider.getIdeInfoFiles()).addOutputGroup(IDE_INFO_TEXT, provider.getIdeInfoTextFiles()).addOutputGroup(IDE_RESOLVE, provider.getIdeResolveFiles()).addOutputGroup(IDE_COMPILE, ideCompileArtifacts.build()).addProvider(provider);
return builder.build();
}
use of com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder in project bazel by bazelbuild.
the class AarImport method create.
@Override
public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
if (!AndroidSdkProvider.verifyPresence(ruleContext)) {
return null;
}
RuleConfiguredTargetBuilder ruleBuilder = new RuleConfiguredTargetBuilder(ruleContext);
Artifact aar = ruleContext.getPrerequisiteArtifact("aar", Mode.TARGET);
Artifact allAarJars = createAarTreeArtifact(ruleContext, "jars");
Artifact jarMergingParams = createAarArtifact(ruleContext, "jar_merging_params");
ruleContext.registerAction(createAarEmbeddedJarsExtractorActions(ruleContext, aar, allAarJars, jarMergingParams));
Artifact mergedJar = createAarArtifact(ruleContext, MERGED_JAR);
ruleContext.registerAction(createAarJarsMergingActions(ruleContext, allAarJars, mergedJar, jarMergingParams));
// AndroidManifest.xml is required in every AAR.
Artifact androidManifestArtifact = createAarArtifact(ruleContext, ANDROID_MANIFEST);
ruleContext.registerAction(createSingleFileExtractorActions(ruleContext, aar, ANDROID_MANIFEST, androidManifestArtifact));
Artifact resourcesManifest = createAarArtifact(ruleContext, "resource_manifest");
ruleContext.registerAction(createManifestExtractorActions(ruleContext, aar, "res/.*", resourcesManifest));
Artifact resources = createAarTreeArtifact(ruleContext, "resources");
ruleContext.registerAction(createManifestFileEntriesExtractorActions(ruleContext, aar, resourcesManifest, resources));
ApplicationManifest androidManifest = ApplicationManifest.fromExplicitManifest(ruleContext, androidManifestArtifact);
FileProvider resourcesProvider = new FileProvider(new NestedSetBuilder<Artifact>(Order.NAIVE_LINK_ORDER).add(resources).build());
Artifact resourcesZip = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_ZIP);
ResourceApk resourceApk = androidManifest.packWithDataAndResources(ruleContext, new LocalResourceContainer.Builder(ruleContext).withResources(ImmutableList.of(resourcesProvider)).build(), ResourceDependencies.fromRuleDeps(ruleContext, JavaCommon.isNeverLink(ruleContext)), ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_R_TXT), ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_SYMBOLS), ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_PROCESSED_MANIFEST), resourcesZip, /* alwaysExportManifest = */
true);
// There isn't really any use case for building an aar_import target on its own, so the files to
// build could be empty. The resources zip and merged jars are added here as a sanity check for
// Bazel developers so that `bazel build java/com/my_aar_import` will fail if the resource
// processing or jar merging steps fail.
NestedSetBuilder<Artifact> filesToBuildBuilder = NestedSetBuilder.<Artifact>stableOrder().add(resourcesZip).add(mergedJar);
Artifact nativeLibs = createAarArtifact(ruleContext, "native_libs.zip");
ruleContext.registerAction(createAarNativeLibsFilterActions(ruleContext, aar, nativeLibs));
JavaRuleOutputJarsProvider.Builder jarProviderBuilder = new JavaRuleOutputJarsProvider.Builder().addOutputJar(mergedJar, null, ImmutableList.<Artifact>of());
for (TransitiveInfoCollection export : ruleContext.getPrerequisites("exports", Mode.TARGET)) {
for (OutputJar jar : JavaProvider.getProvider(JavaRuleOutputJarsProvider.class, export).getOutputJars()) {
jarProviderBuilder.addOutputJar(jar);
filesToBuildBuilder.add(jar.getClassJar());
}
}
ImmutableList<TransitiveInfoCollection> targets = ImmutableList.<TransitiveInfoCollection>copyOf(ruleContext.getPrerequisites("exports", Mode.TARGET));
JavaCommon common = new JavaCommon(ruleContext, javaSemantics, /* sources = */
ImmutableList.<Artifact>of(), /* compileDeps = */
targets, /* runtimeDeps = */
targets, /* bothDeps = */
targets);
common.setJavaCompilationArtifacts(new JavaCompilationArtifacts.Builder().addRuntimeJar(mergedJar).addCompileTimeJar(mergedJar).build());
return ruleBuilder.setFilesToBuild(filesToBuildBuilder.build()).addProvider(RunfilesProvider.class, RunfilesProvider.EMPTY).addProvider(AndroidResourcesProvider.class, resourceApk.toResourceProvider(ruleContext.getLabel())).addProvider(NativeLibsZipsProvider.class, new NativeLibsZipsProvider(AndroidCommon.collectTransitiveNativeLibsZips(ruleContext).add(nativeLibs).build())).addProvider(JavaRuntimeJarProvider.class, new JavaRuntimeJarProvider(ImmutableList.of(mergedJar))).addProvider(JavaCompilationArgsProvider.class, JavaCompilationArgsProvider.create(common.collectJavaCompilationArgs(/* recursive = */
false, JavaCommon.isNeverLink(ruleContext), /* srcLessDepsExport = */
false), common.collectJavaCompilationArgs(/* recursive = */
true, JavaCommon.isNeverLink(ruleContext), /* srcLessDepsExport = */
false))).addProvider(JavaRuleOutputJarsProvider.class, jarProviderBuilder.build()).build();
}
Aggregations