use of com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar in project bazel by bazelbuild.
the class AarImportTest method testClassesJarProvided.
@Test
public void testClassesJarProvided() throws Exception {
ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:foo");
Iterable<OutputJar> outputJars = aarImportTarget.getProvider(JavaRuleOutputJarsProvider.class).getOutputJars();
assertThat(outputJars).hasSize(1);
Artifact classesJar = outputJars.iterator().next().getClassJar();
assertThat(classesJar.getFilename()).isEqualTo("classes_and_libs_merged.jar");
SpawnAction jarMergingAction = ((SpawnAction) getGeneratingAction(classesJar));
assertThat(jarMergingAction.getArguments()).contains("--dont_change_compression");
}
use of com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar in project bazel by bazelbuild.
the class AndroidStudioInfoAspect method makeAndroidIdeInfo.
private static AndroidIdeInfo makeAndroidIdeInfo(AndroidIdeInfoProvider androidIdeInfoProvider, DependenciesResult dependenciesResult, NestedSetBuilder<Artifact> ideResolveArtifacts) {
AndroidIdeInfo.Builder builder = AndroidIdeInfo.newBuilder();
if (androidIdeInfoProvider.getSignedApk() != null) {
builder.setApk(makeArtifactLocation(androidIdeInfoProvider.getSignedApk()));
}
Artifact manifest = androidIdeInfoProvider.getManifest();
if (manifest != null) {
builder.setManifest(makeArtifactLocation(manifest));
addResolveArtifact(ideResolveArtifacts, manifest);
}
for (Artifact artifact : androidIdeInfoProvider.getApksUnderTest()) {
builder.addDependencyApk(makeArtifactLocation(artifact));
}
for (SourceDirectory resourceDir : androidIdeInfoProvider.getResourceDirs()) {
ArtifactLocation artifactLocation = makeArtifactLocation(resourceDir);
builder.addResources(artifactLocation);
}
if (androidIdeInfoProvider.getJavaPackage() != null) {
builder.setJavaPackage(androidIdeInfoProvider.getJavaPackage());
}
String idlImportRoot = androidIdeInfoProvider.getIdlImportRoot();
if (idlImportRoot != null) {
builder.setIdlImportRoot(idlImportRoot);
}
boolean hasIdlSources = !androidIdeInfoProvider.getIdlSrcs().isEmpty();
builder.setHasIdlSources(hasIdlSources);
if (hasIdlSources) {
LibraryArtifact idlLibraryArtifact = makeLibraryArtifact(ideResolveArtifacts, androidIdeInfoProvider.getIdlClassJar(), null, androidIdeInfoProvider.getIdlSourceJar());
if (idlLibraryArtifact != null) {
builder.setIdlJar(idlLibraryArtifact);
}
}
builder.setGenerateResourceClass(androidIdeInfoProvider.definesAndroidResources());
if (dependenciesResult.resources != null) {
builder.setLegacyResources(dependenciesResult.resources.toString());
}
OutputJar resourceJar = androidIdeInfoProvider.getResourceJar();
if (resourceJar != null) {
LibraryArtifact resourceLibraryArtifact = makeLibraryArtifact(ideResolveArtifacts, resourceJar.getClassJar(), resourceJar.getIJar(), resourceJar.getSrcJar());
if (resourceLibraryArtifact != null) {
builder.setResourceJar(resourceLibraryArtifact);
}
}
return builder.build();
}
use of com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar in project bazel by bazelbuild.
the class AndroidStudioInfoAspect method makeJavaIdeInfo.
private JavaIdeInfo makeJavaIdeInfo(ConfiguredTarget base, RuleContext ruleContext, JavaRuleOutputJarsProvider outputJarsProvider, AndroidStudioInfoFilesProvider.Builder providerBuilder) {
NestedSetBuilder<Artifact> ideResolveArtifacts = providerBuilder.ideResolveFilesBuilder();
JavaIdeInfo.Builder builder = JavaIdeInfo.newBuilder();
List<Artifact> javaSources = Lists.newArrayList();
List<Artifact> generatedJavaSources = Lists.newArrayList();
List<Artifact> srcjars = Lists.newArrayList();
divideJavaSources(ruleContext, javaSources, generatedJavaSources, srcjars);
if (!javaSources.isEmpty()) {
Artifact packageManifest = derivedArtifact(base, ruleContext, ".manifest");
providerBuilder.ideInfoFilesBuilder().add(packageManifest);
ruleContext.registerAction(makePackageManifestAction(ruleContext, packageManifest, javaSources));
builder.setPackageManifest(makeArtifactLocation(packageManifest));
}
// This can be removed once android_resources is deleted
if (ruleContext.attributes().has("resources", BuildType.LABEL) && ruleContext.getRule().getRuleClass().startsWith("android_")) {
srcjars = ImmutableList.of();
}
if (!javaSources.isEmpty() && (!generatedJavaSources.isEmpty() || !srcjars.isEmpty())) {
Artifact filteredGenJar = derivedArtifact(base, ruleContext, "-filtered-gen.jar");
Artifact filteredGenSrcJar = derivedArtifact(base, ruleContext, "-filtered-gen-src.jar");
List<Artifact> jars = Lists.newArrayList();
List<Artifact> sourceJars = Lists.newArrayList();
for (OutputJar outputJar : outputJarsProvider.getOutputJars()) {
Artifact jar = outputJar.getIJar();
if (jar == null) {
jar = outputJar.getClassJar();
}
if (jar != null) {
jars.add(jar);
}
if (outputJar.getSrcJar() != null) {
sourceJars.add(outputJar.getSrcJar());
}
}
ruleContext.registerAction(makeFilteredJarAction(ruleContext, jars, sourceJars, generatedJavaSources, srcjars, filteredGenJar, filteredGenSrcJar));
ideResolveArtifacts.add(filteredGenJar);
ideResolveArtifacts.add(filteredGenSrcJar);
builder.setFilteredGenJar(makeLibraryArtifact(ideResolveArtifacts, filteredGenJar, null, filteredGenSrcJar));
}
collectJarsFromOutputJarsProvider(builder, ideResolveArtifacts, outputJarsProvider);
Artifact jdeps = outputJarsProvider.getJdeps();
if (jdeps != null) {
builder.setJdeps(makeArtifactLocation(jdeps));
}
JavaGenJarsProvider genJarsProvider = base.getProvider(JavaGenJarsProvider.class);
if (genJarsProvider != null) {
collectGenJars(builder, ideResolveArtifacts, genJarsProvider);
}
Collection<Artifact> sourceFiles = getSources(ruleContext);
for (Artifact sourceFile : sourceFiles) {
builder.addSources(makeArtifactLocation(sourceFile));
}
return builder.build();
}
use of com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar 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();
}
use of com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar in project bazel by bazelbuild.
the class AndroidCommon method addTransitiveInfoProviders.
public RuleConfiguredTargetBuilder addTransitiveInfoProviders(RuleConfiguredTargetBuilder builder, AndroidSemantics androidSemantics, Artifact aar, ResourceApk resourceApk, Artifact zipAlignedApk, Iterable<Artifact> apksUnderTest) {
idlHelper.addTransitiveInfoProviders(builder, classJar, manifestProtoOutput);
if (generatedExtensionRegistryProvider != null) {
builder.add(GeneratedExtensionRegistryProvider.class, generatedExtensionRegistryProvider);
}
OutputJar resourceJar = null;
if (resourceClassJar != null && resourceSourceJar != null) {
resourceJar = new OutputJar(resourceClassJar, null, ImmutableList.of(resourceSourceJar));
javaRuleOutputJarsProviderBuilder.addOutputJar(resourceJar);
}
JavaRuleOutputJarsProvider ruleOutputJarsProvider = javaRuleOutputJarsProviderBuilder.addOutputJar(classJar, iJar, ImmutableList.of(srcJar)).setJdeps(outputDepsProto).build();
JavaSourceJarsProvider sourceJarsProvider = javaSourceJarsProviderBuilder.build();
JavaCompilationArgsProvider compilationArgsProvider = JavaCompilationArgsProvider.create(javaCompilationArgs, recursiveJavaCompilationArgs, compileTimeDependencyArtifacts, NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER));
JavaSkylarkApiProvider.Builder skylarkApiProvider = JavaSkylarkApiProvider.builder().setRuleOutputJarsProvider(ruleOutputJarsProvider).setSourceJarsProvider(sourceJarsProvider).setCompilationArgsProvider(compilationArgsProvider);
javaCommon.addTransitiveInfoProviders(builder, skylarkApiProvider, filesToBuild, classJar, ANDROID_COLLECTION_SPEC);
javaCommon.addGenJarsProvider(builder, skylarkApiProvider, genClassJar, genSourceJar);
return builder.setFilesToBuild(filesToBuild).addSkylarkTransitiveInfo(JavaSkylarkApiProvider.NAME, skylarkApiProvider.build()).add(JavaRuleOutputJarsProvider.class, ruleOutputJarsProvider).add(JavaSourceJarsProvider.class, sourceJarsProvider).add(JavaRuntimeJarProvider.class, new JavaRuntimeJarProvider(javaCommon.getJavaCompilationArtifacts().getRuntimeJars())).add(RunfilesProvider.class, RunfilesProvider.simple(getRunfiles())).add(AndroidResourcesProvider.class, resourceApk.toResourceProvider(ruleContext.getLabel())).add(AndroidIdeInfoProvider.class, createAndroidIdeInfoProvider(ruleContext, androidSemantics, idlHelper, resourceJar, aar, resourceApk, zipAlignedApk, apksUnderTest)).add(JavaCompilationArgsProvider.class, compilationArgsProvider).add(JackLibraryProvider.class, asNeverLink ? jackCompilationHelper.compileAsNeverlinkLibrary() : jackCompilationHelper.compileAsLibrary()).addSkylarkTransitiveInfo(AndroidSkylarkApiProvider.NAME, new AndroidSkylarkApiProvider()).addOutputGroup(OutputGroupProvider.HIDDEN_TOP_LEVEL, collectHiddenTopLevelArtifacts(ruleContext)).addOutputGroup(JavaSemantics.SOURCE_JARS_OUTPUT_GROUP, sourceJarsProvider.getTransitiveSourceJars());
}
Aggregations