use of com.google.devtools.build.lib.analysis.Runfiles in project bazel by bazelbuild.
the class ShLibrary method create.
@Override
public ConfiguredTarget create(RuleContext ruleContext) throws RuleErrorException {
NestedSet<Artifact> filesToBuild = NestedSetBuilder.<Artifact>stableOrder().addAll(ruleContext.getPrerequisiteArtifacts("srcs", Mode.TARGET).list()).addAll(ruleContext.getPrerequisiteArtifacts("deps", Mode.TARGET).list()).addAll(ruleContext.getPrerequisiteArtifacts("data", Mode.DATA).list()).build();
Runfiles runfiles = new Runfiles.Builder(ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles()).addTransitiveArtifacts(filesToBuild).build();
return new RuleConfiguredTargetBuilder(ruleContext).setFilesToBuild(filesToBuild).addProvider(RunfilesProvider.class, RunfilesProvider.simple(runfiles)).build();
}
use of com.google.devtools.build.lib.analysis.Runfiles in project bazel by bazelbuild.
the class PyBinary method init.
static RuleConfiguredTargetBuilder init(RuleContext ruleContext, PythonSemantics semantics, PyCommon common) throws InterruptedException {
CcLinkParamsStore ccLinkParamsStore = initializeCcLinkParamStore(ruleContext);
List<Artifact> srcs = common.validateSrcs();
List<Artifact> allOutputs = new ArrayList<>(semantics.precompiledPythonFiles(ruleContext, srcs, common));
if (ruleContext.hasErrors()) {
return null;
}
common.initBinary(allOutputs);
semantics.validate(ruleContext, common);
if (ruleContext.hasErrors()) {
return null;
}
NestedSet<PathFragment> imports = common.collectImports(ruleContext, semantics);
if (ruleContext.hasErrors()) {
return null;
}
semantics.createExecutable(ruleContext, common, ccLinkParamsStore, imports);
Runfiles commonRunfiles = collectCommonRunfiles(ruleContext, common, semantics);
Runfiles.Builder defaultRunfilesBuilder = new Runfiles.Builder(ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles()).merge(commonRunfiles);
semantics.collectDefaultRunfilesForBinary(ruleContext, defaultRunfilesBuilder);
Runfiles defaultRunfiles = defaultRunfilesBuilder.build();
RunfilesSupport runfilesSupport = RunfilesSupport.withExecutable(ruleContext, defaultRunfiles, common.getExecutable(), ruleContext.shouldCreateRunfilesSymlinks());
if (ruleContext.hasErrors()) {
return null;
}
// Only include common runfiles and middleman. Default runfiles added by semantics are
// excluded. The middleman is necessary to ensure the runfiles trees are generated for all
// dependency binaries.
Runfiles dataRunfiles = new Runfiles.Builder(ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles()).merge(commonRunfiles).addArtifact(runfilesSupport.getRunfilesMiddleman()).build();
RunfilesProvider runfilesProvider = RunfilesProvider.withData(defaultRunfiles, dataRunfiles);
RuleConfiguredTargetBuilder builder = new RuleConfiguredTargetBuilder(ruleContext);
common.addCommonTransitiveInfoProviders(builder, semantics, common.getFilesToBuild());
semantics.postInitBinary(ruleContext, runfilesSupport, common);
return builder.setFilesToBuild(common.getFilesToBuild()).add(RunfilesProvider.class, runfilesProvider).setRunfilesSupport(runfilesSupport, common.getExecutable()).add(CcLinkParamsProvider.class, new CcLinkParamsProvider(ccLinkParamsStore)).add(PythonImportsProvider.class, new PythonImportsProvider(imports));
}
use of com.google.devtools.build.lib.analysis.Runfiles in project bazel by bazelbuild.
the class SpawnInputExpanderTest method testRunfilesSymlink.
@Test
public void testRunfilesSymlink() throws Exception {
Artifact artifact = new Artifact(fs.getPath("/root/dir/file"), Root.asSourceRoot(fs.getPath("/root")));
Runfiles runfiles = new Runfiles.Builder("workspace").addSymlink(new PathFragment("symlink"), artifact).build();
RunfilesSupplier supplier = new RunfilesSupplierImpl(new PathFragment("runfiles"), runfiles);
ActionInputFileCache mockCache = Mockito.mock(ActionInputFileCache.class);
Mockito.when(mockCache.isFile(artifact)).thenReturn(true);
expander.addRunfilesToInputs(inputMappings, supplier, mockCache);
assertThat(inputMappings).hasSize(1);
assertThat(inputMappings).containsEntry(new PathFragment("runfiles/workspace/symlink"), artifact);
}
use of com.google.devtools.build.lib.analysis.Runfiles in project bazel by bazelbuild.
the class SpawnInputExpanderTest method testRunfilesRootSymlink.
@Test
public void testRunfilesRootSymlink() throws Exception {
Artifact artifact = new Artifact(fs.getPath("/root/dir/file"), Root.asSourceRoot(fs.getPath("/root")));
Runfiles runfiles = new Runfiles.Builder("workspace").addRootSymlink(new PathFragment("symlink"), artifact).build();
RunfilesSupplier supplier = new RunfilesSupplierImpl(new PathFragment("runfiles"), runfiles);
ActionInputFileCache mockCache = Mockito.mock(ActionInputFileCache.class);
Mockito.when(mockCache.isFile(artifact)).thenReturn(true);
expander.addRunfilesToInputs(inputMappings, supplier, mockCache);
assertThat(inputMappings).hasSize(2);
assertThat(inputMappings).containsEntry(new PathFragment("runfiles/symlink"), artifact);
// If there's no other entry, Runfiles adds an empty file in the workspace to make sure the
// directory gets created.
assertThat(inputMappings).containsEntry(new PathFragment("runfiles/workspace/.runfile"), SpawnInputExpander.EMPTY_FILE);
}
use of com.google.devtools.build.lib.analysis.Runfiles in project bazel by bazelbuild.
the class SpawnInputExpanderTest method testRunfilesDirectoryNonStrict.
@Test
public void testRunfilesDirectoryNonStrict() throws Exception {
Artifact artifact = new Artifact(fs.getPath("/root/dir/file"), Root.asSourceRoot(fs.getPath("/root")));
Runfiles runfiles = new Runfiles.Builder("workspace").addArtifact(artifact).build();
RunfilesSupplier supplier = new RunfilesSupplierImpl(new PathFragment("runfiles"), runfiles);
ActionInputFileCache mockCache = Mockito.mock(ActionInputFileCache.class);
Mockito.when(mockCache.isFile(artifact)).thenReturn(false);
expander = new SpawnInputExpander(/*strict=*/
false);
expander.addRunfilesToInputs(inputMappings, supplier, mockCache);
assertThat(inputMappings).hasSize(1);
assertThat(inputMappings).containsEntry(new PathFragment("runfiles/workspace/dir/file"), artifact);
}
Aggregations