use of com.facebook.buck.rules.coercer.TypeCoercerFactory in project buck by facebook.
the class InterCellIntegrationTest method parseTargetForXCellVisibility.
private void parseTargetForXCellVisibility(String targetName) throws IOException, InterruptedException, BuildFileParseException, BuildTargetException {
Pair<ProjectWorkspace, ProjectWorkspace> cells = prepare("inter-cell/visibility/primary", "inter-cell/visibility/secondary");
ProjectWorkspace primary = cells.getFirst();
ProjectWorkspace secondary = cells.getSecond();
registerCell(primary, "primary", primary);
registerCell(secondary, "primary", primary);
// We could just do a build, but that's a little extreme since all we need is the target graph
TypeCoercerFactory coercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
Parser parser = new Parser(new BroadcastEventListener(), primary.asCell().getBuckConfig().getView(ParserConfig.class), coercerFactory, new ConstructorArgMarshaller(coercerFactory));
BuckEventBus eventBus = BuckEventBusFactory.newInstance();
Cell primaryCell = primary.asCell();
BuildTarget namedTarget = BuildTargetFactory.newInstance(primaryCell.getFilesystem(), targetName);
// It's enough that this parses cleanly.
parser.buildTargetGraph(eventBus, primaryCell, false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(namedTarget));
}
use of com.facebook.buck.rules.coercer.TypeCoercerFactory in project buck by facebook.
the class IntraCellIntegrationTest method shouldTreatCellBoundariesAsVisibilityBoundariesToo.
@SuppressWarnings("PMD.EmptyCatchBlock")
@Test
public void shouldTreatCellBoundariesAsVisibilityBoundariesToo() throws IOException, InterruptedException, BuildFileParseException, BuildTargetException {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "intracell/visibility", tmp);
workspace.setUp();
// We don't need to do a build. It's enough to just parse these things.
Cell cell = workspace.asCell();
TypeCoercerFactory coercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
Parser parser = new Parser(new BroadcastEventListener(), cell.getBuckConfig().getView(ParserConfig.class), coercerFactory, new ConstructorArgMarshaller(coercerFactory));
// This parses cleanly
parser.buildTargetGraph(BuckEventBusFactory.newInstance(), cell, false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(BuildTargetFactory.newInstance(cell.getFilesystem(), "//just-a-directory:rule")));
Cell childCell = cell.getCell(BuildTargetFactory.newInstance(workspace.getDestPath().resolve("child-repo"), "//:child-target"));
try {
// Whereas, because visibility is limited to the same cell, this won't.
parser.buildTargetGraph(BuckEventBusFactory.newInstance(), childCell, false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(BuildTargetFactory.newInstance(childCell.getFilesystem(), "//:child-target")));
fail("Didn't expect parsing to work because of visibility");
} catch (HumanReadableException e) {
// This is expected
}
}
use of com.facebook.buck.rules.coercer.TypeCoercerFactory 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());
}
use of com.facebook.buck.rules.coercer.TypeCoercerFactory in project buck by facebook.
the class DistBuildFileHashesIntegrationTest method symlinkPathsRecordedInRootCell.
@Test
public void symlinkPathsRecordedInRootCell() throws Exception {
Assume.assumeTrue(Platform.detect() != Platform.WINDOWS);
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "symlink", temporaryFolder);
workspace.setUp();
ProjectFilesystem rootFs = new ProjectFilesystem(temporaryFolder.getRoot().toAbsolutePath().resolve("root_cell"));
Path absSymlinkFilePath = rootFs.resolve("../" + SYMLINK_FILE_NAME);
Path symLinkPath = rootFs.resolve(SYMLINK_FILE_NAME);
rootFs.createSymLink(symLinkPath, absSymlinkFilePath, false);
BuckConfig rootCellConfig = FakeBuckConfig.builder().setFilesystem(rootFs).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(1, dump.getFileHashesSize());
BuildJobStateFileHashes rootCellHashes = dump.getFileHashes().get(0);
assertEquals(2, rootCellHashes.getEntriesSize());
BuildJobStateFileHashEntry symLinkEntry = rootCellHashes.getEntries().stream().filter(x -> x.isSetRootSymLink()).findFirst().get();
String expectedPath = temporaryFolder.getRoot().resolve(SYMLINK_FILE_NAME).toAbsolutePath().toString();
assertEquals(MorePaths.pathWithUnixSeparators(expectedPath), symLinkEntry.getRootSymLinkTarget().getPath());
assertEquals(SYMLINK_FILE_NAME, symLinkEntry.getRootSymLink().getPath());
BuildJobStateFileHashEntry relPathEntry = rootCellHashes.getEntries().stream().filter(x -> !x.isPathIsAbsolute()).findFirst().get();
assertEquals("A.java", relPathEntry.getPath().getPath());
}
use of com.facebook.buck.rules.coercer.TypeCoercerFactory in project buck by facebook.
the class DistBuildStateTest method canReconstructGraphAndTopLevelBuildTargets.
@Test
public void canReconstructGraphAndTopLevelBuildTargets() throws Exception {
ProjectWorkspace projectWorkspace = TestDataHelper.createProjectWorkspaceForScenario(this, "simple_java_target", temporaryFolder);
projectWorkspace.setUp();
Cell cell = projectWorkspace.asCell();
ProjectFilesystem projectFilesystem = cell.getFilesystem();
projectFilesystem.mkdirs(projectFilesystem.getBuckPaths().getBuckOut());
BuckConfig buckConfig = cell.getBuckConfig();
TypeCoercerFactory typeCoercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
ConstructorArgMarshaller constructorArgMarshaller = new ConstructorArgMarshaller(typeCoercerFactory);
Parser parser = new Parser(new BroadcastEventListener(), buckConfig.getView(ParserConfig.class), typeCoercerFactory, constructorArgMarshaller);
TargetGraph targetGraph = parser.buildTargetGraph(BuckEventBusFactory.newInstance(), cell, /* enableProfiling */
false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(BuildTargetFactory.newInstance(projectFilesystem.getRootPath(), "//:lib1"), BuildTargetFactory.newInstance(projectFilesystem.getRootPath(), "//:lib2"), BuildTargetFactory.newInstance(projectFilesystem.getRootPath(), "//:lib3")));
DistBuildTargetGraphCodec targetGraphCodec = createDefaultCodec(cell, Optional.of(parser));
BuildJobState dump = DistBuildState.dump(new DistBuildCellIndexer(cell), emptyActionGraph(), targetGraphCodec, targetGraph, ImmutableSet.of(BuildTargetFactory.newInstance(projectFilesystem.getRootPath(), "//:lib1"), BuildTargetFactory.newInstance(projectFilesystem.getRootPath(), "//:lib2")));
Cell rootCellWhenLoading = new TestCellBuilder().setFilesystem(createJavaOnlyFilesystem("/loading")).build();
DistBuildState distributedBuildState = DistBuildState.load(Optional.empty(), dump, rootCellWhenLoading, knownBuildRuleTypesFactory);
ProjectFilesystem reconstructedCellFilesystem = distributedBuildState.getCells().get(0).getFilesystem();
TargetGraph reconstructedGraph = distributedBuildState.createTargetGraph(targetGraphCodec).getTargetGraph();
assertEquals(reconstructedGraph.getNodes().stream().map(targetNode -> targetNode.castArg(JavaLibraryDescription.Arg.class).get()).sorted().map(targetNode -> targetNode.getConstructorArg().srcs).collect(Collectors.toList()), Lists.newArrayList("A.java", "B.java", "C.java").stream().map(f -> reconstructedCellFilesystem.getPath(f)).map(p -> new PathSourcePath(reconstructedCellFilesystem, p)).map(ImmutableSortedSet::of).collect(Collectors.toList()));
}
Aggregations