Search in sources :

Example 21 with FilesToRunProvider

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

the class RunCommand method ensureRunfilesBuilt.

/**
   * Ensures that runfiles are built for the specified target. If they already
   * are, does nothing, otherwise builds them.
   *
   * @param target the target to build runfiles for.
   * @return the path of the runfiles directory.
   * @throws CommandException
   */
private Path ensureRunfilesBuilt(CommandEnvironment env, ConfiguredTarget target) throws CommandException {
    FilesToRunProvider provider = target.getProvider(FilesToRunProvider.class);
    RunfilesSupport runfilesSupport = provider == null ? null : provider.getRunfilesSupport();
    if (runfilesSupport == null) {
        return env.getWorkingDirectory();
    }
    Artifact manifest = runfilesSupport.getRunfilesManifest();
    PathFragment runfilesDir = runfilesSupport.getRunfilesDirectoryExecPath();
    Path workingDir = env.getExecRoot().getRelative(runfilesDir);
    // Workspace name directory doesn't exist, so don't add it.
    if (target.getConfiguration().runfilesEnabled()) {
        workingDir = workingDir.getRelative(runfilesSupport.getRunfiles().getSuffix());
    }
    // a handy way to check whether runfiles were built or not.
    if (!RUNFILES_MANIFEST.matches(manifest.getFilename())) {
        // Runfiles already built, nothing to do.
        return workingDir;
    }
    SymlinkTreeHelper helper = new SymlinkTreeHelper(manifest.getPath(), runfilesSupport.getRunfilesDirectory(), false);
    helper.createSymlinksUsingCommand(env.getExecRoot(), target.getConfiguration(), env.getBlazeWorkspace().getBinTools());
    return workingDir;
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) FilesToRunProvider(com.google.devtools.build.lib.analysis.FilesToRunProvider) SymlinkTreeHelper(com.google.devtools.build.lib.exec.SymlinkTreeHelper) RunfilesSupport(com.google.devtools.build.lib.analysis.RunfilesSupport) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 22 with FilesToRunProvider

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

the class PopulateTreeArtifactActionTest method testComputeKey.

@Test
public void testComputeKey() throws Exception {
    final Artifact archiveA = getSourceArtifact("myArchiveA.zip");
    final Artifact archiveB = getSourceArtifact("myArchiveB.zip");
    final Artifact treeArtifactToPopulateA = createTreeArtifact("testA/archive_member");
    final Artifact treeArtifactToPopulateB = createTreeArtifact("testB/archive_member");
    final Artifact archiveManifestA = getSourceArtifact("archiveManifestA.txt");
    final Artifact archiveManifestB = getSourceArtifact("archiveManifestB.txt");
    final FilesToRunProvider zipperA = FilesToRunProvider.fromSingleExecutableArtifact(getSourceArtifact("unzipBinaryA"));
    final FilesToRunProvider zipperB = FilesToRunProvider.fromSingleExecutableArtifact(getSourceArtifact("unzipBinaryB"));
    ActionTester.runTest(16, new ActionCombinationFactory() {

        @Override
        public Action generate(int i) {
            Artifact archive = (i & 1) == 0 ? archiveA : archiveB;
            Artifact treeArtifactToPopulate = (i & 2) == 0 ? treeArtifactToPopulateA : treeArtifactToPopulateB;
            Artifact archiveManifest = (i & 4) == 0 ? archiveManifestA : archiveManifestB;
            FilesToRunProvider zipper = (i & 8) == 0 ? zipperA : zipperB;
            return new PopulateTreeArtifactAction(ActionsTestUtil.NULL_ACTION_OWNER, archive, archiveManifest, treeArtifactToPopulate, zipper);
        }
    });
}
Also used : ActionCombinationFactory(com.google.devtools.build.lib.analysis.util.ActionTester.ActionCombinationFactory) FilesToRunProvider(com.google.devtools.build.lib.analysis.FilesToRunProvider) Action(com.google.devtools.build.lib.actions.Action) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) Test(org.junit.Test)

Aggregations

FilesToRunProvider (com.google.devtools.build.lib.analysis.FilesToRunProvider)22 Artifact (com.google.devtools.build.lib.actions.Artifact)17 SpawnAction (com.google.devtools.build.lib.analysis.actions.SpawnAction)7 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)4 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 CustomCommandLine (com.google.devtools.build.lib.analysis.actions.CustomCommandLine)3 ArrayList (java.util.ArrayList)3 ImmutableList (com.google.common.collect.ImmutableList)2 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)2 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)2 RunfilesSupport (com.google.devtools.build.lib.analysis.RunfilesSupport)2 Builder (com.google.devtools.build.lib.analysis.actions.SpawnAction.Builder)2 Label (com.google.devtools.build.lib.cmdline.Label)2 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)2 Path (com.google.devtools.build.lib.vfs.Path)2 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Nullable (javax.annotation.Nullable)2