Search in sources :

Example 6 with ImmutableSetMultimap

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();
    }
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) AppleTestDescription(com.facebook.buck.apple.AppleTestDescription) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Path(java.nio.file.Path) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) Optional(java.util.Optional) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 7 with ImmutableSetMultimap

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();
}
Also used : Path(java.nio.file.Path) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) BuildTarget(com.facebook.buck.model.BuildTarget) IOException(java.io.IOException)

Example 8 with ImmutableSetMultimap

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();
}
Also used : ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) BuildTarget(com.facebook.buck.model.BuildTarget) MissingSymbolEvent(com.facebook.buck.event.MissingSymbolEvent)

Example 9 with ImmutableSetMultimap

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();
}
Also used : CopyFilePhaseDestinationSpec(com.facebook.buck.apple.xcode.xcodeproj.CopyFilePhaseDestinationSpec) TargetNode(com.facebook.buck.rules.TargetNode) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) ImmutableList(com.google.common.collect.ImmutableList) PBXBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase)

Aggregations

ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)9 BuildTarget (com.facebook.buck.model.BuildTarget)3 Path (java.nio.file.Path)3 TargetNode (com.facebook.buck.rules.TargetNode)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 IOException (java.io.IOException)2 Collection (java.util.Collection)2 Element (javax.lang.model.element.Element)2 ExecutableElement (javax.lang.model.element.ExecutableElement)2 TypeElement (javax.lang.model.element.TypeElement)2 AppleTestDescription (com.facebook.buck.apple.AppleTestDescription)1 CopyFilePhaseDestinationSpec (com.facebook.buck.apple.xcode.xcodeproj.CopyFilePhaseDestinationSpec)1 PBXBuildPhase (com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase)1 PBXTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXTarget)1 MissingSymbolEvent (com.facebook.buck.event.MissingSymbolEvent)1 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)1 SuperficialValidation.validateElement (com.google.auto.common.SuperficialValidation.validateElement)1 Optional (com.google.common.base.Optional)1 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1