Search in sources :

Example 26 with Path

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

the class TestFileOutErr method newInMemoryFile.

private static Path newInMemoryFile(File root, String name) {
    InMemoryFileSystem inMemFS = new InMemoryFileSystem();
    Path directory = inMemFS.getPath(root.getPath());
    try {
        FileSystemUtils.createDirectoryAndParents(directory);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return directory.getRelative(name);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) InMemoryFileSystem(com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem) IOException(java.io.IOException)

Example 27 with Path

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

the class BuildFileASTTest method parseBuildFile.

/**
   * Parses the contents of the specified string (using DUMMY_PATH as the fake
   * filename) and returns the AST. Resets the error handler beforehand.
   */
private BuildFileAST parseBuildFile(String... lines) throws IOException {
    Path file = scratch.file("/a/build/file/BUILD", lines);
    ParserInputSource inputSource = ParserInputSource.create(file, file.getFileSize());
    return BuildFileAST.parseBuildFile(inputSource, getEventHandler());
}
Also used : Path(com.google.devtools.build.lib.vfs.Path)

Example 28 with Path

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

the class Package method getTarget.

/**
   * Returns the target (a member of this package) whose name is "targetName".
   * First rules are searched, then output files, then input files.  The target
   * name must be valid, as defined by {@code LabelValidator#validateTargetName}.
   *
   * @throws NoSuchTargetException if the specified target was not found.
   */
public Target getTarget(String targetName) throws NoSuchTargetException {
    Target target = targets.get(targetName);
    if (target != null) {
        return target;
    }
    // No such target.
    // If there's a file on the disk that's not mentioned in the BUILD file,
    // produce a more informative error.  NOTE! this code path is only executed
    // on failure, which is (relatively) very rare.  In the common case no
    // stat(2) is executed.
    Path filename = getPackageDirectory().getRelative(targetName);
    String suffix;
    if (!new PathFragment(targetName).isNormalized()) {
        // Don't check for file existence in this case because the error message
        // would be confusing and wrong. If the targetName is "foo/bar/.", and
        // there is a directory "foo/bar", it doesn't mean that "//pkg:foo/bar/."
        // is a valid label.
        suffix = "";
    } else if (filename.isDirectory()) {
        suffix = "; however, a source directory of this name exists.  (Perhaps add " + "'exports_files([\"" + targetName + "\"])' to " + name + "/BUILD, or define a " + "filegroup?)";
    } else if (filename.exists()) {
        suffix = "; however, a source file of this name exists.  (Perhaps add " + "'exports_files([\"" + targetName + "\"])' to " + name + "/BUILD?)";
    } else {
        suffix = SpellChecker.didYouMean(targetName, targets.keySet());
    }
    throw makeNoSuchTargetException(targetName, suffix);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Example 29 with Path

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

the class PathPackageLocator method getPackageBuildFileNullable.

/**
   * Like #getPackageBuildFile(), but returns null instead of throwing.
   *  @param packageIdentifier the name of the package.
   * @param cache a filesystem-level cache of stat() calls.
   */
public Path getPackageBuildFileNullable(PackageIdentifier packageIdentifier, AtomicReference<? extends UnixGlob.FilesystemCalls> cache) {
    Preconditions.checkArgument(!packageIdentifier.getRepository().isDefault());
    if (packageIdentifier.getRepository().isMain()) {
        return getFilePath(packageIdentifier.getPackageFragment().getRelative("BUILD"), cache);
    } else {
        Verify.verify(outputBase != null, String.format("External package '%s' needs to be loaded but this PathPackageLocator instance does not " + "support external packages", packageIdentifier));
        // This works only to some degree, because it relies on the presence of the repository under
        // $OUTPUT_BASE/external, which is created by the appropriate RepositoryDirectoryValue. This
        // is true for the invocation in GlobCache, but not for the locator.getBuildFileForPackage()
        // invocation in Parser#include().
        Path buildFile = outputBase.getRelative(packageIdentifier.getSourceRoot()).getRelative("BUILD");
        FileStatus stat = cache.get().statNullable(buildFile, Symlinks.FOLLOW);
        if (stat != null && stat.isFile()) {
            return buildFile;
        } else {
            return null;
        }
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) FileStatus(com.google.devtools.build.lib.vfs.FileStatus)

Example 30 with Path

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

the class WorkerFactory method create.

@Override
public Worker create(WorkerKey key) throws Exception {
    int workerId = pidCounter.getAndIncrement();
    Path logFile = workerBaseDir.getRelative("worker-" + workerId + "-" + key.getMnemonic() + ".log");
    Worker worker;
    boolean sandboxed = workerOptions.workerSandboxing || key.mustBeSandboxed();
    if (sandboxed) {
        Path workDir = workerBaseDir.getRelative("worker-" + workerId + "-" + key.getMnemonic());
        worker = new SandboxedWorker(key, workerId, workDir, logFile);
    } else {
        worker = new Worker(key, workerId, key.getExecRoot(), logFile);
    }
    worker.prepareExecution(key);
    worker.createProcess();
    if (workerOptions.workerVerbose) {
        reporter.handle(Event.info(String.format("Created new %s %s worker (id %d), logging to %s", sandboxed ? "sandboxed" : "non-sandboxed", key.getMnemonic(), workerId, logFile)));
    }
    return worker;
}
Also used : Path(com.google.devtools.build.lib.vfs.Path)

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