Search in sources :

Example 6 with JavaCompilationArgsProvider

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");
}
Also used : JavaCompilationArgsProvider(com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) FileConfiguredTarget(com.google.devtools.build.lib.analysis.FileConfiguredTarget) Test(org.junit.Test)

Example 7 with JavaCompilationArgsProvider

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;
}
Also used : JavaCompilationArgsProvider(com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider) MultimapBuilder(com.google.common.collect.MultimapBuilder) Builder(com.google.devtools.build.lib.analysis.actions.SpawnAction.Builder) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) DeployArchiveBuilder(com.google.devtools.build.lib.rules.java.DeployArchiveBuilder) DeployArchiveBuilder(com.google.devtools.build.lib.rules.java.DeployArchiveBuilder) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) JavaTargetAttributes(com.google.devtools.build.lib.rules.java.JavaTargetAttributes) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 8 with JavaCompilationArgsProvider

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());
}
Also used : JavaRuleOutputJarsProvider(com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider) JavaCompilationArgsProvider(com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider) OutputJar(com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar) JavaSourceJarsProvider(com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider) JavaSkylarkApiProvider(com.google.devtools.build.lib.rules.java.JavaSkylarkApiProvider) JavaRuntimeJarProvider(com.google.devtools.build.lib.rules.java.JavaRuntimeJarProvider) RunfilesProvider(com.google.devtools.build.lib.analysis.RunfilesProvider)

Example 9 with JavaCompilationArgsProvider

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);
}
Also used : JavaCompilationArgsProvider(com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider) ImmutableSet(com.google.common.collect.ImmutableSet) JavaSourceInfoProvider(com.google.devtools.build.lib.rules.java.JavaSourceInfoProvider) JavaGenJarsProvider(com.google.devtools.build.lib.rules.java.JavaGenJarsProvider) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) ProtoCompileActionBuilder(com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder) Artifact(com.google.devtools.build.lib.actions.Artifact)

Aggregations

JavaCompilationArgsProvider (com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider)9 Artifact (com.google.devtools.build.lib.actions.Artifact)5 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)4 JavaSkylarkApiProvider (com.google.devtools.build.lib.rules.java.JavaSkylarkApiProvider)4 JavaSourceJarsProvider (com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider)4 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)3 JavaRuleOutputJarsProvider (com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider)3 Test (org.junit.Test)3 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)2 Runfiles (com.google.devtools.build.lib.analysis.Runfiles)2 RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)2 JavaRunfilesProvider (com.google.devtools.build.lib.rules.java.JavaRunfilesProvider)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 MultimapBuilder (com.google.common.collect.MultimapBuilder)1 FileConfiguredTarget (com.google.devtools.build.lib.analysis.FileConfiguredTarget)1 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)1 Builder (com.google.devtools.build.lib.analysis.actions.SpawnAction.Builder)1 DeployArchiveBuilder (com.google.devtools.build.lib.rules.java.DeployArchiveBuilder)1 JavaCompilationArgs (com.google.devtools.build.lib.rules.java.JavaCompilationArgs)1 JavaGenJarsProvider (com.google.devtools.build.lib.rules.java.JavaGenJarsProvider)1