Search in sources :

Example 46 with TransitiveInfoCollection

use of com.google.devtools.build.lib.analysis.TransitiveInfoCollection in project bazel by bazelbuild.

the class JavaCommon method getRunfiles.

public static Runfiles getRunfiles(RuleContext ruleContext, JavaSemantics semantics, JavaCompilationArtifacts javaArtifacts, boolean neverLink) {
    // runfiles from this target or its dependencies.
    if (neverLink) {
        return Runfiles.EMPTY;
    }
    Runfiles.Builder runfilesBuilder = new Runfiles.Builder(ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles()).addArtifacts(javaArtifacts.getRuntimeJars());
    runfilesBuilder.addRunfiles(ruleContext, RunfilesProvider.DEFAULT_RUNFILES);
    runfilesBuilder.add(ruleContext, JavaRunfilesProvider.TO_RUNFILES);
    List<TransitiveInfoCollection> depsForRunfiles = new ArrayList<>();
    if (ruleContext.getRule().isAttrDefined("runtime_deps", BuildType.LABEL_LIST)) {
        depsForRunfiles.addAll(ruleContext.getPrerequisites("runtime_deps", Mode.TARGET));
    }
    if (ruleContext.getRule().isAttrDefined("exports", BuildType.LABEL_LIST)) {
        depsForRunfiles.addAll(ruleContext.getPrerequisites("exports", Mode.TARGET));
    }
    runfilesBuilder.addTargets(depsForRunfiles, RunfilesProvider.DEFAULT_RUNFILES);
    runfilesBuilder.addTargets(depsForRunfiles, JavaRunfilesProvider.TO_RUNFILES);
    TransitiveInfoCollection launcher = JavaHelper.launcherForTarget(semantics, ruleContext);
    if (launcher != null) {
        runfilesBuilder.addTarget(launcher, RunfilesProvider.DATA_RUNFILES);
    }
    semantics.addRunfilesForLibrary(ruleContext, runfilesBuilder);
    return runfilesBuilder.build();
}
Also used : Runfiles(com.google.devtools.build.lib.analysis.Runfiles) ArrayList(java.util.ArrayList) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection)

Example 47 with TransitiveInfoCollection

use of com.google.devtools.build.lib.analysis.TransitiveInfoCollection in project bazel by bazelbuild.

the class JavaCompilationHelper method addLibrariesToAttributes.

/**
   * Adds the compile time and runtime Java libraries in the transitive closure
   * of the deps to the attributes.
   *
   * @param deps the dependencies to be included as roots of the transitive
   *        closure
   */
public void addLibrariesToAttributes(Iterable<? extends TransitiveInfoCollection> deps) {
    // Enforcing strict Java dependencies: when the --strict_java_deps flag is
    // WARN or ERROR, or is DEFAULT and strict_java_deps attribute is unset,
    // we use a stricter javac compiler to perform direct deps checks.
    attributes.setStrictJavaDeps(getStrictJavaDeps());
    addLibrariesToAttributesInternal(deps);
    JavaClasspathMode classpathMode = getJavaConfiguration().getReduceJavaClasspath();
    if (isStrict() && classpathMode != JavaClasspathMode.OFF) {
        List<JavaCompilationArgsProvider> compilationArgsProviders = new LinkedList<>();
        for (TransitiveInfoCollection dep : deps) {
            JavaCompilationArgsProvider provider = JavaProvider.getProvider(JavaCompilationArgsProvider.class, dep);
            if (provider != null) {
                compilationArgsProviders.add(provider);
            }
        }
        addDependencyArtifactsToAttributes(attributes, compilationArgsProviders);
    }
}
Also used : JavaClasspathMode(com.google.devtools.build.lib.rules.java.JavaConfiguration.JavaClasspathMode) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) LinkedList(java.util.LinkedList)

Example 48 with TransitiveInfoCollection

