Search in sources :

Example 1 with InMemoryBuildFileTree

use of com.facebook.buck.model.InMemoryBuildFileTree in project buck by facebook.

the class TargetsCommand method getMatchingNodes.

/**
   * @param graph Graph used to resolve dependencies between targets and find all build files.
   * @param referencedFiles If present, the result will be limited to the nodes that transitively
   *                        depend on at least one of those.
   * @param matchingBuildTargets If present, the result will be limited to the specified targets.
   * @param buildRuleTypes If present, the result will be limited to targets with the specified
   *                       types.
   * @param detectTestChanges If true, tests are considered to be dependencies of the targets they
   *                          are testing.
   * @return A map of target names to target nodes.
   */
@VisibleForTesting
ImmutableSortedMap<String, TargetNode<?, ?>> getMatchingNodes(TargetGraph graph, Optional<ImmutableSet<Path>> referencedFiles, final Optional<ImmutableSet<BuildTarget>> matchingBuildTargets, final Optional<ImmutableSet<Class<? extends Description<?>>>> descriptionClasses, boolean detectTestChanges, String buildFileName) {
    ImmutableSet<TargetNode<?, ?>> directOwners;
    if (referencedFiles.isPresent()) {
        BuildFileTree buildFileTree = new InMemoryBuildFileTree(graph.getNodes().stream().map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableSet()));
        directOwners = FluentIterable.from(graph.getNodes()).filter(new DirectOwnerPredicate(buildFileTree, referencedFiles.get(), buildFileName)).toSet();
    } else {
        directOwners = graph.getNodes();
    }
    Iterable<TargetNode<?, ?>> selectedReferrers = FluentIterable.from(getDependentNodes(graph, directOwners, detectTestChanges)).filter(targetNode -> {
        if (matchingBuildTargets.isPresent() && !matchingBuildTargets.get().contains(targetNode.getBuildTarget())) {
            return false;
        }
        if (descriptionClasses.isPresent() && !descriptionClasses.get().contains(targetNode.getDescription().getClass())) {
            return false;
        }
        return true;
    });
    ImmutableSortedMap.Builder<String, TargetNode<?, ?>> matchingNodesBuilder = ImmutableSortedMap.naturalOrder();
    for (TargetNode<?, ?> targetNode : selectedReferrers) {
        matchingNodesBuilder.put(targetNode.getBuildTarget().getFullyQualifiedName(), targetNode);
    }
    return matchingNodesBuilder.build();
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) InMemoryBuildFileTree(com.facebook.buck.model.InMemoryBuildFileTree) BuildFileTree(com.facebook.buck.model.BuildFileTree) InMemoryBuildFileTree(com.facebook.buck.model.InMemoryBuildFileTree) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with InMemoryBuildFileTree

use of com.facebook.buck.model.InMemoryBuildFileTree in project buck by facebook.

the class ProjectTest method getModulesForActionGraph.

private ProjectWithModules getModulesForActionGraph(BuildRuleResolver ruleResolver, ImmutableSortedSet<ProjectConfig> projectConfigs, @Nullable JavaPackageFinder javaPackageFinder, @Nullable IntellijConfig intellijConfig) throws IOException {
    if (javaPackageFinder == null) {
        javaPackageFinder = new FakeJavaPackageFinder();
    }
    if (intellijConfig == null) {
        intellijConfig = new IntellijConfig(FakeBuckConfig.builder().build());
    }
    // Create the Project.
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    Properties keystoreProperties = new Properties();
    keystoreProperties.put("key.alias", "androiddebugkey");
    keystoreProperties.put("key.store.password", "android");
    keystoreProperties.put("key.alias.password", "android");
    try (OutputStream output = projectFilesystem.newFileOutputStream(Paths.get("keystore/debug.keystore.properties"))) {
        keystoreProperties.store(output, "");
    }
    ImmutableMap<Path, String> basePathToAliasMap = ImmutableMap.of();
    Project project = new Project(new SourcePathResolver(new SourcePathRuleFinder(ruleResolver)), projectConfigs, basePathToAliasMap, javaPackageFinder, executionContext, new InMemoryBuildFileTree(Iterables.transform(ruleResolver.getBuildRules(), BuildRule::getBuildTarget)), projectFilesystem, /* pathToDefaultAndroidManifest */
    Optional.empty(), intellijConfig, /* pathToPostProcessScript */
    Optional.empty(), "python", ObjectMappers.newDefaultInstance(), true);
    // Execute Project's business logic.
    List<SerializableModule> modules = new ArrayList<>(project.createModulesForProjectConfigs());
    return new ProjectWithModules(project, ImmutableList.copyOf(modules));
}
Also used : Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) Properties(java.util.Properties) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) FakeJavaPackageFinder(com.facebook.buck.jvm.java.FakeJavaPackageFinder) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) InMemoryBuildFileTree(com.facebook.buck.model.InMemoryBuildFileTree) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem)

Aggregations

InMemoryBuildFileTree (com.facebook.buck.model.InMemoryBuildFileTree)2 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 FakeJavaPackageFinder (com.facebook.buck.jvm.java.FakeJavaPackageFinder)1 BuildFileTree (com.facebook.buck.model.BuildFileTree)1 BuildRule (com.facebook.buck.rules.BuildRule)1 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)1 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)1 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)1 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)1 TargetNode (com.facebook.buck.rules.TargetNode)1 ExecutionContext (com.facebook.buck.step.ExecutionContext)1 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)1 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 OutputStream (java.io.OutputStream)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1