Search in sources :

Example 41 with Cell

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);
}
Also used : Path(java.nio.file.Path) Config(com.facebook.buck.config.Config) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 42 with Cell

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);
}
Also used : Path(java.nio.file.Path) Watchman(com.facebook.buck.io.Watchman) FakeWatchmanClient(com.facebook.buck.io.FakeWatchmanClient) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 43 with Cell

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));
}
Also used : Path(java.nio.file.Path) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) BuildTarget(com.facebook.buck.model.BuildTarget) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 44 with Cell

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"));
    }
}
Also used : Cell(com.facebook.buck.rules.Cell) Test(org.junit.Test)

Example 45 with Cell

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"));
    }
}
Also used : Cell(com.facebook.buck.rules.Cell) Test(org.junit.Test)

Aggregations

Cell (com.facebook.buck.rules.Cell)87 Test (org.junit.Test)57 Path (java.nio.file.Path)46 TestCellBuilder (com.facebook.buck.rules.TestCellBuilder)41 BuildTarget (com.facebook.buck.model.BuildTarget)25 BuckConfig (com.facebook.buck.cli.BuckConfig)24 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)22 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)21 PathSourcePath (com.facebook.buck.rules.PathSourcePath)15 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)14 ImmutableSet (com.google.common.collect.ImmutableSet)14 BuckEventBus (com.facebook.buck.event.BuckEventBus)12 ImmutableMap (com.google.common.collect.ImmutableMap)12 BroadcastEventListener (com.facebook.buck.event.listener.BroadcastEventListener)11 ParserConfig (com.facebook.buck.parser.ParserConfig)11 IOException (java.io.IOException)11 Map (java.util.Map)11 TargetNode (com.facebook.buck.rules.TargetNode)10 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)10 ImmutableList (com.google.common.collect.ImmutableList)10