Search in sources :

Example 16 with TargetNode

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

the class IjModuleFactory method addAnnotationOutputIfNeeded.

@SuppressWarnings("unchecked")
private void addAnnotationOutputIfNeeded(IJFolderFactory folderFactory, TargetNode<?, ?> targetNode, ModuleBuildContext context) {
    TargetNode<? extends JvmLibraryArg, ?> jvmLibraryTargetNode = (TargetNode<? extends JvmLibraryArg, ?>) targetNode;
    Optional<Path> annotationOutput = moduleFactoryResolver.getAnnotationOutputPath(jvmLibraryTargetNode);
    if (!annotationOutput.isPresent()) {
        return;
    }
    Path annotationOutputPath = annotationOutput.get();
    context.addGeneratedSourceCodeFolder(folderFactory.create(annotationOutputPath, false, ImmutableSortedSet.of(annotationOutputPath)));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) TargetNode(com.facebook.buck.rules.TargetNode) JvmLibraryArg(com.facebook.buck.jvm.java.JvmLibraryArg)

Example 17 with TargetNode

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

the class IjModuleGraph method createModules.

/**
   * Create all the modules we are capable of representing in IntelliJ from the supplied graph.
   *
   * @param targetGraph graph whose nodes will be converted to {@link IjModule}s.
   * @return map which for every BuildTarget points to the corresponding IjModule. Multiple
   * BuildTarget can point to one IjModule (many:one mapping), the BuildTargets which
   * can't be prepresented in IntelliJ are missing from this mapping.
   */
private static ImmutableMap<BuildTarget, IjModule> createModules(IjProjectConfig projectConfig, TargetGraph targetGraph, IjModuleFactory moduleFactory, final int minimumPathDepth) {
    final BlockedPathNode blockedPathTree = createAggregationHaltPoints(projectConfig, targetGraph);
    ImmutableListMultimap<Path, TargetNode<?, ?>> baseTargetPathMultimap = targetGraph.getNodes().stream().filter(input -> IjModuleFactory.SUPPORTED_MODULE_DESCRIPTION_CLASSES.contains(input.getDescription().getClass())).collect(MoreCollectors.toImmutableListMultimap(targetNode -> {
        Path path;
        Path basePath = targetNode.getBuildTarget().getBasePath();
        if (targetNode.getConstructorArg() instanceof AndroidResourceDescription.Arg) {
            path = basePath;
        } else {
            path = simplifyPath(basePath, minimumPathDepth, blockedPathTree);
        }
        return path;
    }, targetNode -> targetNode));
    ImmutableMap.Builder<BuildTarget, IjModule> moduleMapBuilder = new ImmutableMap.Builder<>();
    for (Path baseTargetPath : baseTargetPathMultimap.keySet()) {
        ImmutableSet<TargetNode<?, ?>> targets = ImmutableSet.copyOf(baseTargetPathMultimap.get(baseTargetPath));
        IjModule module = moduleFactory.createModule(baseTargetPath, targets);
        for (TargetNode<?, ?> target : targets) {
            moduleMapBuilder.put(target.getBuildTarget(), module);
        }
    }
    return moduleMapBuilder.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TargetGraph(com.facebook.buck.rules.TargetGraph) TargetNode(com.facebook.buck.rules.TargetNode) Set(java.util.Set) HashMap(java.util.HashMap) JavacOptions(com.facebook.buck.jvm.java.JavacOptions) BuildTarget(com.facebook.buck.model.BuildTarget) AndroidResourceDescription(com.facebook.buck.android.AndroidResourceDescription) HashSet(java.util.HashSet) Objects(java.util.Objects) Stream(java.util.stream.Stream) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) Map(java.util.Map) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) JavaLibraryDescription(com.facebook.buck.jvm.java.JavaLibraryDescription) Path(java.nio.file.Path) Nullable(javax.annotation.Nullable) MoreCollectors(com.facebook.buck.util.MoreCollectors) Path(java.nio.file.Path) TargetNode(com.facebook.buck.rules.TargetNode) ImmutableMap(com.google.common.collect.ImmutableMap) AndroidResourceDescription(com.facebook.buck.android.AndroidResourceDescription) BuildTarget(com.facebook.buck.model.BuildTarget)

Example 18 with TargetNode

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

the class TargetNodeParsePipeline method computeNode.

