Search in sources :

Example 81 with Cell

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();
}
Also used : Path(java.nio.file.Path) BuildJobStateTargetNode(com.facebook.buck.distributed.thrift.BuildJobStateTargetNode) BuildJobStateTargetNode(com.facebook.buck.distributed.thrift.BuildJobStateTargetNode) TargetNode(com.facebook.buck.rules.TargetNode) BuildJobStateTargetGraph(com.facebook.buck.distributed.thrift.BuildJobStateTargetGraph) TargetGraph(com.facebook.buck.rules.TargetGraph) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableSet(com.google.common.collect.ImmutableSet) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BuildJobStateBuildTarget(com.facebook.buck.distributed.thrift.BuildJobStateBuildTarget) BuildTarget(com.facebook.buck.model.BuildTarget) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Cell(com.facebook.buck.rules.Cell) MutableDirectedGraph(com.facebook.buck.graph.MutableDirectedGraph)

Example 82 with Cell

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());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) 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) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestConsole(com.facebook.buck.testutil.TestConsole) Cell(com.facebook.buck.rules.Cell) ParserConfig(com.facebook.buck.parser.ParserConfig) PerBuildState(com.facebook.buck.parser.PerBuildState) Before(org.junit.Before)

Example 83 with Cell

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()));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 84 with Cell

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));
}
Also used : Path(java.nio.file.Path) BuildTarget(com.facebook.buck.model.BuildTarget) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 85 with Cell

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);
}
Also used : Path(java.nio.file.Path) BuildTarget(com.facebook.buck.model.BuildTarget) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Aggregations

Cell (com.facebook.buck.rules.Cell)87 Test (org.junit.Test)57 Path (java.nio.file.Path)46 TestCellBuilder (com.facebook.buck.rules.TestCellBuilder)41 BuildTarget (com.facebook.buck.model.BuildTarget)25 BuckConfig (com.facebook.buck.cli.BuckConfig)24 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)22 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)21 PathSourcePath (com.facebook.buck.rules.PathSourcePath)15 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)14 ImmutableSet (com.google.common.collect.ImmutableSet)14 BuckEventBus (com.facebook.buck.event.BuckEventBus)12 ImmutableMap (com.google.common.collect.ImmutableMap)12 BroadcastEventListener (com.facebook.buck.event.listener.BroadcastEventListener)11 ParserConfig (com.facebook.buck.parser.ParserConfig)11 IOException (java.io.IOException)11 Map (java.util.Map)11 TargetNode (com.facebook.buck.rules.TargetNode)10 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)10 ImmutableList (com.google.common.collect.ImmutableList)10