use of com.facebook.buck.rules.Cell in project buck by facebook.
the class DistBuildTargetGraphCodec method createTargetGraph.
public TargetGraphAndBuildTargets createTargetGraph(BuildJobStateTargetGraph remoteTargetGraph, Function<Integer, Cell> cellLookup) throws IOException {
ImmutableMap.Builder<BuildTarget, TargetNode<?, ?>> targetNodeIndexBuilder = ImmutableMap.builder();
ImmutableSet.Builder<BuildTarget> buildTargetsBuilder = ImmutableSet.builder();
for (BuildJobStateTargetNode remoteNode : remoteTargetGraph.getNodes()) {
Cell cell = cellLookup.apply(remoteNode.getCellIndex());
ProjectFilesystem projectFilesystem = cell.getFilesystem();
BuildTarget target = decodeBuildTarget(remoteNode.getBuildTarget(), cell);
if (topLevelTargets.contains(target.getFullyQualifiedName())) {
buildTargetsBuilder.add(target);
}
@SuppressWarnings("unchecked") Map<String, Object> rawNode = objectMapper.readValue(remoteNode.getRawNode(), Map.class);
Path buildFilePath = projectFilesystem.resolve(target.getBasePath()).resolve(cell.getBuildFileName());
TargetNode<?, ?> targetNode = parserTargetNodeFactory.createTargetNode(cell, buildFilePath, target, rawNode, input -> SimplePerfEvent.scope(Optional.empty(), input));
targetNodeIndexBuilder.put(targetNode.getBuildTarget(), targetNode);
}
ImmutableSet<BuildTarget> buildTargets = buildTargetsBuilder.build();
Preconditions.checkArgument(topLevelTargets.size() == buildTargets.size());
ImmutableMap<BuildTarget, TargetNode<?, ?>> targetNodeIndex = targetNodeIndexBuilder.build();
MutableDirectedGraph<TargetNode<?, ?>> mutableTargetGraph = new MutableDirectedGraph<>();
for (TargetNode<?, ?> targetNode : targetNodeIndex.values()) {
mutableTargetGraph.addNode(targetNode);
for (BuildTarget dep : targetNode.getDeps()) {
mutableTargetGraph.addEdge(targetNode, Preconditions.checkNotNull(targetNodeIndex.get(dep)));
}
}
// TODO(tophyr): make this work with TargetGroups
TargetGraph targetGraph = new TargetGraph(mutableTargetGraph, targetNodeIndex, ImmutableSet.of());
return TargetGraphAndBuildTargets.builder().setTargetGraph(targetGraph).addAllBuildTargets(buildTargets).build();
}
use of com.facebook.buck.rules.Cell 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());
}
use of com.facebook.buck.rules.Cell in project buck by facebook.
the class AppleBuildRulesTest method testAppleLibraryIsXcodeTargetDescription.
@Test
public void testAppleLibraryIsXcodeTargetDescription() throws Exception {
Cell rootCell = (new TestCellBuilder()).build();
BuildTarget libraryTarget = BuildTarget.builder(rootCell.getRoot(), "//foo", "lib").build();
TargetNode<AppleLibraryDescription.Arg, ?> library = AppleLibraryBuilder.createBuilder(libraryTarget).setSrcs(ImmutableSortedSet.of()).build();
assertTrue(AppleBuildRules.isXcodeTargetDescription(library.getDescription()));
}
use of com.facebook.buck.rules.Cell in project buck by facebook.
the class OwnersReportTest method verifyInputsWithOneOwnerAreCorrectlyReported.
/**
* Verify that owners are correctly detected:
* - one owner, multiple inputs
*/
@Test
public void verifyInputsWithOneOwnerAreCorrectlyReported() throws CmdLineException, IOException, InterruptedException {
ImmutableSet<String> inputs = ImmutableSet.of("java/somefolder/badfolder/somefile.java", "java/somefolder/perfect.java", "com/test/subtest/random.java");
ImmutableSet<Path> inputPaths = RichStream.from(inputs).map(filesystem::getPath).toImmutableSet();
for (Path path : inputPaths) {
filesystem.mkdirs(path.getParent());
filesystem.writeContentsToPath("", path);
}
BuildTarget target = BuildTargetFactory.newInstance("//base:name");
TargetNode<?, ?> targetNode = createTargetNode(target, inputPaths);
Cell cell = new TestCellBuilder().setFilesystem(filesystem).build();
OwnersReport report = OwnersReport.generateOwnersReport(cell, targetNode, inputs);
assertTrue(report.nonFileInputs.isEmpty());
assertTrue(report.nonExistentInputs.isEmpty());
assertTrue(report.inputsWithNoOwners.isEmpty());
assertEquals(inputs.size(), report.owners.size());
assertTrue(report.owners.containsKey(targetNode));
assertEquals(targetNode.getInputs(), report.owners.get(targetNode));
}
use of com.facebook.buck.rules.Cell in project buck by facebook.
the class OwnersReportTest method verifyInputsWithoutOwnersAreCorrectlyReported.
@Test
public void verifyInputsWithoutOwnersAreCorrectlyReported() throws CmdLineException, IOException, InterruptedException {
// Inputs that should be treated as existing files
ImmutableSet<String> inputs = ImmutableSet.of("java/somefolder/badfolder/somefile.java", "java/somefolder/perfect.java", "com/test/subtest/random.java");
ImmutableSet<Path> inputPaths = RichStream.from(inputs).map(filesystem::getPath).toImmutableSet();
// Write dummy files.
for (Path path : inputPaths) {
filesystem.mkdirs(path.getParent());
filesystem.writeContentsToPath("", path);
}
BuildTarget target = BuildTargetFactory.newInstance("//base:name");
TargetNode<?, ?> targetNode = createTargetNode(target, ImmutableSet.of());
Cell cell = new TestCellBuilder().setFilesystem(filesystem).build();
OwnersReport report = OwnersReport.generateOwnersReport(cell, targetNode, inputs);
assertTrue(report.owners.isEmpty());
assertTrue(report.nonFileInputs.isEmpty());
assertTrue(report.nonExistentInputs.isEmpty());
assertEquals(inputPaths, report.inputsWithNoOwners);
}
Aggregations