use of com.google.common.collect.ImmutableSetMultimap 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();
}
}
use of com.google.common.collect.ImmutableSetMultimap in project buck by facebook.
the class JavaSymbolFinder method findTargetsForSymbols.
/**
* Figure out the build targets that provide a set of Java symbols.
* @param symbols The set of symbols (e.g. "com.example.foo.Bar") to find defining targets for.
* This is taken as a collection, rather than as an individual string, because
* instantiating a ProjectBuildFileParser is expensive (it spawns a Python
* subprocess), and we don't want to encourage the caller to do it more than once.
* @return A multimap of symbols to the targets that define them, of the form:
* {"com.example.a.A": set("//com/example/a:a", "//com/another/a:a")}
*/
public ImmutableSetMultimap<String, BuildTarget> findTargetsForSymbols(Set<String> symbols) throws InterruptedException, IOException {
// TODO(oconnor663): Handle files that aren't included in any rule.
// First find all the source roots in the current project.
Collection<Path> srcRoots;
try {
srcRoots = srcRootsFinder.getAllSrcRootPaths(config.getView(JavaBuckConfig.class).getSrcRoots());
} catch (IOException e) {
buckEventBus.post(ThrowableConsoleEvent.create(e, "Error while searching for source roots."));
return ImmutableSetMultimap.of();
}
// Now collect all the code files that define our symbols.
Multimap<String, Path> symbolsToSourceFiles = HashMultimap.create();
for (String symbol : symbols) {
symbolsToSourceFiles.putAll(symbol, getDefiningPaths(symbol, srcRoots));
}
// Now find all the targets that define all those code files. We do this in one pass because we
// don't want to instantiate a new parser subprocess for every symbol.
Set<Path> allSourceFilePaths = ImmutableSet.copyOf(symbolsToSourceFiles.values());
Multimap<Path, BuildTarget> sourceFilesToTargets = getTargetsForSourceFiles(allSourceFilePaths);
// Now build the map from from symbols to build targets.
ImmutableSetMultimap.Builder<String, BuildTarget> symbolsToTargets = ImmutableSetMultimap.builder();
for (String symbol : symbolsToSourceFiles.keySet()) {
for (Path sourceFile : symbolsToSourceFiles.get(symbol)) {
symbolsToTargets.putAll(symbol, sourceFilesToTargets.get(sourceFile));
}
}
return symbolsToTargets.build();
}
use of com.google.common.collect.ImmutableSetMultimap in project buck by facebook.
the class MissingSymbolsHandler method getNeededDependencies.
/**
* Using missing symbol events from the build and the JavaSymbolFinder class, build a list of
* missing dependencies for each broken target.
*/
public ImmutableSetMultimap<BuildTarget, BuildTarget> getNeededDependencies(Collection<MissingSymbolEvent> missingSymbolEvents) throws InterruptedException, IOException {
ImmutableSetMultimap.Builder<BuildTarget, String> targetsMissingSymbolsBuilder = ImmutableSetMultimap.builder();
for (MissingSymbolEvent event : missingSymbolEvents) {
if (event.getType() != MissingSymbolEvent.SymbolType.Java) {
throw new UnsupportedOperationException("Only implemented for Java.");
}
targetsMissingSymbolsBuilder.put(event.getTarget(), event.getSymbol());
}
ImmutableSetMultimap<BuildTarget, String> targetsMissingSymbols = targetsMissingSymbolsBuilder.build();
ImmutableSetMultimap<String, BuildTarget> symbolProviders = javaSymbolFinder.findTargetsForSymbols(ImmutableSet.copyOf(targetsMissingSymbols.values()));
ImmutableSetMultimap.Builder<BuildTarget, BuildTarget> neededDeps = ImmutableSetMultimap.builder();
for (BuildTarget target : targetsMissingSymbols.keySet()) {
for (String symbol : targetsMissingSymbols.get(target)) {
// TODO(oconnor663): Properly handle symbols that are defined in more than one place.
// TODO(oconnor663): Properly handle target visibility.
neededDeps.putAll(target, ImmutableSortedSet.copyOf(symbolProviders.get(symbol)));
}
}
return neededDeps.build();
}
use of com.google.common.collect.ImmutableSetMultimap in project buck by facebook.
the class ProjectGenerator method getCopyFilesBuildPhases.
private ImmutableList<PBXBuildPhase> getCopyFilesBuildPhases(Iterable<TargetNode<?, ?>> copiedNodes) {
// Bucket build rules into bins by their destinations
ImmutableSetMultimap.Builder<CopyFilePhaseDestinationSpec, TargetNode<?, ?>> ruleByDestinationSpecBuilder = ImmutableSetMultimap.builder();
for (TargetNode<?, ?> copiedNode : copiedNodes) {
Optional<CopyFilePhaseDestinationSpec> optionalDestinationSpec = getDestinationSpec(copiedNode);
if (optionalDestinationSpec.isPresent()) {
ruleByDestinationSpecBuilder.put(optionalDestinationSpec.get(), copiedNode);
}
}
ImmutableList.Builder<PBXBuildPhase> phases = ImmutableList.builder();
ImmutableSetMultimap<CopyFilePhaseDestinationSpec, TargetNode<?, ?>> ruleByDestinationSpec = ruleByDestinationSpecBuilder.build();
// Emit a copy files phase for each destination.
for (CopyFilePhaseDestinationSpec destinationSpec : ruleByDestinationSpec.keySet()) {
Iterable<TargetNode<?, ?>> targetNodes = ruleByDestinationSpec.get(destinationSpec);
phases.add(getSingleCopyFilesBuildPhase(destinationSpec, targetNodes));
}
return phases.build();
}
Aggregations