use of com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider in project bazel by bazelbuild.
the class AarImportTest method testJavaCompilationArgsProvider.
@Test
public void testJavaCompilationArgsProvider() throws Exception {
ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:bar");
JavaCompilationArgsProvider provider = aarImportTarget.getProvider(JavaCompilationArgsProvider.class);
assertThat(provider).isNotNull();
assertThat(artifactsToStrings(provider.getJavaCompilationArgs().getRuntimeJars())).containsExactly("bin a/_aar/bar/classes_and_libs_merged.jar", "bin a/_aar/foo/classes_and_libs_merged.jar", "src java/baz.jar");
}
use of com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider 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.JavaCompilationArgsProvider 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());
}
use of com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider in project bazel by bazelbuild.
the class J2ObjcAspect method java.
private ConfiguredAspect java(ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) throws InterruptedException {
JavaCompilationArgsProvider compilationArgsProvider = base.getProvider(JavaCompilationArgsProvider.class);
JavaSourceInfoProvider sourceInfoProvider = base.getProvider(JavaSourceInfoProvider.class);
JavaGenJarsProvider genJarProvider = base.getProvider(JavaGenJarsProvider.class);
ImmutableSet.Builder<Artifact> javaSourceFilesBuilder = ImmutableSet.builder();
ImmutableSet.Builder<Artifact> javaSourceJarsBuilder = ImmutableSet.builder();
if (sourceInfoProvider != null) {
javaSourceFilesBuilder.addAll(sourceInfoProvider.getSourceFiles());
javaSourceJarsBuilder.addAll(sourceInfoProvider.getSourceJars()).addAll(sourceInfoProvider.getSourceJarsForJarFiles());
}
if (genJarProvider != null && genJarProvider.getGenSourceJar() != null) {
javaSourceJarsBuilder.add(genJarProvider.getGenSourceJar());
}
ImmutableSet<Artifact> javaSourceFiles = javaSourceFilesBuilder.build();
ImmutableSet<Artifact> javaSourceJars = javaSourceJarsBuilder.build();
J2ObjcSource j2ObjcSource = javaJ2ObjcSource(ruleContext, javaSourceFiles, javaSourceJars);
J2ObjcMappingFileProvider depJ2ObjcMappingFileProvider = depJ2ObjcMappingFileProvider(ruleContext);
J2ObjcMappingFileProvider directJ2ObjcMappingFileProvider;
if (Iterables.isEmpty(j2ObjcSource.getObjcSrcs())) {
directJ2ObjcMappingFileProvider = new J2ObjcMappingFileProvider.Builder().build();
} else {
directJ2ObjcMappingFileProvider = createJ2ObjcTranspilationAction(ruleContext, javaSourceFiles, javaSourceJars, depJ2ObjcMappingFileProvider, compilationArgsProvider, j2ObjcSource);
}
return buildAspect(base, ruleContext, parameters, j2ObjcSource, directJ2ObjcMappingFileProvider, JAVA_DEPENDENT_ATTRIBUTES);
}
Aggregations