Search in sources :

Example 11 with Artifact

use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.

the class SpawnInputExpander method addRunfilesToInputs.

/** Adds runfiles inputs from runfilesSupplier to inputMappings. */
@VisibleForTesting
void addRunfilesToInputs(Map<PathFragment, ActionInput> inputMap, RunfilesSupplier runfilesSupplier, ActionInputFileCache actionFileCache) throws IOException {
    Map<PathFragment, Map<PathFragment, Artifact>> rootsAndMappings = null;
    rootsAndMappings = runfilesSupplier.getMappings();
    for (Entry<PathFragment, Map<PathFragment, Artifact>> rootAndMappings : rootsAndMappings.entrySet()) {
        PathFragment root = rootAndMappings.getKey();
        for (Entry<PathFragment, Artifact> mapping : rootAndMappings.getValue().entrySet()) {
            PathFragment targetPrefix = root.getRelative(mapping.getKey());
            Artifact localArtifact = mapping.getValue();
            if (localArtifact != null) {
                if (strict && !actionFileCache.isFile(localArtifact)) {
                    throw new IOException("Not a file: " + localArtifact.getPath().getPathString());
                }
                addMapping(inputMap, targetPrefix, localArtifact);
            } else {
                addMapping(inputMap, targetPrefix, EMPTY_FILE);
            }
        }
    }
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment) IOException(java.io.IOException) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap) Artifact(com.google.devtools.build.lib.actions.Artifact) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 12 with Artifact

use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.

the class ActionsTestUtil method findTransitivePrerequisitesOf.

/**
   * Finds all the actions that are instances of <code>actionClass</code>
   * in the transitive closure of prerequisites.
   */
public <A extends Action> List<A> findTransitivePrerequisitesOf(Artifact artifact, Class<A> actionClass, Predicate<Artifact> allowedArtifacts) {
    List<A> actions = new ArrayList<>();
    Set<Artifact> visited = new LinkedHashSet<>();
    List<Artifact> toVisit = new LinkedList<>();
    toVisit.add(artifact);
    while (!toVisit.isEmpty()) {
        Artifact current = toVisit.remove(0);
        if (!visited.add(current)) {
            continue;
        }
        ActionAnalysisMetadata generatingAction = actionGraph.getGeneratingAction(current);
        if (generatingAction != null) {
            Iterables.addAll(toVisit, Iterables.filter(generatingAction.getInputs(), allowedArtifacts));
            if (actionClass.isInstance(generatingAction)) {
                actions.add(actionClass.cast(generatingAction));
            }
        }
    }
    return actions;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) LinkedList(java.util.LinkedList)

Example 13 with Artifact

use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.

the class SkylarkRuleImplementationFunctionsTest method testResolveCommandInputs.

