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);
}
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));
}
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);
}
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();
}
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());
}
Aggregations