Search in sources :

Example 31 with TargetNode

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

the class ParserTest method loadedBuildFileWithoutLoadedTargetNodesLoadsAdditionalTargetNodes.

@Test
public void loadedBuildFileWithoutLoadedTargetNodesLoadsAdditionalTargetNodes() throws IOException, InterruptedException, BuildFileParseException, BuildTargetException {
    tempDir.newFolder("foo");
    Path testFooBuckFile = tempDir.newFile("foo/BUCK").toRealPath();
    Files.write(testFooBuckFile, "java_library(name = 'lib1')\njava_library(name = 'lib2')\n".getBytes(UTF_8));
    BuildTarget fooLib1Target = BuildTarget.builder(cellRoot, "//foo", "lib1").build();
    BuildTarget fooLib2Target = BuildTarget.builder(cellRoot, "//foo", "lib2").build();
    // First, only load one target from the build file so the file is parsed, but only one of the
    // TargetNodes will be cached.
    TargetNode<?, ?> targetNode = parser.getTargetNode(eventBus, cell, false, executorService, fooLib1Target);
    assertThat(targetNode.getBuildTarget(), equalTo(fooLib1Target));
    // Now, try to load the entire build file and get all TargetNodes.
    ImmutableSet<TargetNode<?, ?>> targetNodes = parser.getAllTargetNodes(eventBus, cell, false, executorService, testFooBuckFile);
    assertThat(targetNodes.size(), equalTo(2));
    assertThat(targetNodes.stream().map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableList()), hasItems(fooLib1Target, fooLib2Target));
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) TargetNode(com.facebook.buck.rules.TargetNode) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) Test(org.junit.Test)

Example 32 with TargetNode

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

the class ParsePipelineTest method speculativeDepsTraversalWhenGettingAllNodes.

@Test
public void speculativeDepsTraversalWhenGettingAllNodes() throws Exception {
    final Fixture fixture = createMultiThreadedFixture("pipeline_test");
    final Cell cell = fixture.getCell();
    ImmutableSet<TargetNode<?, ?>> libTargetNodes = fixture.getTargetNodeParsePipeline().getAllNodes(cell, fixture.getCell().getFilesystem().resolve("BUCK"));
    FluentIterable<BuildTarget> allDeps = FluentIterable.from(libTargetNodes).transformAndConcat(new Function<TargetNode<?, ?>, Iterable<BuildTarget>>() {

        @Override
        public Iterable<BuildTarget> apply(TargetNode<?, ?> input) {
            return input.getDeps();
        }
    });
    waitForAll(allDeps, dep -> fixture.getTargetNodeParsePipelineCache().lookupComputedNode(cell, dep) != null);
    fixture.close();
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) FluentIterable(com.google.common.collect.FluentIterable) BuildTarget(com.facebook.buck.model.BuildTarget) Cell(com.facebook.buck.rules.Cell) Test(org.junit.Test)

Example 33 with TargetNode

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

the class APKModuleGraph method mapTargetsToContainingModules.

/**
   * For each seed target, find its reachable targets and mark them in a multimap as being reachable
   * by that module for later sorting into exclusive and shared targets
   *
   * @return the Multimap containing targets and the seed modules that contain them
   */
private HashMultimap<BuildTarget, String> mapTargetsToContainingModules() {
    final HashMultimap<BuildTarget, String> targetToContainingApkModuleNameMap = HashMultimap.create();
    for (BuildTarget seedTarget : seedTargets.get()) {
        final String seedModuleName = generateNameFromTarget(seedTarget);
        targetToContainingApkModuleNameMap.put(seedTarget, seedModuleName);
        new AbstractBreadthFirstTraversal<TargetNode<?, ?>>(targetGraph.get(seedTarget)) {

            @Override
            public ImmutableSet<TargetNode<?, ?>> visit(TargetNode<?, ?> node) {
                ImmutableSet.Builder<TargetNode<?, ?>> depsBuilder = ImmutableSet.builder();
                for (BuildTarget depTarget : node.getDeps()) {
                    if (!isInRootModule(depTarget) && !isSeedTarget(depTarget)) {
                        depsBuilder.add(targetGraph.get(depTarget));
                        targetToContainingApkModuleNameMap.put(depTarget, seedModuleName);
                    }
                }
                return depsBuilder.build();
            }
        }.start();
    }
    return targetToContainingApkModuleNameMap;
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget)

