Search in sources :

Example 91 with Path

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

the class ArtifactTest method testRootPrefixedExecPath_noRoot.

@Test
public void testRootPrefixedExecPath_noRoot() throws IOException {
    Path f1 = scratch.file("/exec/dir/file.ext");
    Artifact a1 = new Artifact(f1.relativeTo(execDir), Root.asDerivedRoot(execDir));
    assertEquals(":dir/file.ext", Artifact.asRootPrefixedExecPath(a1));
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) Test(org.junit.Test)

Example 92 with Path

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

the class ArtifactTest method testRootPrefixedExecPath_nullRootDir.

@Test
public void testRootPrefixedExecPath_nullRootDir() throws IOException {
    Path f1 = scratch.file("/exec/dir/file.ext");
    try {
        new Artifact(f1, null, f1.relativeTo(execDir));
        fail("Expected IllegalArgumentException creating artifact with null root");
    } catch (IllegalArgumentException expected) {
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) Test(org.junit.Test)

Example 93 with Path

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

the class Scratch method overwriteFile.

/**
   * Like {@code scratch.file}, but the file is first deleted if it already
   * exists.
   */
public Path overwriteFile(String pathName, Charset charset, String... lines) throws IOException {
    Path oldFile = resolve(pathName);
    long newMTime = oldFile.exists() ? oldFile.getLastModifiedTime() + 1 : -1;
    oldFile.delete();
    Path newFile = file(pathName, charset, lines);
    newFile.setLastModifiedTime(newMTime);
    return newFile;
}
Also used : Path(com.google.devtools.build.lib.vfs.Path)

Example 94 with Path

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

the class Scratch method newFile.

/** Creates a new scratch file, ensuring parents exist. */
private Path newFile(String pathName) throws IOException {
    Path file = resolve(pathName);
    Path parentDir = file.getParentDirectory();
    if (!parentDir.exists()) {
        FileSystemUtils.createDirectoryAndParents(parentDir);
    }
    if (file.exists()) {
        throw new IOException("Could not create scratch file (file exists) " + pathName);
    }
    return file;
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) IOException(java.io.IOException)

Example 95 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)

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