@Override
protected TargetNode<?, ?> computeNode(final Cell cell, final BuildTarget buildTarget, final Map<String, Object> rawNode) throws BuildTargetException {
    try (final SimplePerfEvent.Scope scope = SimplePerfEvent.scopeIgnoringShortEvents(eventBus, PerfEventId.of("GetTargetNode"), "target", buildTarget, targetNodePipelineLifetimeEventScope, getMinimumPerfEventTimeMs(), TimeUnit.MILLISECONDS)) {
        Function<PerfEventId, SimplePerfEvent.Scope> perfEventScopeFunction = perfEventId -> SimplePerfEvent.scopeIgnoringShortEvents(eventBus, perfEventId, scope, getMinimumPerfEventTimeMs(), TimeUnit.MILLISECONDS);
        final TargetNode<?, ?> targetNode = delegate.createTargetNode(cell, cell.getAbsolutePathToBuildFile(buildTarget), buildTarget, rawNode, perfEventScopeFunction);
        if (speculativeDepsTraversal) {
            executorService.submit(() -> {
                for (BuildTarget depTarget : targetNode.getDeps()) {
                    Path depCellPath = depTarget.getCellPath();
                    // non-threadsafe way making it inconvenient to access from the pipeline.
                    if (depCellPath.equals(cell.getRoot())) {
                        try {
                            if (depTarget.isFlavored()) {
                                getNodeJob(cell, BuildTarget.of(depTarget.getUnflavoredBuildTarget()));
                            }
                            getNodeJob(cell, depTarget);
                        } catch (BuildTargetException e) {
                            // No biggie, we'll hit the error again in the non-speculative path.
                            LOG.info(e, "Could not schedule speculative parsing for %s", depTarget);
                        }
                    }
                }
            });
        }
        return targetNode;
    }
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) Logger(com.facebook.buck.log.Logger) PerfEventId(com.facebook.buck.event.PerfEventId) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TargetNode(com.facebook.buck.rules.TargetNode) SimplePerfEvent(com.facebook.buck.event.SimplePerfEvent) BuildTargetException(com.facebook.buck.model.BuildTargetException) ThreadSafe(javax.annotation.concurrent.ThreadSafe) BuildTarget(com.facebook.buck.model.BuildTarget) TimeUnit(java.util.concurrent.TimeUnit) Map(java.util.Map) Cache(com.facebook.buck.parser.PipelineNodeCache.Cache) Cell(com.facebook.buck.rules.Cell) Path(java.nio.file.Path) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Path(java.nio.file.Path) BuildTargetException(com.facebook.buck.model.BuildTargetException) PerfEventId(com.facebook.buck.event.PerfEventId) BuildTarget(com.facebook.buck.model.BuildTarget) SimplePerfEvent(com.facebook.buck.event.SimplePerfEvent)

Example 19 with TargetNode

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

the class APKModuleTest method testAPKModuleGraphSimple.

/*
                          + - - - - - -+
                        ' root:      '
                        '            '
                        ' +--------+ '
        +-------------- ' | Binary | ' --------+
        |               ' +--------+ '         |
        |               '   |        '         |
        |               '   |        '         |
        v               '   |        '         v
    + - - - - - - +     '   |        '     +- - - - - +
    ' android:    '     '   |        '     ' java:    '
    '             '     '   |        '     '          '
    ' +---------+ '     '   |        '     ' +------+ '
    ' | Android | '     '   |        '     ' | Java | '
    ' +---------+ '     '   |        '     ' +------+ '
    '             '     '   |        '     '          '
    + - - - - - - +     '   |        '     +- - - - - +
        |               '   |        '         |
        |               '   |        '         |
        |               '   v        '         |
        |               ' +--------+ '         |
        +-------------> ' | Common | ' <-------+
                        ' +--------+ '
                        '            '
                        + - - - - - -+
   */