Example 34 with TargetNode

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

the class WorkspaceAndProjectGenerator method getOrderedTestNodes.

/**
   * Find tests to run.
   *
   * @param targetGraph input target graph
   * @param includeProjectTests whether to include tests of nodes in the project
   * @param orderedTargetNodes target nodes for which to fetch tests for
   * @param extraTestBundleTargets extra tests to include
   *
   * @return test targets that should be run.
   */
private ImmutableSet<TargetNode<AppleTestDescription.Arg, ?>> getOrderedTestNodes(Optional<BuildTarget> mainTarget, TargetGraph targetGraph, boolean includeProjectTests, boolean includeDependenciesTests, ImmutableSet<TargetNode<?, ?>> orderedTargetNodes, ImmutableSet<TargetNode<AppleTestDescription.Arg, ?>> extraTestBundleTargets) {
    LOG.debug("Getting ordered test target nodes for %s", orderedTargetNodes);
    ImmutableSet.Builder<TargetNode<AppleTestDescription.Arg, ?>> testsBuilder = ImmutableSet.builder();
    if (includeProjectTests) {
        Optional<TargetNode<?, ?>> mainTargetNode = Optional.empty();
        if (mainTarget.isPresent()) {
            mainTargetNode = targetGraph.getOptional(mainTarget.get());
        }
        for (TargetNode<?, ?> node : orderedTargetNodes) {
            if (includeDependenciesTests || (mainTargetNode.isPresent() && node.equals(mainTargetNode.get()))) {
                if (!(node.getConstructorArg() instanceof HasTests)) {
                    continue;
                }
                for (BuildTarget explicitTestTarget : ((HasTests) node.getConstructorArg()).getTests()) {
                    if (!explicitTestTarget.matchesUnflavoredTargets(focusModules)) {
                        continue;
                    }
                    Optional<TargetNode<?, ?>> explicitTestNode = targetGraph.getOptional(explicitTestTarget);
                    if (explicitTestNode.isPresent()) {
                        Optional<TargetNode<AppleTestDescription.Arg, ?>> castedNode = explicitTestNode.get().castArg(AppleTestDescription.Arg.class);
                        if (castedNode.isPresent()) {
                            testsBuilder.add(castedNode.get());
                        } else {
                            LOG.debug("Test target specified in '%s' is not a apple_test;" + " not including in project: '%s'", node.getBuildTarget(), explicitTestTarget);
                        }
                    } else {
                        throw new HumanReadableException("Test target specified in '%s' is not in the target graph: '%s'", node.getBuildTarget(), explicitTestTarget);
                    }
                }
            }
        }
    }
    for (TargetNode<AppleTestDescription.Arg, ?> extraTestTarget : extraTestBundleTargets) {
        testsBuilder.add(extraTestTarget);
    }
    return testsBuilder.build();
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) ImmutableSet(com.google.common.collect.ImmutableSet) AppleTestDescription(com.facebook.buck.apple.AppleTestDescription) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) HasTests(com.facebook.buck.model.HasTests)

Example 35 with TargetNode

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

the class WorkspaceAndProjectGenerator method generateWorkspaceAndDependentProjects.