@Test
public void testResolveCommandInputs() throws Exception {
    evalRuleContextCode(createRuleContext("//foo:resolve_me"), "inputs, argv, input_manifests = ruleContext.resolve_command(", "   tools=ruleContext.attr.tools)");
    @SuppressWarnings("unchecked") List<Artifact> inputs = (List<Artifact>) (List<?>) (MutableList) lookup("inputs");
    assertArtifactFilenames(inputs, "mytool.sh", "mytool", "foo_Smytool-runfiles", "t.exe");
    @SuppressWarnings("unchecked") CompositeRunfilesSupplier runfilesSupplier = new CompositeRunfilesSupplier((List<RunfilesSupplier>) lookup("input_manifests"));
    assertThat(runfilesSupplier.getMappings()).hasSize(1);
}
Also used : CompositeRunfilesSupplier(com.google.devtools.build.lib.actions.CompositeRunfilesSupplier) MutableList(com.google.devtools.build.lib.syntax.SkylarkList.MutableList) MutableList(com.google.devtools.build.lib.syntax.SkylarkList.MutableList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Artifact(com.google.devtools.build.lib.actions.Artifact) RunfilesSupplier(com.google.devtools.build.lib.actions.RunfilesSupplier) CompositeRunfilesSupplier(com.google.devtools.build.lib.actions.CompositeRunfilesSupplier) Test(org.junit.Test)

Example 14 with Artifact

use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.

the class SkylarkRuleContextTest method testParamFileLegacy.

@Test
public void testParamFileLegacy() throws Exception {
    SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
    Object result = evalRuleContextCode(ruleContext, "ruleContext.new_file(ruleContext.bin_dir," + "ruleContext.files.tools[0], '.params')");
    PathFragment fragment = ((Artifact) result).getRootRelativePath();
    assertEquals("foo/t.exe.params", fragment.getPathString());
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment) SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 15 with Artifact

use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.

the class CcBinary method collectRunfiles.

private static Runfiles collectRunfiles(RuleContext context, CcToolchainProvider toolchain, CcLinkingOutputs linkingOutputs, CcLibraryHelper.Info info, LinkStaticness linkStaticness, NestedSet<Artifact> filesToBuild, Iterable<Artifact> fakeLinkerInputs, boolean fake, ImmutableSet<CppSource> cAndCppSources, boolean linkCompileOutputSeparately) {
    Runfiles.Builder builder = new Runfiles.Builder(context.getWorkspaceName(), context.getConfiguration().legacyExternalRunfiles());
    Function<TransitiveInfoCollection, Runfiles> runfilesMapping = CppRunfilesProvider.runfilesFunction(linkStaticness != LinkStaticness.DYNAMIC);
    builder.addTransitiveArtifacts(filesToBuild);
    // Add the shared libraries to the runfiles. This adds any shared libraries that are in the
    // srcs of this target.
    builder.addArtifacts(linkingOutputs.getLibrariesForRunfiles(true));
    builder.addRunfiles(context, RunfilesProvider.DEFAULT_RUNFILES);
    builder.add(context, runfilesMapping);
    // Add the C++ runtime libraries if linking them dynamically.
    if (linkStaticness == LinkStaticness.DYNAMIC) {
        builder.addTransitiveArtifacts(toolchain.getDynamicRuntimeLinkInputs());
    }
    if (linkCompileOutputSeparately) {
        builder.addArtifacts(LinkerInputs.toLibraryArtifacts(info.getCcLinkingOutputs().getExecutionDynamicLibraries()));
    }
    // For cc_binary and cc_test rules, there is an implicit dependency on
    // the malloc library package, which is specified by the "malloc" attribute.
    // As the BUILD encyclopedia says, the "malloc" attribute should be ignored
    // if linkshared=1.
    boolean linkshared = isLinkShared(context);
    if (!linkshared) {
        TransitiveInfoCollection malloc = CppHelper.mallocForTarget(context);
        builder.addTarget(malloc, RunfilesProvider.DEFAULT_RUNFILES);
        builder.addTarget(malloc, runfilesMapping);
    }
    if (fake) {
        // Add the object files, libraries, and linker scripts that are used to
        // link this executable.
        builder.addSymlinksToArtifacts(Iterables.filter(fakeLinkerInputs, Artifact.MIDDLEMAN_FILTER));
        // The crosstool inputs for the link action are not sufficient; we also need the crosstool
        // inputs for compilation. Node that these cannot be middlemen because Runfiles does not
        // know how to expand them.
        builder.addTransitiveArtifacts(toolchain.getCrosstool());
        builder.addTransitiveArtifacts(toolchain.getLibcLink());
        // Add the sources files that are used to compile the object files.
        // We add the headers in the transitive closure and our own sources in the srcs
        // attribute. We do not provide the auxiliary inputs, because they are only used when we
        // do FDO compilation, and cc_fake_binary does not support FDO.
        ImmutableSet.Builder<Artifact> sourcesBuilder = ImmutableSet.<Artifact>builder();
        for (CppSource cppSource : cAndCppSources) {
            sourcesBuilder.add(cppSource.getSource());
        }
        builder.addSymlinksToArtifacts(sourcesBuilder.build());
        CppCompilationContext cppCompilationContext = info.getCppCompilationContext();
        builder.addSymlinksToArtifacts(cppCompilationContext.getDeclaredIncludeSrcs());
        // Add additional files that are referenced from the compile command, like module maps
        // or header modules.
        builder.addSymlinksToArtifacts(cppCompilationContext.getAdditionalInputs());
        builder.addSymlinksToArtifacts(cppCompilationContext.getTransitiveModules(CppHelper.usePic(context, !isLinkShared(context))));
    }
    return builder.build();
}
Also used : Runfiles(com.google.devtools.build.lib.analysis.Runfiles) ImmutableSet(com.google.common.collect.ImmutableSet) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) Artifact(com.google.devtools.build.lib.actions.Artifact)

Aggregations

Artifact (com.google.devtools.build.lib.actions.Artifact)659 Test (org.junit.Test)242 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)184 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)83 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)65 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)64 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)51 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)50 ImmutableList (com.google.common.collect.ImmutableList)46 Action (com.google.devtools.build.lib.actions.Action)42 IOException (java.io.IOException)42 ArrayList (java.util.ArrayList)40 SpawnAction (com.google.devtools.build.lib.analysis.actions.SpawnAction)38 Path (com.google.devtools.build.lib.vfs.Path)37 HashMap (java.util.HashMap)37 Map (java.util.Map)36 Root (com.google.devtools.build.lib.actions.Root)31 LinkedHashMap (java.util.LinkedHashMap)31 ImmutableMap (com.google.common.collect.ImmutableMap)28 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)28