Search in sources :

Example 1 with JavaRuleOutputJarsProvider

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

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

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

the class AndroidStudioInfoAspect method createIdeBuildArtifact.

private AndroidStudioInfoFilesProvider createIdeBuildArtifact(ConfiguredTarget base, RuleContext ruleContext, DependenciesResult dependenciesResult, AndroidStudioInfoFilesProvider.Builder providerBuilder) {
    Artifact ideInfoFile = derivedArtifact(base, ruleContext, ASWB_BUILD_SUFFIX);
    Artifact ideInfoTextFile = derivedArtifact(base, ruleContext, ASWB_BUILD_TEXT_SUFFIX);
    providerBuilder.ideInfoFilesBuilder().add(ideInfoFile);
    providerBuilder.ideInfoTextFilesBuilder().add(ideInfoTextFile);
    NestedSetBuilder<Artifact> ideResolveArtifacts = providerBuilder.ideResolveFilesBuilder();
    TargetIdeInfo.Builder outputBuilder = TargetIdeInfo.newBuilder();
    outputBuilder.setLabel(base.getLabel().toString());
    outputBuilder.setBuildFileArtifactLocation(makeArtifactLocation(ruleContext.getRule().getPackage(), ruleContext.getLabel()));
    outputBuilder.setKindString(ruleContext.getRule().getRuleClass());
    // Java rules
    JavaRuleOutputJarsProvider outputJarsProvider = JavaProvider.getProvider(JavaRuleOutputJarsProvider.class, base);
    if (outputJarsProvider != null && !androidStudioInfoSemantics.suppressJavaRuleInfo(base)) {
        JavaIdeInfo javaIdeInfo = makeJavaIdeInfo(base, ruleContext, outputJarsProvider, providerBuilder);
        outputBuilder.setJavaIdeInfo(javaIdeInfo);
    }
    // C rules
    if (isCppRule(base)) {
        CppCompilationContext cppCompilationContext = base.getProvider(CppCompilationContext.class);
        if (cppCompilationContext != null) {
            CIdeInfo cIdeInfo = makeCIdeInfo(base, ruleContext, cppCompilationContext, ideResolveArtifacts);
            outputBuilder.setCIdeInfo(cIdeInfo);
        }
    }
    // CCToolchain rule
    CcToolchainProvider ccToolchainProvider = base.getProvider(CcToolchainProvider.class);
    if (ccToolchainProvider != null) {
        CppConfiguration cppConfiguration = ccToolchainProvider.getCppConfiguration();
        if (cppConfiguration != null) {
            CToolchainIdeInfo cToolchainIdeInfo = makeCToolchainIdeInfo(ruleContext, cppConfiguration);
            if (cToolchainIdeInfo != null) {
                outputBuilder.setCToolchainIdeInfo(cToolchainIdeInfo);
            }
        }
    }
    // Android rules
    AndroidIdeInfoProvider androidIdeInfoProvider = base.getProvider(AndroidIdeInfoProvider.class);
    if (androidIdeInfoProvider != null) {
        outputBuilder.setAndroidIdeInfo(makeAndroidIdeInfo(androidIdeInfoProvider, dependenciesResult, ideResolveArtifacts));
    }
    // Python rules
    if (isPythonRule(base)) {
        outputBuilder.setPyIdeInfo(makePyIdeInfo(base, ruleContext, ideResolveArtifacts));
    }
    // Test rules
    if (TargetUtils.isTestRule(base.getTarget())) {
        TestInfo.Builder builder = TestInfo.newBuilder();
        String attr = NonconfigurableAttributeMapper.of(base.getTarget().getAssociatedRule()).get("size", Type.STRING);
        if (attr != null) {
            builder.setSize(attr);
        }
        outputBuilder.setTestInfo(builder);
    }
    // Java toolchain rule
    JavaToolchainProvider javaToolchainProvider = base.getProvider(JavaToolchainProvider.class);
    if (javaToolchainProvider != null) {
        outputBuilder.setJavaToolchainIdeInfo(JavaToolchainIdeInfo.newBuilder().setSourceVersion(javaToolchainProvider.getSourceVersion()).setTargetVersion(javaToolchainProvider.getTargetVersion()));
    }
    androidStudioInfoSemantics.augmentRuleInfo(outputBuilder, base, ruleContext, ideResolveArtifacts);
    AndroidStudioInfoFilesProvider provider = providerBuilder.build();
    outputBuilder.addAllDependencies(transform(dependenciesResult.deps, LABEL_TO_STRING));
    outputBuilder.addAllRuntimeDeps(transform(dependenciesResult.runtimeDeps, LABEL_TO_STRING));
    outputBuilder.addAllTags(base.getTarget().getAssociatedRule().getRuleTags());
    final TargetIdeInfo targetIdeInfo = outputBuilder.build();
    ruleContext.registerAction(makeProtoWriteAction(ruleContext.getActionOwner(), targetIdeInfo, ideInfoFile));
    ruleContext.registerAction(makeProtoTextWriteAction(ruleContext.getActionOwner(), targetIdeInfo, ideInfoTextFile));
    return provider;
}
Also used : JavaRuleOutputJarsProvider(com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider) CcToolchainProvider(com.google.devtools.build.lib.rules.cpp.CcToolchainProvider) Artifact(com.google.devtools.build.lib.actions.Artifact) LibraryArtifact(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.LibraryArtifact) TargetIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo) CppCompilationContext(com.google.devtools.build.lib.rules.cpp.CppCompilationContext) CToolchainIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CToolchainIdeInfo) CppConfiguration(com.google.devtools.build.lib.rules.cpp.CppConfiguration) JavaToolchainProvider(com.google.devtools.build.lib.rules.java.JavaToolchainProvider) AndroidIdeInfoProvider(com.google.devtools.build.lib.rules.android.AndroidIdeInfoProvider) CIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CIdeInfo) TestInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TestInfo) JavaIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.JavaIdeInfo)

Example 4 with JavaRuleOutputJarsProvider

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

JavaRuleOutputJarsProvider (com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider)4 Artifact (com.google.devtools.build.lib.actions.Artifact)3 JavaCompilationArgsProvider (com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider)3 JavaSkylarkApiProvider (com.google.devtools.build.lib.rules.java.JavaSkylarkApiProvider)3 JavaSourceJarsProvider (com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider)3 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 AndroidIdeInfoProvider (com.google.devtools.build.lib.rules.android.AndroidIdeInfoProvider)1 CcToolchainProvider (com.google.devtools.build.lib.rules.cpp.CcToolchainProvider)1 CppCompilationContext (com.google.devtools.build.lib.rules.cpp.CppCompilationContext)1 CppConfiguration (com.google.devtools.build.lib.rules.cpp.CppConfiguration)1 OutputJar (com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar)1 JavaRuntimeJarProvider (com.google.devtools.build.lib.rules.java.JavaRuntimeJarProvider)1 JavaToolchainProvider (com.google.devtools.build.lib.rules.java.JavaToolchainProvider)1 CIdeInfo (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CIdeInfo)1 CToolchainIdeInfo (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CToolchainIdeInfo)1 JavaIdeInfo (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.JavaIdeInfo)1