public Path generateWorkspaceAndDependentProjects(Map<Path, ProjectGenerator> projectGenerators, ListeningExecutorService listeningExecutorService) throws IOException, InterruptedException {
    LOG.debug("Generating workspace for target %s", workspaceBuildTarget);
    String workspaceName = XcodeWorkspaceConfigDescription.getWorkspaceNameFromArg(workspaceArguments);
    Path outputDirectory;
    if (combinedProject) {
        workspaceName += "-Combined";
        outputDirectory = BuildTargets.getGenPath(rootCell.getFilesystem(), workspaceBuildTarget, "%s").getParent().resolve(workspaceName + ".xcodeproj");
    } else {
        outputDirectory = workspaceBuildTarget.getBasePath();
    }
    WorkspaceGenerator workspaceGenerator = new WorkspaceGenerator(rootCell.getFilesystem(), combinedProject ? "project" : workspaceName, outputDirectory);
    ImmutableMap.Builder<String, XcodeWorkspaceConfigDescription.Arg> schemeConfigsBuilder = ImmutableMap.builder();
    ImmutableSetMultimap.Builder<String, Optional<TargetNode<?, ?>>> schemeNameToSrcTargetNodeBuilder = ImmutableSetMultimap.builder();
    ImmutableSetMultimap.Builder<String, TargetNode<?, ?>> buildForTestNodesBuilder = ImmutableSetMultimap.builder();
    ImmutableSetMultimap.Builder<String, TargetNode<AppleTestDescription.Arg, ?>> testsBuilder = ImmutableSetMultimap.builder();
    buildWorkspaceSchemes(projectGraph, projectGeneratorOptions.contains(ProjectGenerator.Option.INCLUDE_TESTS), projectGeneratorOptions.contains(ProjectGenerator.Option.INCLUDE_DEPENDENCIES_TESTS), workspaceName, workspaceArguments, schemeConfigsBuilder, schemeNameToSrcTargetNodeBuilder, buildForTestNodesBuilder, testsBuilder);
    ImmutableMap<String, XcodeWorkspaceConfigDescription.Arg> schemeConfigs = schemeConfigsBuilder.build();
    ImmutableSetMultimap<String, Optional<TargetNode<?, ?>>> schemeNameToSrcTargetNode = schemeNameToSrcTargetNodeBuilder.build();
    ImmutableSetMultimap<String, TargetNode<?, ?>> buildForTestNodes = buildForTestNodesBuilder.build();
    ImmutableSetMultimap<String, TargetNode<AppleTestDescription.Arg, ?>> tests = testsBuilder.build();
    ImmutableSet<BuildTarget> targetsInRequiredProjects = Stream.concat(schemeNameToSrcTargetNode.values().stream().flatMap(Optionals::toStream), buildForTestNodes.values().stream()).map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableSet());
    ImmutableMultimap.Builder<BuildTarget, PBXTarget> buildTargetToPbxTargetMapBuilder = ImmutableMultimap.builder();
    ImmutableMap.Builder<PBXTarget, Path> targetToProjectPathMapBuilder = ImmutableMap.builder();
    Optional<BuildTarget> targetToBuildWithBuck = getTargetToBuildWithBuck();
    generateProjects(projectGenerators, listeningExecutorService, workspaceName, outputDirectory, workspaceGenerator, targetsInRequiredProjects, buildTargetToPbxTargetMapBuilder, targetToProjectPathMapBuilder, targetToBuildWithBuck);
    if (projectGeneratorOptions.contains(ProjectGenerator.Option.GENERATE_HEADERS_SYMLINK_TREES_ONLY)) {
        return workspaceGenerator.getWorkspaceDir();
    } else {
        final Multimap<BuildTarget, PBXTarget> buildTargetToTarget = buildTargetToPbxTargetMapBuilder.build();
        writeWorkspaceSchemes(workspaceName, outputDirectory, schemeConfigs, schemeNameToSrcTargetNode, buildForTestNodes, tests, targetToProjectPathMapBuilder.build(), input -> buildTargetToTarget.get(input.getBuildTarget()), getTargetNodeToPBXTargetTransformFunction(buildTargetToTarget, buildWithBuck));
        return workspaceGenerator.writeWorkspace();
    }
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) AppleTestDescription(com.facebook.buck.apple.AppleTestDescription) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Path(java.nio.file.Path) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) Optional(java.util.Optional) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

TargetNode (com.facebook.buck.rules.TargetNode)88 BuildTarget (com.facebook.buck.model.BuildTarget)73 TargetGraph (com.facebook.buck.rules.TargetGraph)43 Test (org.junit.Test)40 Path (java.nio.file.Path)36 ImmutableSet (com.google.common.collect.ImmutableSet)33 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)23 PathSourcePath (com.facebook.buck.rules.PathSourcePath)22 SourcePath (com.facebook.buck.rules.SourcePath)22 ImmutableMap (com.google.common.collect.ImmutableMap)22 Optional (java.util.Optional)20 Map (java.util.Map)18 HumanReadableException (com.facebook.buck.util.HumanReadableException)17 ImmutableList (com.google.common.collect.ImmutableList)17 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)13 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)13 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)13 Cell (com.facebook.buck.rules.Cell)13 IOException (java.io.IOException)13 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)12