Search in sources :

Example 41 with TestCellBuilder

use of com.facebook.buck.rules.TestCellBuilder in project buck by facebook.

the class BuildFileSpecTest method findWithWatchmanThrowsOnFailure.

@Test
public void findWithWatchmanThrowsOnFailure() throws IOException, InterruptedException {
    Path watchRoot = Paths.get(".").toAbsolutePath().normalize();
    FakeProjectFilesystem filesystem = new FakeProjectFilesystem(watchRoot.resolve("project-name"));
    Path buildFile = Paths.get("a", "BUCK");
    BuildFileSpec recursiveSpec = BuildFileSpec.fromRecursivePath(buildFile.getParent(), filesystem.getRootPath());
    FakeWatchmanClient fakeWatchmanClient = new FakeWatchmanClient(0, 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"))), new IOException("Whoopsie!"));
    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(fakeWatchmanClient))).build();
    thrown.expect(IOException.class);
    thrown.expectMessage("Whoopsie!");
    recursiveSpec.findBuildFiles(cell, ParserConfig.BuildFileSearchMethod.WATCHMAN);
}
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) IOException(java.io.IOException) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 42 with TestCellBuilder

use of com.facebook.buck.rules.TestCellBuilder in project buck by facebook.

the class ParserTest method whenAllRulesAreRequestedWithDifferingIncludesThenRulesAreParsedTwice.

@Test
public void whenAllRulesAreRequestedWithDifferingIncludesThenRulesAreParsedTwice() throws BuildFileParseException, BuildTargetException, IOException, InterruptedException {
    filterAllTargetsInProject(parser, cell, x -> true, eventBus, executorService);
    BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem).setSections(ImmutableMap.of(ParserConfig.BUILDFILE_SECTION_NAME, ImmutableMap.of(ParserConfig.INCLUDES_PROPERTY_NAME, "//bar.py"))).build();
    Cell cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
    filterAllTargetsInProject(parser, cell, x -> true, eventBus, executorService);
    assertEquals("Should have invalidated cache.", 2, counter.calls);
}
Also used : BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 43 with TestCellBuilder

use of com.facebook.buck.rules.TestCellBuilder in project buck by facebook.

the class ParserTest method whenBuckConfigEntryRemovedThenCachedRulesAreInvalidated.

@Test
public void whenBuckConfigEntryRemovedThenCachedRulesAreInvalidated() throws Exception {
    Path buckFile = cellRoot.resolve("BUCK");
    Files.write(buckFile, Joiner.on("").join(ImmutableList.of("read_config('foo', 'bar')\n", "genrule(name = 'cake', out = 'file.txt', cmd = 'touch $OUT')\n")).getBytes(UTF_8));
    BuckConfig config = FakeBuckConfig.builder().setSections(ImmutableMap.of("foo", ImmutableMap.of("bar", "value"))).setFilesystem(filesystem).build();
    Cell cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
    parser.getAllTargetNodes(eventBus, cell, false, executorService, buckFile);
    // Call filterAllTargetsInProject to request cached rules.
    config = FakeBuckConfig.builder().setFilesystem(filesystem).build();
    cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
    parser.getAllTargetNodes(eventBus, cell, false, executorService, buckFile);
    // Test that the second parseBuildFile call repopulated the cache.
    assertEquals("Should have invalidated.", 2, counter.calls);
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 44 with TestCellBuilder

use of com.facebook.buck.rules.TestCellBuilder in project buck by facebook.

the class ParserTest method whenEnvironmentNotChangedThenCacheRulesAreNotInvalidated.

@Test
public void whenEnvironmentNotChangedThenCacheRulesAreNotInvalidated() throws BuildFileParseException, BuildTargetException, IOException, InterruptedException {
    BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem).setEnvironment(ImmutableMap.of("Some Key", "Some Value", "PATH", System.getenv("PATH"))).build();
    Cell cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
    // Call filterAllTargetsInProject to populate the cache.
    filterAllTargetsInProject(parser, cell, x -> true, eventBus, executorService);
    // Call filterAllTargetsInProject to request cached rules with identical environment.
    filterAllTargetsInProject(parser, cell, x -> true, eventBus, executorService);
    // Test that the second parseBuildFile call repopulated the cache.
    assertEquals("Should not have invalidated cache.", 1, counter.calls);
}
Also used : BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 45 with TestCellBuilder

use of com.facebook.buck.rules.TestCellBuilder in project buck by facebook.

the class BuckQueryEnvironmentTest method setUp.

@Before
public void setUp() throws IOException, InterruptedException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "query_command", tmp);
    workspace.setUp();
    Cell cell = new TestCellBuilder().setFilesystem(new ProjectFilesystem(workspace.getDestPath())).build();
    TestConsole console = new TestConsole();
    DefaultTypeCoercerFactory typeCoercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
    Parser parser = new Parser(new BroadcastEventListener(), cell.getBuckConfig().getView(ParserConfig.class), typeCoercerFactory, new ConstructorArgMarshaller(typeCoercerFactory));
    BuckEventBus eventBus = BuckEventBusFactory.newInstance();
    parserState = new PerBuildState(parser, eventBus, executor, cell, /* enableProfiling */
    false, SpeculativeParsing.of(true), /* ignoreBuckAutodepsFiles */
    false);
    TargetPatternEvaluator targetPatternEvaluator = new TargetPatternEvaluator(cell, FakeBuckConfig.builder().build(), parser, eventBus, /* enableProfiling */
    false);
    OwnersReport.Builder ownersReportBuilder = OwnersReport.builder(cell, parser, eventBus, console);
    buckQueryEnvironment = BuckQueryEnvironment.from(cell, ownersReportBuilder, parserState, targetPatternEvaluator);
    cellRoot = workspace.getDestPath();
    executor = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Parser(com.facebook.buck.parser.Parser) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestConsole(com.facebook.buck.testutil.TestConsole) Cell(com.facebook.buck.rules.Cell) ParserConfig(com.facebook.buck.parser.ParserConfig) PerBuildState(com.facebook.buck.parser.PerBuildState) Before(org.junit.Before)

Aggregations

TestCellBuilder (com.facebook.buck.rules.TestCellBuilder)50 Cell (com.facebook.buck.rules.Cell)39 Test (org.junit.Test)39 Path (java.nio.file.Path)31 BuckConfig (com.facebook.buck.cli.BuckConfig)29 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)29 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)18 PathSourcePath (com.facebook.buck.rules.PathSourcePath)18 BuildTarget (com.facebook.buck.model.BuildTarget)15 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)14 Before (org.junit.Before)8 BroadcastEventListener (com.facebook.buck.event.listener.BroadcastEventListener)7 ParserConfig (com.facebook.buck.parser.ParserConfig)7 BuildJobState (com.facebook.buck.distributed.thrift.BuildJobState)6 TestConsole (com.facebook.buck.testutil.TestConsole)6 FakeAndroidDirectoryResolver (com.facebook.buck.android.FakeAndroidDirectoryResolver)5 Config (com.facebook.buck.config.Config)5 BuckEventBus (com.facebook.buck.event.BuckEventBus)5 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)5 ConstructorArgMarshaller (com.facebook.buck.rules.ConstructorArgMarshaller)5