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)));
}
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();
}
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;
}
}
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"));
}
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));
}
}
Aggregations