Search in sources :

Example 26 with TestCellBuilder

use of com.facebook.buck.rules.TestCellBuilder 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 27 with TestCellBuilder

use of com.facebook.buck.rules.TestCellBuilder 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 28 with TestCellBuilder

use of com.facebook.buck.rules.TestCellBuilder 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)

Example 29 with TestCellBuilder

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

the class WorkspaceAndProjectGeneratorTest method setUp.

@Before
public void setUp() throws InterruptedException, IOException {
    rootCell = (new TestCellBuilder()).build();
    ProjectFilesystem projectFilesystem = rootCell.getFilesystem();
    halideBuckConfig = HalideLibraryBuilder.createDefaultHalideConfig(projectFilesystem);
    cxxBuckConfig = CxxLibraryBuilder.createDefaultConfig();
    BuckConfig fakeBuckConfig = FakeBuckConfig.builder().build();
    appleConfig = new AppleConfig(fakeBuckConfig);
    swiftBuckConfig = new SwiftBuckConfig(fakeBuckConfig);
    setUpWorkspaceAndProjects();
}
Also used : AppleConfig(com.facebook.buck.apple.AppleConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) HalideBuckConfig(com.facebook.buck.halide.HalideBuckConfig) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Before(org.junit.Before)

Example 30 with TestCellBuilder

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

the class DistBuildFileHashesIntegrationTest method crossCellDoesNotCauseAbsolutePathSrcs.

@Test
public void crossCellDoesNotCauseAbsolutePathSrcs() throws Exception {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "cross_cell", temporaryFolder);
    workspace.setUp();
    ProjectFilesystem rootFs = new ProjectFilesystem(temporaryFolder.getRoot().toAbsolutePath().resolve("root_cell"));
    ProjectFilesystem secondaryFs = new ProjectFilesystem(temporaryFolder.getRoot().toAbsolutePath().resolve("secondary_cell"));
    BuckConfig rootCellConfig = FakeBuckConfig.builder().setFilesystem(rootFs).setSections("[repositories]", "cross_cell_secondary = " + secondaryFs.getRootPath().toAbsolutePath()).build();
    Cell rootCell = new TestCellBuilder().setBuckConfig(rootCellConfig).setFilesystem(rootFs).build();
    TypeCoercerFactory typeCoercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
    ConstructorArgMarshaller constructorArgMarshaller = new ConstructorArgMarshaller(typeCoercerFactory);
    Parser parser = new Parser(new BroadcastEventListener(), rootCellConfig.getView(ParserConfig.class), typeCoercerFactory, constructorArgMarshaller);
    TargetGraph targetGraph = parser.buildTargetGraph(BuckEventBusFactory.newInstance(), rootCell, /* enableProfiling */
    false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(BuildTargetFactory.newInstance(rootFs.getRootPath(), "//:libA")));
    DistBuildTargetGraphCodec targetGraphCodec = DistBuildStateTest.createDefaultCodec(rootCell, Optional.of(parser));
    BuildJobState dump = DistBuildState.dump(new DistBuildCellIndexer(rootCell), createDistBuildFileHashes(targetGraph, rootCell), targetGraphCodec, targetGraph, ImmutableSet.of(BuildTargetFactory.newInstance(rootFs.getRootPath(), "//:libA")));
    assertNotNull(dump);
    assertEquals(2, dump.getFileHashesSize());
    List<BuildJobStateFileHashes> sortedHashes = dump.getFileHashes().stream().sorted(Comparator.comparingInt(BuildJobStateFileHashes::getCellIndex)).collect(Collectors.toList());
    BuildJobStateFileHashes rootCellHashes = sortedHashes.get(0);
    assertEquals(1, rootCellHashes.getEntriesSize());
    assertEquals("A.java", rootCellHashes.getEntries().get(0).getPath().getPath());
    BuildJobStateFileHashes secondaryCellHashes = sortedHashes.get(1);
    assertEquals(1, secondaryCellHashes.getEntriesSize());
    assertEquals("B.java", secondaryCellHashes.getEntries().get(0).getPath().getPath());
}
Also used : BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) TargetGraph(com.facebook.buck.rules.TargetGraph) TypeCoercerFactory(com.facebook.buck.rules.coercer.TypeCoercerFactory) 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) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Cell(com.facebook.buck.rules.Cell) ParserConfig(com.facebook.buck.parser.ParserConfig) Test(org.junit.Test)

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