Search in sources :

Example 36 with BuckConfig

use of com.facebook.buck.cli.BuckConfig in project buck by facebook.

the class ParserConfigTest method shouldReturnOneThreadCountIfParallelParsingIsNotEnabled.

@Test
public void shouldReturnOneThreadCountIfParallelParsingIsNotEnabled() {
    BuckConfig config = FakeBuckConfig.builder().setSections("[project]", "parsing_threads = 3", "parallel_parsing = false").build();
    ParserConfig parserConfig = config.getView(ParserConfig.class);
    assertFalse(parserConfig.getEnableParallelParsing());
    assertEquals(1, parserConfig.getNumParsingThreads());
}
Also used : BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) Test(org.junit.Test)

Example 37 with BuckConfig

use of com.facebook.buck.cli.BuckConfig in project buck by facebook.

the class DaemonicCellStateTest method setUp.

@Before
public void setUp() throws IOException, InterruptedException {
    Path root = tempDir.getRoot().toRealPath();
    filesystem = new ProjectFilesystem(root);
    BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem).build();
    cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
    state = new DaemonicCellState(cell, 1);
}
Also used : Path(java.nio.file.Path) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Before(org.junit.Before)

Example 38 with BuckConfig

use of com.facebook.buck.cli.BuckConfig 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 39 with BuckConfig

use of com.facebook.buck.cli.BuckConfig in project buck by facebook.

the class ParserConfigTest method shouldReturnThreadCountIfParallelParsingIsEnabled.

@Test
public void shouldReturnThreadCountIfParallelParsingIsEnabled() {
    BuckConfig config = FakeBuckConfig.builder().setSections("[project]", "parsing_threads = 2", "parallel_parsing = true").build();
    ParserConfig parserConfig = config.getView(ParserConfig.class);
    assertTrue(parserConfig.getEnableParallelParsing());
    assertEquals(2, parserConfig.getNumParsingThreads());
}
Also used : BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) Test(org.junit.Test)

Example 40 with BuckConfig

use of com.facebook.buck.cli.BuckConfig in project buck by facebook.

the class ParserTest method whenBuckConfigEntryChangesThenCachedRulesAreInvalidated.

@Test
public void whenBuckConfigEntryChangesThenCachedRulesAreInvalidated() 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).setSections(ImmutableMap.of("foo", ImmutableMap.of("bar", "other value"))).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)

Aggregations

BuckConfig (com.facebook.buck.cli.BuckConfig)98 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)89 Test (org.junit.Test)74 Path (java.nio.file.Path)46 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)37 TestCellBuilder (com.facebook.buck.rules.TestCellBuilder)29 PathSourcePath (com.facebook.buck.rules.PathSourcePath)27 Cell (com.facebook.buck.rules.Cell)22 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)17 ImmutableMap (com.google.common.collect.ImmutableMap)17 Config (com.facebook.buck.config.Config)15 DefaultCellPathResolver (com.facebook.buck.rules.DefaultCellPathResolver)14 BuildTarget (com.facebook.buck.model.BuildTarget)12 FakeAndroidDirectoryResolver (com.facebook.buck.android.FakeAndroidDirectoryResolver)9 ParserConfig (com.facebook.buck.parser.ParserConfig)8 ConstructorArgMarshaller (com.facebook.buck.rules.ConstructorArgMarshaller)7 DefaultTypeCoercerFactory (com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory)7 TestConsole (com.facebook.buck.testutil.TestConsole)7 Optional (java.util.Optional)7 BuildJobState (com.facebook.buck.distributed.thrift.BuildJobState)6