use of com.google.devtools.build.lib.analysis.TransitiveInfoCollection in project bazel by bazelbuild.

the class TestSuite method create.

@Override
public ConfiguredTarget create(RuleContext ruleContext) throws RuleErrorException {
    checkTestsAndSuites(ruleContext, "tests");
    if (ruleContext.hasErrors()) {
        return null;
    }
    //
    //  CAUTION!  Keep this logic consistent with lib.query2.TestsExpression!
    //
    List<String> tagsAttribute = new ArrayList<>(ruleContext.attributes().get("tags", Type.STRING_LIST));
    tagsAttribute.remove("manual");
    Pair<Collection<String>, Collection<String>> requiredExcluded = TestTargetUtils.sortTagsBySense(tagsAttribute);
    List<TransitiveInfoCollection> directTestsAndSuitesBuilder = new ArrayList<>();
    // Manual tests are already filtered out there. That is what $implicit_tests is about.
    for (TransitiveInfoCollection dep : Iterables.concat(getPrerequisites(ruleContext, "tests"), getPrerequisites(ruleContext, "$implicit_tests"))) {
        if (dep.getProvider(TestProvider.class) != null) {
            List<String> tags = dep.getProvider(TestProvider.class).getTestTags();
            if (!TestTargetUtils.testMatchesFilters(tags, requiredExcluded.first, requiredExcluded.second, true)) {
                // This test does not match our filter. Ignore it.
                continue;
            }
        }
        directTestsAndSuitesBuilder.add(dep);
    }
    Runfiles runfiles = new Runfiles.Builder(ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles()).addTargets(directTestsAndSuitesBuilder, RunfilesProvider.DATA_RUNFILES).build();
    return new RuleConfiguredTargetBuilder(ruleContext).add(RunfilesProvider.class, RunfilesProvider.withData(Runfiles.EMPTY, runfiles)).add(TransitiveTestsProvider.class, new TransitiveTestsProvider()).build();
}
Also used : Runfiles(com.google.devtools.build.lib.analysis.Runfiles) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) ArrayList(java.util.ArrayList) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) Collection(java.util.Collection) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection)

Example 49 with TransitiveInfoCollection

use of com.google.devtools.build.lib.analysis.TransitiveInfoCollection in project bazel by bazelbuild.

the class TestSuite method checkTestsAndSuites.

private void checkTestsAndSuites(RuleContext ruleContext, String attributeName) {
    if (!ruleContext.attributes().has(attributeName, BuildType.LABEL_LIST)) {
        return;
    }
    for (TransitiveInfoCollection dep : ruleContext.getPrerequisites(attributeName, Mode.TARGET)) {
        // TODO(bazel-team): Maybe convert the TransitiveTestsProvider into an inner interface.
        TransitiveTestsProvider provider = dep.getProvider(TransitiveTestsProvider.class);
        TestProvider testProvider = dep.getProvider(TestProvider.class);
        if (provider == null && testProvider == null) {
            ruleContext.attributeError(attributeName, "expecting a test or a test_suite rule but '" + dep.getLabel() + "' is not one");
        }
    }
}
Also used : TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection)

Example 50 with TransitiveInfoCollection

use of com.google.devtools.build.lib.analysis.TransitiveInfoCollection in project bazel by bazelbuild.

the class MultiArchBinarySupport method registerActions.

/**
   * Registers actions to create a multi-arch Apple binary.
   *
   * @param platform the platform for which the binary is targeted
   * @param extraLinkArgs the extra linker args to add to link actions linking single-architecture
   *     binaries together
   * @param configurationToObjcProvider a map from from dependency configuration to the
   *     {@link ObjcProvider} which comprises all information about the dependencies in that
   *     configuration. Can be obtained via {@link #objcProviderByDepConfiguration}
   * @param extraLinkInputs the extra linker inputs to be made available during link actions
   * @param configToDepsCollectionMap a multimap from dependency configuration to the
   *     list of provider collections which are propagated from the dependencies of that
   *     configuration
   * @param outputLipoBinary the artifact (lipo'ed binary) which should be output as a result of
   *     this support
   * @throws RuleErrorException if there are attribute errors in the current rule context
   */
