Search in sources :

Example 1 with SymlinkTreeHelper

use of com.google.devtools.build.lib.exec.SymlinkTreeHelper 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)

Aggregations

Artifact (com.google.devtools.build.lib.actions.Artifact)1 FilesToRunProvider (com.google.devtools.build.lib.analysis.FilesToRunProvider)1 RunfilesSupport (com.google.devtools.build.lib.analysis.RunfilesSupport)1 SymlinkTreeHelper (com.google.devtools.build.lib.exec.SymlinkTreeHelper)1 Path (com.google.devtools.build.lib.vfs.Path)1 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)1