@Test
public void testAPKModuleGraphSimple() throws Exception {
    ImmutableSet.Builder<TargetNode<?, ?>> nodeBuilder = ImmutableSet.builder();
    BuildTarget commonLibraryTarget = BuildTargetFactory.newInstance("//src/com/facebook/test-common-library:test-common-library");
    nodeBuilder.add(AndroidLibraryBuilder.createBuilder(commonLibraryTarget).addSrc(Paths.get("src/com/facebook/TestCommonLibrary.java")).build());
    BuildTarget javaLibraryTarget = BuildTargetFactory.newInstance("//src/com/facebook/test-java-library:test-java-library").withFlavors(InternalFlavor.of("flavor"));
    nodeBuilder.add(JavaLibraryBuilder.createBuilder(javaLibraryTarget).addSrc(Paths.get("src/com/facebook/TestJavaLibrary.java")).addDep(commonLibraryTarget).build());
    BuildTarget androidLibraryTarget = BuildTargetFactory.newInstance("//src/com/facebook/test-android-library:test-android-library");
    nodeBuilder.add(AndroidLibraryBuilder.createBuilder(androidLibraryTarget).addSrc(Paths.get("src/com/facebook/TestAndroidLibrary.java")).addDep(commonLibraryTarget).build());
    BuildTarget keystoreTarget = BuildTargetFactory.newInstance("//:keystore");
    nodeBuilder.add(KeystoreBuilder.createBuilder(keystoreTarget).setStore(new FakeSourcePath("debug.keystore")).setProperties(new FakeSourcePath("keystore.properties")).build());
    BuildTarget androidBinaryTarget = BuildTargetFactory.newInstance("//src/com/facebook/test-android-binary:test-android-binary");
    nodeBuilder.add(AndroidBinaryBuilder.createBuilder(androidBinaryTarget).setManifest(new FakeSourcePath("AndroidManifest.xml")).setKeystore(keystoreTarget).setOriginalDeps(ImmutableSortedSet.of(androidLibraryTarget, javaLibraryTarget, commonLibraryTarget)).build());
    TargetGraph graph = TargetGraphFactory.newInstance(nodeBuilder.build());
    Set<BuildTarget> seedTargets = new HashSet<>();
    seedTargets.add(androidLibraryTarget);
    seedTargets.add(javaLibraryTarget);
    APKModuleGraph dag = new APKModuleGraph(graph, androidBinaryTarget, Optional.of(seedTargets));
    ImmutableSet<APKModule> topLevelNodes = dag.getGraph().getNodesWithNoIncomingEdges();
    assertThat(topLevelNodes.size(), is(2));
    for (APKModule apkModule : topLevelNodes) {
        assertThat(apkModule.getName(), oneOf("src.com.facebook.test.android.library", "src.com.facebook.test.java.library.test.java.library.flavor"));
        ImmutableSet<APKModule> dependencies = dag.getGraph().getOutgoingNodesFor(apkModule);
        assertThat(apkModule.isRootModule(), is(false));
        assertThat(dependencies.size(), is(1));
        assertThat(Iterables.getFirst(dependencies, null).getName(), is(APKModuleGraph.ROOT_APKMODULE_NAME));
        assertThat(Iterables.getFirst(dependencies, null).isRootModule(), is(true));
    }
    assertThat(dag.getAPKModules().stream().map(APKModule::getName).collect(MoreCollectors.toImmutableSet()), containsInAnyOrder("dex", "src.com.facebook.test.android.library", "src.com.facebook.test.java.library.test.java.library.flavor"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) TargetNode(com.facebook.buck.rules.TargetNode) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) TargetGraph(com.facebook.buck.rules.TargetGraph) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 20 with TargetNode

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

the class AppleBuildRulesTest method linkingStopsAtGenruleDep.

@Test
public void linkingStopsAtGenruleDep() throws Exception {
    // Pass a random static lib in a genrule and make sure a framework
    // depending on the genrule doesn't link against or copy in the static lib.
    BuildTarget fooLibTarget = BuildTargetFactory.newInstance("//foo:lib");
    TargetNode<?, ?> fooLibNode = AppleLibraryBuilder.createBuilder(fooLibTarget).build();
    BuildTarget fooGenruleTarget = BuildTargetFactory.newInstance("//foo:genrule");
    TargetNode<?, ?> fooGenruleNode = GenruleBuilder.newGenruleBuilder(fooGenruleTarget).setOut("foo").setCmd("echo hi > $OUT").setSrcs(ImmutableList.of(new DefaultBuildTargetSourcePath(fooLibTarget))).build();
    BuildTarget barLibTarget = BuildTargetFactory.newInstance("//bar:lib#" + CxxDescriptionEnhancer.SHARED_FLAVOR);
    TargetNode<?, ?> barLibNode = AppleLibraryBuilder.createBuilder(barLibTarget).setDeps(ImmutableSortedSet.of(fooGenruleTarget)).build();
    BuildTarget barFrameworkTarget = BuildTargetFactory.newInstance("//bar:framework");
    TargetNode<?, ?> barFrameworkNode = AppleBundleBuilder.createBuilder(barFrameworkTarget).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setBinary(barLibTarget).build();
    ImmutableSet<TargetNode<?, ?>> targetNodes = ImmutableSet.<TargetNode<?, ?>>builder().add(fooLibNode, fooGenruleNode, barLibNode, barFrameworkNode).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(targetNodes);
    Optional<AppleDependenciesCache> cache = useCache ? Optional.of(new AppleDependenciesCache(targetGraph)) : Optional.empty();
    for (int i = 0; i < (useCache ? 2 : 1); i++) {
        Iterable<TargetNode<?, ?>> rules = AppleBuildRules.getRecursiveTargetNodeDependenciesOfTypes(targetGraph, cache, AppleBuildRules.RecursiveDependenciesMode.LINKING, barFrameworkNode, Optional.empty());
        assertEquals(ImmutableSortedSet.of(fooGenruleNode), ImmutableSortedSet.copyOf(rules));
    }
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) BuildTarget(com.facebook.buck.model.BuildTarget) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) Test(org.junit.Test)

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