Search in sources :

Example 1 with JavaSourceJarsProvider

use of com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider in project bazel by bazelbuild.

the class JavaProtoLibrary method create.

@Override
public ConfiguredTarget create(final RuleContext ruleContext) throws InterruptedException, RuleErrorException {
    JavaCompilationArgsProvider dependencyArgsProviders = JavaCompilationArgsProvider.merge(Iterables.<JavaCompilationArgsAspectProvider, JavaCompilationArgsProvider>transform(this.<JavaCompilationArgsAspectProvider>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(this.<JavaSourceJarsAspectProvider>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 ruleOutputJarsProvider = JavaRuleOutputJarsProvider.builder().build();
    JavaSkylarkApiProvider.Builder skylarkApiProvider = JavaSkylarkApiProvider.builder().setRuleOutputJarsProvider(ruleOutputJarsProvider).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(JavaRuleOutputJarsProvider.class, ruleOutputJarsProvider).build();
}
Also used : JavaRuleOutputJarsProvider(com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider) JavaSourceJarsProvider(com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider) JavaSkylarkApiProvider(com.google.devtools.build.lib.rules.java.JavaSkylarkApiProvider) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) Artifact(com.google.devtools.build.lib.actions.Artifact) Runfiles(com.google.devtools.build.lib.analysis.Runfiles) JavaCompilationArgsProvider(com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) JavaRunfilesProvider(com.google.devtools.build.lib.rules.java.JavaRunfilesProvider)

Example 2 with JavaSourceJarsProvider

use of com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider 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();
}
Also used : JavaRuleOutputJarsProvider(com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider) JavaSourceJarsProvider(com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider) JavaSkylarkApiProvider(com.google.devtools.build.lib.rules.java.JavaSkylarkApiProvider) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) RunfilesProvider(com.google.devtools.build.lib.analysis.RunfilesProvider) JavaRunfilesProvider(com.google.devtools.build.lib.rules.java.JavaRunfilesProvider) Artifact(com.google.devtools.build.lib.actions.Artifact) Runfiles(com.google.devtools.build.lib.analysis.Runfiles) JavaCompilationArgsProvider(com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) JavaRunfilesProvider(com.google.devtools.build.lib.rules.java.JavaRunfilesProvider)

Example 3 with JavaSourceJarsProvider

use of com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider in project bazel by bazelbuild.

the class SkylarkJavaLiteProtoLibraryTest method testEmptySrcsForJavaApi.

@Test
public void testEmptySrcsForJavaApi() throws Exception {
    ConfiguredTarget target = scratchConfiguredTarget("notbad", "lite_pb2", "load('//tools/build_rules/java_lite_proto_library:java_lite_proto_library.bzl',", "      'java_lite_proto_library')", "java_lite_proto_library(name = 'lite_pb2', deps = [':null_lib'])", "proto_library(name = 'null_lib')");
    JavaCompilationArgsProvider compilationArgsProvider = getProvider(JavaCompilationArgsProvider.class, target);
    assertThat(compilationArgsProvider).isNotNull();
    assertThat(compilationArgsProvider.getJavaCompilationArgs()).isNotNull();
    JavaSourceJarsProvider sourceJarsProvider = getProvider(JavaSourceJarsProvider.class, target);
    assertThat(sourceJarsProvider).isNotNull();
    assertThat(sourceJarsProvider.getSourceJars()).isNotNull();
}
Also used : JavaCompilationArgsProvider(com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider) JavaSourceJarsProvider(com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Test(org.junit.Test)

Example 4 with JavaSourceJarsProvider

use of com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider in project bazel by bazelbuild.

the class SkylarkJavaLiteProtoLibraryTest method testJavacOpts.

/** Protobufs should always be compiled with the default and proto javacopts. */
@Test
public void testJavacOpts() throws Exception {
    ConfiguredTarget rule = scratchConfiguredTarget("x", "lite_pb2", "load('//tools/build_rules/java_lite_proto_library:java_lite_proto_library.bzl',", "      'java_lite_proto_library')", "java_lite_proto_library(name = 'lite_pb2', deps = [':proto_lib'])", "proto_library(name = 'proto_lib',", "              srcs = ['input1.proto', 'input2.proto'])");
    JavaCompilationArgs compilationArgs = getProvider(JavaCompilationArgsProvider.class, rule).getJavaCompilationArgs();
    assertThat(compilationArgs.getInstrumentationMetadata()).isEmpty();
    JavaSourceJarsProvider sourceJarsProvider = getProvider(JavaSourceJarsProvider.class, rule);
    assertThat(sourceJarsProvider).isNotNull();
    assertThat(prettyJarNames(sourceJarsProvider.getSourceJars())).containsExactly("x/proto_lib-lite-src.jar");
    ImmutableListMultimap<String, Artifact> runtimeJars = Multimaps.index(compilationArgs.getRuntimeJars(), ROOT_RELATIVE_PATH_STRING);
    Artifact jar = Iterables.getOnlyElement(runtimeJars.get("x/libproto_lib-lite.jar"));
    JavaCompileAction action = (JavaCompileAction) getGeneratingAction(jar);
    List<String> commandLine = ImmutableList.copyOf(action.buildCommandLine());
    assertThat(commandLine).contains("-protoMarkerForTest");
}
Also used : JavaCompilationArgsProvider(com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider) JavaSourceJarsProvider(com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider) JavaCompilationArgs(com.google.devtools.build.lib.rules.java.JavaCompilationArgs) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Artifact(com.google.devtools.build.lib.actions.Artifact) JavaCompileAction(com.google.devtools.build.lib.rules.java.JavaCompileAction) Test(org.junit.Test)

Example 5 with JavaSourceJarsProvider

use of com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider 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)

Aggregations

JavaCompilationArgsProvider (com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider)5 JavaSourceJarsProvider (com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider)5 Artifact (com.google.devtools.build.lib.actions.Artifact)3 JavaRuleOutputJarsProvider (com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider)3 JavaSkylarkApiProvider (com.google.devtools.build.lib.rules.java.JavaSkylarkApiProvider)3 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)2 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)2 Runfiles (com.google.devtools.build.lib.analysis.Runfiles)2 RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)2 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)2 JavaRunfilesProvider (com.google.devtools.build.lib.rules.java.JavaRunfilesProvider)2 Test (org.junit.Test)2 JavaCompilationArgs (com.google.devtools.build.lib.rules.java.JavaCompilationArgs)1 JavaCompileAction (com.google.devtools.build.lib.rules.java.JavaCompileAction)1 OutputJar (com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar)1 JavaRuntimeJarProvider (com.google.devtools.build.lib.rules.java.JavaRuntimeJarProvider)1