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);
}
}
}
}
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;
}
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);
}
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());
}
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();
}
Aggregations