Search in sources :

Example 11 with Runfiles

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();
}
Also used : Runfiles(com.google.devtools.build.lib.analysis.Runfiles) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) RunfilesProvider(com.google.devtools.build.lib.analysis.RunfilesProvider) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 12 with Runfiles

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));
}
Also used : CcLinkParamsProvider(com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider) CcLinkParamsStore(com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore) ArrayList(java.util.ArrayList) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RunfilesProvider(com.google.devtools.build.lib.analysis.RunfilesProvider) Artifact(com.google.devtools.build.lib.actions.Artifact) Runfiles(com.google.devtools.build.lib.analysis.Runfiles) RunfilesSupport(com.google.devtools.build.lib.analysis.RunfilesSupport) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)

Example 13 with Runfiles

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);
}
Also used : Runfiles(com.google.devtools.build.lib.analysis.Runfiles) ActionInputFileCache(com.google.devtools.build.lib.actions.ActionInputFileCache) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RunfilesSupplierImpl(com.google.devtools.build.lib.analysis.RunfilesSupplierImpl) Artifact(com.google.devtools.build.lib.actions.Artifact) EmptyRunfilesSupplier(com.google.devtools.build.lib.actions.EmptyRunfilesSupplier) RunfilesSupplier(com.google.devtools.build.lib.actions.RunfilesSupplier) Test(org.junit.Test)

Example 14 with Runfiles

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);
}
Also used : Runfiles(com.google.devtools.build.lib.analysis.Runfiles) ActionInputFileCache(com.google.devtools.build.lib.actions.ActionInputFileCache) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RunfilesSupplierImpl(com.google.devtools.build.lib.analysis.RunfilesSupplierImpl) Artifact(com.google.devtools.build.lib.actions.Artifact) EmptyRunfilesSupplier(com.google.devtools.build.lib.actions.EmptyRunfilesSupplier) RunfilesSupplier(com.google.devtools.build.lib.actions.RunfilesSupplier) Test(org.junit.Test)

Example 15 with Runfiles

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);
}
Also used : Runfiles(com.google.devtools.build.lib.analysis.Runfiles) ActionInputFileCache(com.google.devtools.build.lib.actions.ActionInputFileCache) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RunfilesSupplierImpl(com.google.devtools.build.lib.analysis.RunfilesSupplierImpl) Artifact(com.google.devtools.build.lib.actions.Artifact) EmptyRunfilesSupplier(com.google.devtools.build.lib.actions.EmptyRunfilesSupplier) RunfilesSupplier(com.google.devtools.build.lib.actions.RunfilesSupplier) Test(org.junit.Test)

Aggregations

Runfiles (com.google.devtools.build.lib.analysis.Runfiles)28 Artifact (com.google.devtools.build.lib.actions.Artifact)24 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)15 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)11 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)10 RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)9 RunfilesSupplierImpl (com.google.devtools.build.lib.analysis.RunfilesSupplierImpl)7 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)7 Test (org.junit.Test)7 ActionInputFileCache (com.google.devtools.build.lib.actions.ActionInputFileCache)6 EmptyRunfilesSupplier (com.google.devtools.build.lib.actions.EmptyRunfilesSupplier)6 RunfilesSupplier (com.google.devtools.build.lib.actions.RunfilesSupplier)6 RunfilesSupport (com.google.devtools.build.lib.analysis.RunfilesSupport)6 ArrayList (java.util.ArrayList)5 ImmutableMap (com.google.common.collect.ImmutableMap)3 SkylarkClassObject (com.google.devtools.build.lib.packages.SkylarkClassObject)3 LibraryToLink (com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink)3 InstrumentedFilesProvider (com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider)3 Label (com.google.devtools.build.lib.cmdline.Label)2 NestedSet (com.google.devtools.build.lib.collect.nestedset.NestedSet)2