use of com.facebook.buck.rules.Cell in project buck by facebook.
the class BuildFileSpecTest method recursiveIgnorePaths.
@Test
public void recursiveIgnorePaths() throws IOException, InterruptedException {
Path ignoredBuildFile = Paths.get("a", "b", "BUCK");
Config config = ConfigBuilder.createFromText("[project]", "ignore = a/b");
ProjectFilesystem filesystem = new ProjectFilesystem(tmp.getRoot().toPath(), config);
Path buildFile = Paths.get("a", "BUCK");
filesystem.mkdirs(buildFile.getParent());
filesystem.writeContentsToPath("", buildFile);
filesystem.mkdirs(ignoredBuildFile.getParent());
filesystem.writeContentsToPath("", ignoredBuildFile);
// Test a recursive spec with an ignored dir.
BuildFileSpec recursiveSpec = BuildFileSpec.fromRecursivePath(buildFile.getParent(), filesystem.getRootPath());
ImmutableSet<Path> expectedBuildFiles = ImmutableSet.of(filesystem.resolve(buildFile));
Cell cell = new TestCellBuilder().setFilesystem(filesystem).build();
ImmutableSet<Path> actualBuildFiles = recursiveSpec.findBuildFiles(cell, ParserConfig.BuildFileSearchMethod.FILESYSTEM_CRAWL);
assertEquals(expectedBuildFiles, actualBuildFiles);
}
use of com.facebook.buck.rules.Cell in project buck by facebook.
the class BuildFileSpecTest method findWithWatchmanFallsBackToFilesystemOnTimeout.
@Test
public void findWithWatchmanFallsBackToFilesystemOnTimeout() throws IOException, InterruptedException {
Path watchRoot = Paths.get(".").toAbsolutePath().normalize();
FakeProjectFilesystem filesystem = new FakeProjectFilesystem(watchRoot.resolve("project-name"));
Path buildFile = Paths.get("a", "BUCK");
filesystem.mkdirs(buildFile.getParent());
filesystem.touch(buildFile);
Path nestedBuildFile = Paths.get("a", "b", "BUCK");
filesystem.mkdirs(nestedBuildFile.getParent());
filesystem.touch(nestedBuildFile);
BuildFileSpec recursiveSpec = BuildFileSpec.fromRecursivePath(buildFile.getParent(), filesystem.getRootPath());
FakeWatchmanClient timingOutWatchmanClient = new FakeWatchmanClient(// Pretend the query takes a very very long time.
TimeUnit.SECONDS.toNanos(Long.MAX_VALUE), ImmutableMap.of(ImmutableList.of("query", watchRoot.toString(), ImmutableMap.of("relative_root", "project-name", "sync_timeout", 0, "path", ImmutableList.of("a"), "fields", ImmutableList.of("name"), "expression", ImmutableList.of("allof", "exists", ImmutableList.of("name", "BUCK"), ImmutableList.of("type", "f")))), ImmutableMap.of("files", ImmutableList.of("a/BUCK", "a/b/BUCK"))));
Cell cell = new TestCellBuilder().setFilesystem(filesystem).setWatchman(new Watchman(ImmutableMap.of(filesystem.getRootPath(), ProjectWatch.of(watchRoot.toString(), Optional.of("project-name"))), ImmutableSet.of(Watchman.Capability.SUPPORTS_PROJECT_WATCH, Watchman.Capability.DIRNAME, Watchman.Capability.WILDMATCH_GLOB), ImmutableMap.of(), Optional.of(Paths.get(".watchman-sock")), Optional.of(timingOutWatchmanClient))).build();
ImmutableSet<Path> expectedBuildFiles = ImmutableSet.of(filesystem.resolve(buildFile), filesystem.resolve(nestedBuildFile));
ImmutableSet<Path> actualBuildFiles = recursiveSpec.findBuildFiles(cell, ParserConfig.BuildFileSearchMethod.WATCHMAN);
assertEquals(expectedBuildFiles, actualBuildFiles);
}
use of com.facebook.buck.rules.Cell in project buck by facebook.
the class DaemonicCellStateTest method testTrackCellAgnosticTargetConfig.
@Test
public void testTrackCellAgnosticTargetConfig() throws BuildTargetException, IOException, InterruptedException {
BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem).setSections("[project]", "track_cell_agnostic_target = false").build();
Cell cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
DaemonicCellState state = new DaemonicCellState(cell, 1);
Cache<BuildTarget, Boolean> cache = state.getOrCreateCache(Boolean.class);
Path targetPath = cell.getRoot().resolve("path/to/BUCK");
BuildTarget target = BuildTargetFactory.newInstance(filesystem, "xplat//path/to:target");
cache.putComputedNodeIfNotPresent(cell, target, true);
assertEquals(Optional.of(true), cache.lookupComputedNode(cell, target));
state.putRawNodesIfNotPresentAndStripMetaEntries(targetPath, ImmutableSet.of(// Forms the target "//path/to:target"
ImmutableMap.of("buck.base_path", "path/to", "name", "target")), ImmutableSet.of(), ImmutableMap.of(), ImmutableMap.of());
assertEquals("One raw node should be invalidated", 1, state.invalidatePath(targetPath));
assertEquals("Cell-named target should not have been removed", Optional.of(true), cache.lookupComputedNode(cell, target));
// If we change the config, then eviction does happen
config = FakeBuckConfig.builder().setFilesystem(filesystem).setSections("[project]", "track_cell_agnostic_target = true").build();
cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
state = new DaemonicCellState(cell, 1);
cache = state.getOrCreateCache(Boolean.class);
cache.putComputedNodeIfNotPresent(cell, target, true);
assertEquals(Optional.of(true), cache.lookupComputedNode(cell, target));
state.putRawNodesIfNotPresentAndStripMetaEntries(targetPath, ImmutableSet.of(// Forms the target "//path/to:target"
ImmutableMap.of("buck.base_path", "path/to", "name", "target")), ImmutableSet.of(), ImmutableMap.of(), ImmutableMap.of());
assertEquals("Still only one invalidated node", 1, state.invalidatePath(targetPath));
assertEquals("Cell-named target should still be invalidated", Optional.empty(), cache.lookupComputedNode(cell, target));
}
use of com.facebook.buck.rules.Cell in project buck by facebook.
the class ParsePipelineTest method missingBuildFile.
@Test
public void missingBuildFile() throws Exception {
try (Fixture fixture = createMultiThreadedFixture("parse_rule_with_bad_dependency")) {
Cell cell = fixture.getCell();
expectedException.expect(BuildFileParseException.class);
expectedException.expectMessage(stringContainsInOrder("Parse error for build file", "No such file or directory"));
fixture.getTargetNodeParsePipeline().getAllNodes(cell, cell.getFilesystem().resolve("no/such/file/BUCK"));
}
}
use of com.facebook.buck.rules.Cell in project buck by facebook.
the class ParsePipelineTest method exceptionOnFetchingNodeAsGroup.
@Test
public void exceptionOnFetchingNodeAsGroup() throws Exception {
try (Fixture fixture = createSynchronousExecutionFixture("groups")) {
final Cell cell = fixture.getCell();
expectedException.expect(NoSuchBuildTargetException.class);
fixture.getTargetNodeParsePipeline().getNode(cell, BuildTargetFactory.newInstance(cell.getFilesystem(), "//:group_one"));
}
}
Aggregations