use of com.google.devtools.build.lib.windows.WindowsFileSystem.WindowsPath in project bazel by bazelbuild.
the class PathWindowsTest method testChildRegistrationWithTranslatedPaths.
@Test
public void testChildRegistrationWithTranslatedPaths() {
// Ensure the Path to "/usr" (actually "C:/fake/msys/usr") is created, path parents/children
// properly registered.
WindowsPath usrPath = (WindowsPath) root.getRelative("/usr");
root.getRelative("dummy_path");
// Assert that "usr" is not registered as a child of "/".
final List<String> children = new ArrayList<>(2);
root.applyToChildren(new Predicate<Path>() {
@Override
public boolean apply(Path input) {
children.add(input.getPathString());
return true;
}
});
assertThat(children).containsAllOf("C:/fake", "C:/dummy_path");
// Assert that "usr" is registered as a child of "C:/fake/msys/".
children.clear();
((WindowsPath) root.getRelative("C:/fake/msys")).applyToChildren(new Predicate<Path>() {
@Override
public boolean apply(Path input) {
children.add(input.getPathString());
return true;
}
});
assertThat(children).containsExactly("C:/fake/msys/usr");
assertThat(usrPath).isEqualTo(root.getRelative("C:/fake/msys/usr"));
}
use of com.google.devtools.build.lib.windows.WindowsFileSystem.WindowsPath in project bazel by bazelbuild.
the class WindowsFileSystemTest method testUnresolvableShortPathWhichIsThenCreated.
@Test
public void testUnresolvableShortPathWhichIsThenCreated() throws Exception {
String shortPath = "unreso~1.sho/foo/will~1.exi/bar/hello.txt";
String longPrefix = "unresolvable.shortpath/foo/";
String longPath = longPrefix + "will.exist/bar/hello.txt";
testUtil.scratchDir(longPrefix);
final WindowsPath foo = (WindowsPath) fs.getPath(scratchRoot).getRelative(longPrefix);
// Assert that we can create an unresolvable path.
Path p = fs.getPath(scratchRoot).getRelative(shortPath);
assertThat(p.getPathString()).endsWith(longPrefix + "will~1.exi/bar/hello.txt");
// Assert that said path is not cached in its parent's `children` cache.
final List<String> children = new ArrayList<>();
Predicate<Path> collector = new Predicate<Path>() {
@Override
public boolean apply(Path child) {
children.add(child.relativeTo(foo).getPathString());
return true;
}
};
foo.applyToChildren(collector);
assertThat(children).isEmpty();
// Assert that we can then create the whole path, and can now resolve the short form.
testUtil.scratchFile(longPath, "hello");
Path q = fs.getPath(scratchRoot).getRelative(shortPath);
assertThat(q.getPathString()).endsWith(longPath);
// Assert however that the unresolved and resolved Path objects are different, and only the
// resolved one is cached.
assertThat(p).isNotEqualTo(q);
foo.applyToChildren(collector);
assertThat(children).containsExactly("will.exist");
}
use of com.google.devtools.build.lib.windows.WindowsFileSystem.WindowsPath in project bazel by bazelbuild.
the class PathWindowsTest method testResolvesShortenedPaths.
@Test
public void testResolvesShortenedPaths() {
shortPathResolver.resolutions.put("d:/progra~1", "program files");
shortPathResolver.resolutions.put("d:/program files/micros~1", "microsoft something");
shortPathResolver.resolutions.put("d:/program files/microsoft something/foo/~bar~1", "~bar_hello");
// Assert normal shortpath resolution.
Path normal = root.getRelative("d:/progra~1/micros~1/foo/~bar~1/baz");
// The path string has an upper-case drive letter because that's how path printing works.
assertThat(normal.getPathString()).isEqualTo("D:/program files/microsoft something/foo/~bar_hello/baz");
// Assert that we only try to resolve the path segments that look like they may be shortened.
assertThat(shortPathResolver.resolutionQueries).containsExactly("d:/progra~1", "d:/program files/micros~1", "d:/program files/microsoft something/foo/~bar~1");
// Assert resolving a path that has a segment which doesn't exist but later will.
shortPathResolver.resolutionQueries.clear();
Path notYetExistent = root.getRelative("d:/progra~1/micros~1/foo/will~1.exi/bar");
// The path string has an upper-case drive letter because that's how path printing works.
assertThat(notYetExistent.getPathString()).isEqualTo("D:/program files/microsoft something/foo/will~1.exi/bar");
// Assert that we only try to resolve the path segments that look like they may be shortened.
assertThat(shortPathResolver.resolutionQueries).containsExactly("d:/progra~1", "d:/program files/micros~1", "d:/program files/microsoft something/foo/will~1.exi");
// Assert that the paths we failed to resolve don't get cached.
final List<String> children = new ArrayList<>(2);
Predicate<Path> collector = new Predicate<Path>() {
@Override
public boolean apply(Path child) {
children.add(child.getPathString());
return true;
}
};
WindowsPath msRoot = (WindowsPath) root.getRelative("d:/progra~1/micros~1");
assertThat(msRoot.getPathString()).isEqualTo("D:/program files/microsoft something");
msRoot.applyToChildren(collector);
// The path string has an upper-case drive letter because that's how path printing works.
assertThat(children).containsExactly("D:/program files/microsoft something/foo");
// Assert that the non-resolvable path was not cached.
children.clear();
WindowsPath foo = (WindowsPath) msRoot.getRelative("foo");
foo.applyToChildren(collector);
assertThat(children).containsExactly("D:/program files/microsoft something/foo/~bar_hello");
// Pretend that a path we already failed to resolve once came into existence.
shortPathResolver.resolutions.put("d:/program files/microsoft something/foo/will~1.exi", "will.exist");
// Assert that this time we can resolve the previously non-existent path.
shortPathResolver.resolutionQueries.clear();
Path nowExists = root.getRelative("d:/progra~1/micros~1/foo/will~1.exi/bar");
// The path string has an upper-case drive letter because that's how path printing works.
assertThat(nowExists.getPathString()).isEqualTo("D:/program files/microsoft something/foo/will.exist/bar");
// Assert that we only try to resolve the path segments that look like they may be shortened.
assertThat(shortPathResolver.resolutionQueries).containsExactly("d:/progra~1", "d:/program files/micros~1", "d:/program files/microsoft something/foo/will~1.exi");
// Assert that this time we cached the previously non-existent path.
children.clear();
foo.applyToChildren(collector);
// The path strings have upper-case drive letters because that's how path printing works.
children.clear();
foo.applyToChildren(collector);
assertThat(children).containsExactly("D:/program files/microsoft something/foo/~bar_hello", "D:/program files/microsoft something/foo/will.exist");
}
Aggregations