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