Search in sources :

Example 1 with SearchPath

use of com.google.devtools.build.lib.vfs.SearchPath in project bazel by bazelbuild.

the class DarwinSandboxedStrategy method getRunUnderPath.

/**
   * If a --run_under= option is set and refers to a command via its path (as opposed to via its
   * label), we have to mount this. Note that this is best effort and works fine for shell scripts
   * and small binaries, but we can't track any further dependencies of this command.
   *
   * <p>If --run_under= refers to a label, it is automatically provided in the spawn's input files,
   * so mountInputs() will catch that case.
   */
private Path getRunUnderPath(Spawn spawn) {
    if (spawn.getResourceOwner() instanceof TestRunnerAction) {
        TestRunnerAction testRunnerAction = ((TestRunnerAction) spawn.getResourceOwner());
        RunUnder runUnder = testRunnerAction.getExecutionSettings().getRunUnder();
        if (runUnder != null && runUnder.getCommand() != null) {
            PathFragment sourceFragment = new PathFragment(runUnder.getCommand());
            Path mount;
            if (sourceFragment.isAbsolute()) {
                mount = blazeDirs.getFileSystem().getPath(sourceFragment);
            } else if (blazeDirs.getExecRoot().getRelative(sourceFragment).exists()) {
                mount = blazeDirs.getExecRoot().getRelative(sourceFragment);
            } else {
                List<Path> searchPath = SearchPath.parse(blazeDirs.getFileSystem(), clientEnv.get("PATH"));
                mount = SearchPath.which(searchPath, runUnder.getCommand());
            }
            // only need to hardlink when under workspace
            Path workspace = blazeDirs.getWorkspace();
            if (mount != null && mount.startsWith(workspace)) {
                return mount;
            }
        }
    }
    return null;
}
Also used : SearchPath(com.google.devtools.build.lib.vfs.SearchPath) Path(com.google.devtools.build.lib.vfs.Path) RunUnder(com.google.devtools.build.lib.analysis.config.RunUnder) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) TestRunnerAction(com.google.devtools.build.lib.rules.test.TestRunnerAction) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 RunUnder (com.google.devtools.build.lib.analysis.config.RunUnder)1 TestRunnerAction (com.google.devtools.build.lib.rules.test.TestRunnerAction)1 Path (com.google.devtools.build.lib.vfs.Path)1 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)1 SearchPath (com.google.devtools.build.lib.vfs.SearchPath)1 List (java.util.List)1