public void registerActions(Platform platform, ExtraLinkArgs extraLinkArgs, Map<BuildConfiguration, ObjcProvider> configurationToObjcProvider, Iterable<Artifact> extraLinkInputs, ImmutableListMultimap<BuildConfiguration, TransitiveInfoCollection> configToDepsCollectionMap, Artifact outputLipoBinary) throws RuleErrorException, InterruptedException {
    NestedSetBuilder<Artifact> binariesToLipo = NestedSetBuilder.<Artifact>stableOrder();
    for (BuildConfiguration childConfig : configurationToObjcProvider.keySet()) {
        IntermediateArtifacts intermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext, childConfig);
        ImmutableList.Builder<J2ObjcMappingFileProvider> j2ObjcMappingFileProviders = ImmutableList.builder();
        J2ObjcEntryClassProvider.Builder j2ObjcEntryClassProviderBuilder = new J2ObjcEntryClassProvider.Builder();
        for (TransitiveInfoCollection dep : configToDepsCollectionMap.get(childConfig)) {
            if (dep.getProvider(J2ObjcMappingFileProvider.class) != null) {
                j2ObjcMappingFileProviders.add(dep.getProvider(J2ObjcMappingFileProvider.class));
            }
            if (dep.getProvider(J2ObjcEntryClassProvider.class) != null) {
                j2ObjcEntryClassProviderBuilder.addTransitive(dep.getProvider(J2ObjcEntryClassProvider.class));
            }
        }
        J2ObjcMappingFileProvider j2ObjcMappingFileProvider = J2ObjcMappingFileProvider.union(j2ObjcMappingFileProviders.build());
        J2ObjcEntryClassProvider j2ObjcEntryClassProvider = j2ObjcEntryClassProviderBuilder.build();
        binariesToLipo.add(intermediateArtifacts.strippedSingleArchitectureBinary());
        ObjcProvider objcProvider = configurationToObjcProvider.get(childConfig);
        CompilationArtifacts compilationArtifacts = CompilationSupport.compilationArtifacts(ruleContext, ObjcRuleClasses.intermediateArtifacts(ruleContext, childConfig));
        CompilationSupport.createForConfig(ruleContext, childConfig).registerCompileAndArchiveActions(compilationArtifacts, objcProvider).registerLinkActions(objcProvider, j2ObjcMappingFileProvider, j2ObjcEntryClassProvider, extraLinkArgs, extraLinkInputs, DsymOutputType.APP).validateAttributes();
        ruleContext.assertNoErrors();
    }
    new LipoSupport(ruleContext).registerCombineArchitecturesAction(binariesToLipo.build(), outputLipoBinary, platform);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) Artifact(com.google.devtools.build.lib.actions.Artifact) BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection)

Aggregations

TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)54 Artifact (com.google.devtools.build.lib.actions.Artifact)27 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)14 FileProvider (com.google.devtools.build.lib.analysis.FileProvider)11 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)11 Label (com.google.devtools.build.lib.cmdline.Label)10 ImmutableList (com.google.common.collect.ImmutableList)8 ArrayList (java.util.ArrayList)8 Runfiles (com.google.devtools.build.lib.analysis.Runfiles)7 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)5 Test (org.junit.Test)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 FilesToRunProvider (com.google.devtools.build.lib.analysis.FilesToRunProvider)4 RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)4 SkylarkClassObject (com.google.devtools.build.lib.packages.SkylarkClassObject)4 Pair (com.google.devtools.build.lib.util.Pair)4 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)4 Map (java.util.Map)4 CustomCommandLine (com.google.devtools.build.lib.analysis.actions.CustomCommandLine)3 CcLinkParamsProvider (com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider)3