Search in sources :

Example 6 with Path

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

the class TestStrategy method getLocalRunfilesDirectory.

/**
   * Returns the runfiles directory associated with the test executable, creating/updating it if
   * necessary and --build_runfile_links is specified.
   */
protected static Path getLocalRunfilesDirectory(TestRunnerAction testAction, ActionExecutionContext actionExecutionContext, BinTools binTools, ImmutableMap<String, String> shellEnvironment, boolean enableRunfiles) throws ExecException, InterruptedException {
    TestTargetExecutionSettings execSettings = testAction.getExecutionSettings();
    Path runfilesDir = execSettings.getRunfilesDir();
    // as a flag to the build.
    if (execSettings.getRunfilesSymlinksCreated()) {
        return runfilesDir;
    }
    // Synchronize runfiles tree generation on the runfiles manifest artifact.
    // This is necessary, because we might end up with multiple test runner actions
    // trying to generate same runfiles tree in case of --runs_per_test > 1 or
    // local test sharding.
    long startTime = Profiler.nanoTimeMaybe();
    synchronized (execSettings.getInputManifest()) {
        Profiler.instance().logSimpleTask(startTime, ProfilerTask.WAIT, testAction);
        updateLocalRunfilesDirectory(testAction, runfilesDir, actionExecutionContext, binTools, shellEnvironment, enableRunfiles);
    }
    return runfilesDir;
}
Also used : TestTargetExecutionSettings(com.google.devtools.build.lib.rules.test.TestTargetExecutionSettings) Path(com.google.devtools.build.lib.vfs.Path)

Example 7 with Path

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

the class ExecutionTool method createBuilder.

private Builder createBuilder(BuildRequest request, ActionCache actionCache, SkyframeExecutor skyframeExecutor, ModifiedFileSet modifiedOutputFiles) {
    BuildRequest.BuildRequestOptions options = request.getBuildOptions();
    boolean keepGoing = request.getViewOptions().keepGoing;
    Path actionOutputRoot = env.getDirectories().getActionConsoleOutputDirectory();
    Predicate<Action> executionFilter = CheckUpToDateFilter.fromOptions(request.getOptions(ExecutionOptions.class));
    // jobs should have been verified in BuildRequest#validateOptions().
    Preconditions.checkState(options.jobs >= -1);
    // Treat 0 jobs as a single task.
    int actualJobs = options.jobs == 0 ? 1 : options.jobs;
    skyframeExecutor.setActionOutputRoot(actionOutputRoot);
    ArtifactFactory artifactFactory = env.getSkyframeBuildView().getArtifactFactory();
    return new SkyframeBuilder(skyframeExecutor, new ActionCacheChecker(actionCache, artifactFactory, executionFilter, ActionCacheChecker.CacheConfig.builder().setEnabled(options.useActionCache).setVerboseExplanations(options.verboseExplanations).build()), keepGoing, actualJobs, request.getPackageCacheOptions().checkOutputFiles ? modifiedOutputFiles : ModifiedFileSet.NOTHING_MODIFIED, options.finalizeActions, fileCache, request.getBuildOptions().progressReportInterval);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) ExecutionOptions(com.google.devtools.build.lib.exec.ExecutionOptions) Action(com.google.devtools.build.lib.actions.Action) WorkspaceStatusAction(com.google.devtools.build.lib.analysis.WorkspaceStatusAction) ArtifactFactory(com.google.devtools.build.lib.actions.ArtifactFactory) ActionCacheChecker(com.google.devtools.build.lib.actions.ActionCacheChecker)

Example 8 with Path

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

the class ExecutionTool method startLocalOutputBuild.

/**
   * Prepare for a local output build.
   */
private void startLocalOutputBuild(String workspaceName) throws ExecutorInitException {
    try (AutoProfiler p = AutoProfiler.profiled("Starting local output build", ProfilerTask.INFO)) {
        Path outputPath = env.getDirectories().getOutputPath(workspaceName);
        Path localOutputPath = env.getDirectories().getLocalOutputPath();
        if (outputPath.isSymbolicLink()) {
            try {
                // Remove the existing symlink first.
                outputPath.delete();
                if (localOutputPath.exists()) {
                    // Pre-existing local output directory. Move to outputPath.
                    localOutputPath.renameTo(outputPath);
                }
            } catch (IOException e) {
                throw new ExecutorInitException("Couldn't handle local output directory symlinks", e);
            }
        }
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) AutoProfiler(com.google.devtools.build.lib.profiler.AutoProfiler) IOException(java.io.IOException) ExecutorInitException(com.google.devtools.build.lib.actions.ExecutorInitException)

Example 9 with Path

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

the class OutputDirectoryLinksUtils method relativize.

// Helper to getPrettyPath.  Returns file, relativized w.r.t. the referent of
// "linkname", or null if it was a not a child.
private static PathFragment relativize(Path file, Path workspaceDirectory, String linkname) {
    PathFragment link = new PathFragment(linkname);
    try {
        Path dir = workspaceDirectory.getRelative(link);
        PathFragment levelOneLinkTarget = dir.readSymbolicLink();
        if (levelOneLinkTarget.isAbsolute() && file.startsWith(dir = file.getRelative(levelOneLinkTarget))) {
            return link.getRelative(file.relativeTo(dir));
        }
    } catch (IOException e) {
    /* ignore */
    }
    return null;
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) IOException(java.io.IOException)

Example 10 with Path

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

the class GlobCache method getGlobUnsorted.

@VisibleForTesting
protected List<String> getGlobUnsorted(String pattern, boolean excludeDirs) throws IOException, BadGlobException, InterruptedException {
    Future<List<Path>> futureResult = getGlobUnsortedAsync(pattern, excludeDirs);
    List<Path> globPaths = fromFuture(futureResult);
    // garbage collection of the GlobFuture and GlobVisitor objects.
    if (!(futureResult instanceof SettableFuture<?>)) {
        SettableFuture<List<Path>> completedFuture = SettableFuture.create();
        completedFuture.set(globPaths);
        globCache.put(Pair.of(pattern, excludeDirs), completedFuture);
    }
    List<String> result = Lists.newArrayListWithCapacity(globPaths.size());
    for (Path path : globPaths) {
        String relative = path.relativeTo(packageDirectory).getPathString();
        // really want to name the package directory.
        if (!relative.isEmpty()) {
            result.add(relative);
        }
    }
    return result;
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) SettableFuture(com.google.common.util.concurrent.SettableFuture) ArrayList(java.util.ArrayList) List(java.util.List) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

Path (com.google.devtools.build.lib.vfs.Path)492 Test (org.junit.Test)250 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)111 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)105 IOException (java.io.IOException)102 Artifact (com.google.devtools.build.lib.actions.Artifact)37 SkyKey (com.google.devtools.build.skyframe.SkyKey)37 ArrayList (java.util.ArrayList)29 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)17 FileSystem (com.google.devtools.build.lib.vfs.FileSystem)17 InMemoryFileSystem (com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem)17 HashMap (java.util.HashMap)17 WindowsPath (com.google.devtools.build.lib.windows.WindowsFileSystem.WindowsPath)16 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)14 Before (org.junit.Before)14 Package (com.google.devtools.build.lib.packages.Package)13 FileStatus (com.google.devtools.build.lib.vfs.FileStatus)13 Map (java.util.Map)12 Nullable (javax.annotation.Nullable)12 Executor (com.google.devtools.build.lib.actions.Executor)10