use of com.google.common.collect.ImmutableMultimap in project buck by facebook.
the class ProjectGenerator method generateBinaryTarget.
private PBXNativeTarget generateBinaryTarget(PBXProject project, Optional<? extends TargetNode<? extends HasAppleBundleFields, ?>> bundle, TargetNode<? extends CxxLibraryDescription.Arg, ?> targetNode, ProductType productType, String productOutputFormat, Optional<Path> infoPlistOptional, boolean includeFrameworks, ImmutableSet<AppleResourceDescription.Arg> recursiveResources, ImmutableSet<AppleResourceDescription.Arg> directResources, ImmutableSet<AppleAssetCatalogDescription.Arg> recursiveAssetCatalogs, ImmutableSet<AppleAssetCatalogDescription.Arg> directAssetCatalogs, ImmutableSet<AppleWrapperResourceArg> wrapperResources, Optional<Iterable<PBXBuildPhase>> copyFilesPhases, Optional<TargetNode<AppleBundleDescription.Arg, ?>> bundleLoaderNode) throws IOException {
LOG.debug("Generating binary target for node %s", targetNode);
TargetNode<?, ?> buildTargetNode = bundle.isPresent() ? bundle.get() : targetNode;
final BuildTarget buildTarget = buildTargetNode.getBuildTarget();
String buildTargetName = getProductNameForBuildTarget(buildTarget);
CxxLibraryDescription.Arg arg = targetNode.getConstructorArg();
NewNativeTargetProjectMutator mutator = new NewNativeTargetProjectMutator(pathRelativizer, this::resolveSourcePath);
ImmutableSet<SourcePath> exportedHeaders = ImmutableSet.copyOf(getHeaderSourcePaths(arg.exportedHeaders));
ImmutableSet<SourcePath> headers = ImmutableSet.copyOf(getHeaderSourcePaths(arg.headers));
ImmutableMap<CxxSource.Type, ImmutableList<String>> langPreprocessorFlags = targetNode.getConstructorArg().langPreprocessorFlags;
mutator.setTargetName(getXcodeTargetName(buildTarget)).setProduct(productType, buildTargetName, Paths.get(String.format(productOutputFormat, buildTargetName)));
boolean isFocusedOnTarget = buildTarget.matchesUnflavoredTargets(focusModules);
Optional<TargetNode<AppleNativeTargetDescriptionArg, ?>> appleTargetNode = targetNode.castArg(AppleNativeTargetDescriptionArg.class);
if (!shouldGenerateHeaderSymlinkTreesOnly()) {
if (isFocusedOnTarget) {
mutator.setLangPreprocessorFlags(langPreprocessorFlags).setPublicHeaders(exportedHeaders).setPrefixHeader(arg.prefixHeader).setSourcesWithFlags(ImmutableSet.copyOf(arg.srcs)).setPrivateHeaders(headers).setRecursiveResources(recursiveResources).setDirectResources(directResources).setWrapperResources(wrapperResources);
}
if (bundle.isPresent() && isFocusedOnTarget) {
HasAppleBundleFields bundleArg = bundle.get().getConstructorArg();
mutator.setInfoPlist(Optional.of(bundleArg.getInfoPlist()));
}
mutator.setBridgingHeader(arg.bridgingHeader);
if (appleTargetNode.isPresent() && isFocusedOnTarget) {
AppleNativeTargetDescriptionArg appleArg = appleTargetNode.get().getConstructorArg();
mutator = mutator.setExtraXcodeSources(ImmutableSet.copyOf(appleArg.extraXcodeSources));
}
if (options.contains(Option.CREATE_DIRECTORY_STRUCTURE) && isFocusedOnTarget) {
mutator.setTargetGroupPath(StreamSupport.stream(buildTarget.getBasePath().spliterator(), false).map(Object::toString).collect(MoreCollectors.toImmutableList()));
}
if (!recursiveAssetCatalogs.isEmpty() && isFocusedOnTarget) {
mutator.setRecursiveAssetCatalogs(recursiveAssetCatalogs);
}
if (!directAssetCatalogs.isEmpty() && isFocusedOnTarget) {
mutator.setDirectAssetCatalogs(directAssetCatalogs);
}
if (includeFrameworks && isFocusedOnTarget) {
ImmutableSet.Builder<FrameworkPath> frameworksBuilder = ImmutableSet.builder();
frameworksBuilder.addAll(targetNode.getConstructorArg().frameworks);
frameworksBuilder.addAll(targetNode.getConstructorArg().libraries);
frameworksBuilder.addAll(collectRecursiveFrameworkDependencies(ImmutableList.of(targetNode)));
mutator.setFrameworks(frameworksBuilder.build());
mutator.setArchives(collectRecursiveLibraryDependencies(ImmutableList.of(targetNode)));
}
// TODO(Task #3772930): Go through all dependencies of the rule
// and add any shell script rules here
ImmutableList.Builder<TargetNode<?, ?>> preScriptPhases = ImmutableList.builder();
ImmutableList.Builder<TargetNode<?, ?>> postScriptPhases = ImmutableList.builder();
if (bundle.isPresent() && targetNode != bundle.get() && isFocusedOnTarget) {
collectBuildScriptDependencies(targetGraph.getAll(bundle.get().getDeclaredDeps()), preScriptPhases, postScriptPhases);
}
collectBuildScriptDependencies(targetGraph.getAll(targetNode.getDeclaredDeps()), preScriptPhases, postScriptPhases);
if (isFocusedOnTarget) {
mutator.setPreBuildRunScriptPhasesFromTargetNodes(preScriptPhases.build());
if (copyFilesPhases.isPresent()) {
mutator.setCopyFilesPhases(copyFilesPhases.get());
}
mutator.setPostBuildRunScriptPhasesFromTargetNodes(postScriptPhases.build());
}
}
NewNativeTargetProjectMutator.Result targetBuilderResult = mutator.buildTargetAndAddToProject(project, isFocusedOnTarget);
PBXNativeTarget target = targetBuilderResult.target;
Optional<PBXGroup> targetGroup = targetBuilderResult.targetGroup;
ImmutableMap.Builder<String, String> extraSettingsBuilder = ImmutableMap.builder();
ImmutableMap.Builder<String, String> defaultSettingsBuilder = ImmutableMap.builder();
if (!shouldGenerateHeaderSymlinkTreesOnly()) {
if (isFocusedOnTarget) {
SourceTreePath buckFilePath = new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputPathToBuildTargetPath(buildTarget).resolve(buildFileName), Optional.empty());
PBXFileReference buckReference = targetGroup.get().getOrCreateFileReferenceBySourceTreePath(buckFilePath);
buckReference.setExplicitFileType(Optional.of("text.script.python"));
}
// -- configurations
extraSettingsBuilder.put("TARGET_NAME", buildTargetName).put("SRCROOT", pathRelativizer.outputPathToBuildTargetPath(buildTarget).toString());
if (productType == ProductType.UI_TEST && isFocusedOnTarget) {
if (bundleLoaderNode.isPresent()) {
BuildTarget testTarget = bundleLoaderNode.get().getBuildTarget();
extraSettingsBuilder.put("TEST_TARGET_NAME", getXcodeTargetName(testTarget));
} else {
throw new HumanReadableException("The test rule '%s' is configured with 'is_ui_test' but has no test_host_app", buildTargetName);
}
} else if (bundleLoaderNode.isPresent() && isFocusedOnTarget) {
TargetNode<AppleBundleDescription.Arg, ?> bundleLoader = bundleLoaderNode.get();
String bundleLoaderProductName = getProductNameForBuildTarget(bundleLoader.getBuildTarget());
String bundleLoaderBundleName = bundleLoaderProductName + "." + getExtensionString(bundleLoader.getConstructorArg().getExtension());
// NOTE(grp): This is a hack. We need to support both deep (OS X) and flat (iOS)
// style bundles for the bundle loader, but at this point we don't know what platform
// the bundle loader (or current target) is going to be built for. However, we can be
// sure that it's the same as the target (presumably a test) we're building right now.
//
// Using that knowledge, we can do build setting tricks to defer choosing the bundle
// loader path until Xcode build time, when the platform is known. There's no build
// setting that conclusively says whether the current platform uses deep bundles:
// that would be too easy. But in the cases we care about (unit test bundles), the
// current bundle will have a style matching the style of the bundle loader app, so
// we can take advantage of that to do the determination.
//
// Unfortunately, the build setting for the bundle structure (CONTENTS_FOLDER_PATH)
// includes the WRAPPER_NAME, so we can't just interpolate that in. Instead, we have
// to use another trick with build setting operations and evaluation. By using the
// $(:file) operation, we can extract the last component of the contents path: either
// "Contents" or the current bundle name. Then, we can interpolate with that expected
// result in the build setting name to conditionally choose a different loader path.
// The conditional that decides which path is used. This is a complex Xcode build setting
// expression that expands to one of two values, depending on the last path component of
// the CONTENTS_FOLDER_PATH variable. As described above, this will be either "Contents"
// for deep bundles or the bundle file name itself for flat bundles. Finally, to santiize
// the potentially invalid build setting names from the bundle file name, it converts that
// to an identifier. We rely on BUNDLE_LOADER_BUNDLE_STYLE_CONDITIONAL_<bundle file name>
// being undefined (and thus expanding to nothing) for the path resolution to work.
//
// The operations on the CONTENTS_FOLDER_PATH are documented here:
// http://codeworkshop.net/posts/xcode-build-setting-transformations
String bundleLoaderOutputPathConditional = "$(BUNDLE_LOADER_BUNDLE_STYLE_CONDITIONAL_$(CONTENTS_FOLDER_PATH:file:identifier))";
// If the $(CONTENTS_FOLDER_PATH:file:identifier) expands to this, we add the deep bundle
// path into the bundle loader. See above for the case when it will expand to this value.
String bundleLoaderOutputPathDeepSetting = "BUNDLE_LOADER_BUNDLE_STYLE_CONDITIONAL_Contents";
String bundleLoaderOutputPathDeepValue = "Contents/MacOS/";
String bundleLoaderOutputPathValue = Joiner.on('/').join(getTargetOutputPath(bundleLoader), bundleLoaderBundleName, bundleLoaderOutputPathConditional, bundleLoaderProductName);
extraSettingsBuilder.put(bundleLoaderOutputPathDeepSetting, bundleLoaderOutputPathDeepValue).put("BUNDLE_LOADER", bundleLoaderOutputPathValue).put("TEST_HOST", "$(BUNDLE_LOADER)");
}
if (infoPlistOptional.isPresent()) {
Path infoPlistPath = pathRelativizer.outputDirToRootRelative(infoPlistOptional.get());
extraSettingsBuilder.put("INFOPLIST_FILE", infoPlistPath.toString());
}
if (arg.bridgingHeader.isPresent()) {
Path bridgingHeaderPath = pathRelativizer.outputDirToRootRelative(resolveSourcePath(arg.bridgingHeader.get()));
extraSettingsBuilder.put("SWIFT_OBJC_BRIDGING_HEADER", Joiner.on('/').join("$(SRCROOT)", bridgingHeaderPath.toString()));
}
Optional<String> swiftVersion = swiftBuckConfig.getVersion();
if (swiftVersion.isPresent()) {
extraSettingsBuilder.put("SWIFT_VERSION", swiftVersion.get());
}
Optional<SourcePath> prefixHeaderOptional = targetNode.getConstructorArg().prefixHeader;
if (prefixHeaderOptional.isPresent()) {
Path prefixHeaderRelative = resolveSourcePath(prefixHeaderOptional.get());
Path prefixHeaderPath = pathRelativizer.outputDirToRootRelative(prefixHeaderRelative);
extraSettingsBuilder.put("GCC_PREFIX_HEADER", prefixHeaderPath.toString());
extraSettingsBuilder.put("GCC_PRECOMPILE_PREFIX_HEADER", "YES");
}
extraSettingsBuilder.put("USE_HEADERMAP", "NO");
defaultSettingsBuilder.put("REPO_ROOT", projectFilesystem.getRootPath().toAbsolutePath().normalize().toString());
defaultSettingsBuilder.put(PRODUCT_NAME, getProductName(buildTargetNode, buildTarget));
if (bundle.isPresent()) {
defaultSettingsBuilder.put("WRAPPER_EXTENSION", getExtensionString(bundle.get().getConstructorArg().getExtension()));
}
// We use BUILT_PRODUCTS_DIR as the root for the everything being built. Target-
// specific output is placed within CONFIGURATION_BUILD_DIR, inside BUILT_PRODUCTS_DIR.
// That allows Copy Files build phases to reference files in the CONFIGURATION_BUILD_DIR
// of other targets by using paths relative to the target-independent BUILT_PRODUCTS_DIR.
defaultSettingsBuilder.put("BUILT_PRODUCTS_DIR", // $SYMROOT/Debug-iphonesimulator
Joiner.on('/').join("$SYMROOT", "$CONFIGURATION$EFFECTIVE_PLATFORM_NAME"));
defaultSettingsBuilder.put("CONFIGURATION_BUILD_DIR", "$BUILT_PRODUCTS_DIR");
boolean nodeIsAppleLibrary = targetNode.getDescription() instanceof AppleLibraryDescription;
boolean nodeIsCxxLibrary = targetNode.getDescription() instanceof CxxLibraryDescription;
if (!bundle.isPresent() && (nodeIsAppleLibrary || nodeIsCxxLibrary)) {
defaultSettingsBuilder.put("EXECUTABLE_PREFIX", "lib");
}
if (isFocusedOnTarget) {
ImmutableSet<Path> recursiveHeaderSearchPaths = collectRecursiveHeaderSearchPaths(targetNode);
ImmutableSet<Path> headerMapBases = recursiveHeaderSearchPaths.isEmpty() ? ImmutableSet.of() : ImmutableSet.of(pathRelativizer.outputDirToRootRelative(buildTargetNode.getFilesystem().getBuckPaths().getBuckOut()));
ImmutableMap.Builder<String, String> appendConfigsBuilder = ImmutableMap.builder();
appendConfigsBuilder.put("HEADER_SEARCH_PATHS", Joiner.on(' ').join(Iterables.concat(recursiveHeaderSearchPaths, headerMapBases))).put("LIBRARY_SEARCH_PATHS", Joiner.on(' ').join(collectRecursiveLibrarySearchPaths(ImmutableSet.of(targetNode)))).put("FRAMEWORK_SEARCH_PATHS", Joiner.on(' ').join(collectRecursiveFrameworkSearchPaths(ImmutableList.of(targetNode))));
Iterable<String> otherCFlags = Iterables.concat(cxxBuckConfig.getFlags("cflags").orElse(DEFAULT_CFLAGS), collectRecursiveExportedPreprocessorFlags(ImmutableList.of(targetNode)), targetNode.getConstructorArg().compilerFlags, targetNode.getConstructorArg().preprocessorFlags);
Iterable<String> otherCxxFlags = Iterables.concat(cxxBuckConfig.getFlags("cxxflags").orElse(DEFAULT_CXXFLAGS), collectRecursiveExportedPreprocessorFlags(ImmutableList.of(targetNode)), targetNode.getConstructorArg().compilerFlags, targetNode.getConstructorArg().preprocessorFlags);
ImmutableList<String> otherLdFlags = convertStringWithMacros(targetNode, Iterables.concat(targetNode.getConstructorArg().linkerFlags, collectRecursiveExportedLinkerFlags(ImmutableList.of(targetNode))));
appendConfigsBuilder.put("OTHER_CFLAGS", Joiner.on(' ').join(Iterables.transform(otherCFlags, Escaper.BASH_ESCAPER))).put("OTHER_CPLUSPLUSFLAGS", Joiner.on(' ').join(Iterables.transform(otherCxxFlags, Escaper.BASH_ESCAPER))).put("OTHER_LDFLAGS", Joiner.on(' ').join(Iterables.transform(otherLdFlags, Escaper.BASH_ESCAPER)));
ImmutableMultimap.Builder<String, ImmutableList<String>> platformFlagsBuilder = ImmutableMultimap.builder();
for (Pair<Pattern, ImmutableList<String>> flags : Iterables.concat(targetNode.getConstructorArg().platformCompilerFlags.getPatternsAndValues(), targetNode.getConstructorArg().platformPreprocessorFlags.getPatternsAndValues(), collectRecursiveExportedPlatformPreprocessorFlags(ImmutableList.of(targetNode)))) {
String sdk = flags.getFirst().pattern().replaceAll("[*.]", "");
platformFlagsBuilder.put(sdk, flags.getSecond());
}
ImmutableMultimap<String, ImmutableList<String>> platformFlags = platformFlagsBuilder.build();
for (String sdk : platformFlags.keySet()) {
appendConfigsBuilder.put(String.format("OTHER_CFLAGS[sdk=*%s*]", sdk), Joiner.on(' ').join(Iterables.transform(Iterables.concat(otherCFlags, Iterables.concat(platformFlags.get(sdk))), Escaper.BASH_ESCAPER))).put(String.format("OTHER_CPLUSPLUSFLAGS[sdk=*%s*]", sdk), Joiner.on(' ').join(Iterables.transform(Iterables.concat(otherCxxFlags, Iterables.concat(platformFlags.get(sdk))), Escaper.BASH_ESCAPER)));
}
ImmutableMultimap.Builder<String, ImmutableList<String>> platformLinkerFlagsBuilder = ImmutableMultimap.builder();
for (Pair<Pattern, ImmutableList<StringWithMacros>> flags : Iterables.concat(targetNode.getConstructorArg().platformLinkerFlags.getPatternsAndValues(), collectRecursiveExportedPlatformLinkerFlags(ImmutableList.of(targetNode)))) {
String sdk = flags.getFirst().pattern().replaceAll("[*.]", "");
platformLinkerFlagsBuilder.put(sdk, convertStringWithMacros(targetNode, flags.getSecond()));
}
ImmutableMultimap<String, ImmutableList<String>> platformLinkerFlags = platformLinkerFlagsBuilder.build();
for (String sdk : platformLinkerFlags.keySet()) {
appendConfigsBuilder.put(String.format("OTHER_LDFLAGS[sdk=*%s*]", sdk), Joiner.on(' ').join(Iterables.transform(Iterables.concat(otherLdFlags, Iterables.concat(platformLinkerFlags.get(sdk))), Escaper.BASH_ESCAPER)));
}
ImmutableMap<String, String> appendedConfig = appendConfigsBuilder.build();
Optional<ImmutableSortedMap<String, ImmutableMap<String, String>>> configs = getXcodeBuildConfigurationsForTargetNode(targetNode, appendedConfig);
setTargetBuildConfigurations(getConfigurationNameToXcconfigPath(buildTarget), target, project.getMainGroup(), configs.get(), extraSettingsBuilder.build(), defaultSettingsBuilder.build(), appendedConfig);
}
}
// -- phases
createHeaderSymlinkTree(getPublicCxxHeaders(targetNode), getPathToHeaderSymlinkTree(targetNode, HeaderVisibility.PUBLIC), arg.xcodePublicHeadersSymlinks.orElse(true) || isHeaderMapDisabled(), !shouldMergeHeaderMaps());
if (isFocusedOnTarget) {
createHeaderSymlinkTree(getPrivateCxxHeaders(targetNode), getPathToHeaderSymlinkTree(targetNode, HeaderVisibility.PRIVATE), arg.xcodePrivateHeadersSymlinks.orElse(true) || isHeaderMapDisabled(), !isHeaderMapDisabled());
}
if (shouldMergeHeaderMaps() && isMainProject) {
createMergedHeaderMap();
}
if (appleTargetNode.isPresent() && isFocusedOnTarget && !shouldGenerateHeaderSymlinkTreesOnly()) {
// Use Core Data models from immediate dependencies only.
addCoreDataModelsIntoTarget(appleTargetNode.get(), targetGroup.get());
addSceneKitAssetsIntoTarget(appleTargetNode.get(), targetGroup.get());
}
return target;
}
use of com.google.common.collect.ImmutableMultimap in project buck by facebook.
the class DalvikAwareZipSplitter method execute.
@Override
public ImmutableMultimap<APKModule, Path> execute() throws IOException {
ClasspathTraverser classpathTraverser = new DefaultClasspathTraverser();
final Set<String> secondaryTail = new HashSet<String>();
// Start out by writing the primary zip and recording which entries were added to it.
primaryOut = newZipOutput(outPrimary);
secondaryDexWriter.reset();
final ImmutableMap.Builder<String, FileLike> entriesBuilder = ImmutableMap.builder();
final List<String> additionalDexStoreEntries = new ArrayList<>();
// Iterate over all of the inFiles and add all entries that match the requiredInPrimaryZip
// predicate.
LOG.debug("Traversing classpath for primary zip");
classpathTraverser.traverse(new ClasspathTraversal(inFiles, filesystem) {
@Override
public void visit(FileLike entry) throws IOException {
LOG.debug("Visiting " + entry.getRelativePath());
String relativePath = entry.getRelativePath();
if (!relativePath.endsWith(".class")) {
// We don't need resources in dex jars, so just drop them.
return;
}
Preconditions.checkNotNull(primaryOut);
Preconditions.checkNotNull(classPathToDexStore);
if (requiredInPrimaryZip.apply(relativePath)) {
primaryOut.putEntry(entry);
} else if (wantedInPrimaryZip.contains(relativePath) || (secondaryHeadSet != null && secondaryHeadSet.contains(relativePath))) {
entriesBuilder.put(relativePath, new BufferedFileLike(entry));
} else if (secondaryTailSet != null && secondaryTailSet.contains(relativePath)) {
entriesBuilder.put(relativePath, new BufferedFileLike(entry));
secondaryTail.add(relativePath);
} else {
ImmutableCollection<APKModule> containingModule = classPathToDexStore.get(relativePath);
if (!containingModule.isEmpty()) {
if (containingModule.size() > 1) {
throw new IllegalStateException(String.format("classpath %s is contained in multiple dex stores: %s", relativePath, classPathToDexStore.get(relativePath).asList().toString()));
}
APKModule dexStore = containingModule.iterator().next();
if (!dexStore.equals(apkModuleGraph.getRootAPKModule())) {
MySecondaryDexHelper dexHelper = additionalDexWriters.get(dexStore);
Preconditions.checkNotNull(dexHelper);
dexHelper.getOutputToWriteTo(entry).putEntry(entry);
additionalDexStoreEntries.add(relativePath);
}
}
}
}
});
// Put as many of the items wanted in the primary dex as we can into the primary dex.
ImmutableMap<String, FileLike> entries = entriesBuilder.build();
for (String wanted : wantedInPrimaryZip) {
FileLike entry = entries.get(wanted);
if ((entry != null) && !primaryOut.containsEntry(entry) && primaryOut.canPutEntry(entry)) {
primaryOut.putEntry(entry);
}
}
if (secondaryHeadSet != null) {
for (String head : secondaryHeadSet) {
FileLike headEntry = entries.get(head);
if ((headEntry != null) && !primaryOut.containsEntry(headEntry)) {
secondaryDexWriter.getOutputToWriteTo(headEntry).putEntry(headEntry);
}
}
}
LOG.debug("Traversing classpath for secondary zip");
// Now that all of the required entries have been added to the primary zip, fill the rest of
// the zip up with the remaining entries.
classpathTraverser.traverse(new ClasspathTraversal(inFiles, filesystem) {
@Override
public void visit(FileLike entry) throws IOException {
Preconditions.checkNotNull(primaryOut);
String relativePath = entry.getRelativePath();
// skip if it is the primary dex, is part of a modular dex store, or is not a class file
if (primaryOut.containsEntry(entry) || additionalDexStoreEntries.contains(relativePath)) {
return;
}
LOG.debug("Visiting " + entry.getRelativePath());
// room in the primary dex for the current entry in the traversal.
if (dexSplitStrategy == DexSplitStrategy.MAXIMIZE_PRIMARY_DEX_SIZE && primaryOut.canPutEntry(entry)) {
primaryOut.putEntry(entry);
} else {
if (secondaryHeadSet != null && secondaryHeadSet.contains(relativePath)) {
return;
}
if (secondaryTail.contains(relativePath)) {
return;
}
secondaryDexWriter.getOutputToWriteTo(entry).putEntry(entry);
}
}
});
if (secondaryTailSet != null) {
for (String tail : secondaryTailSet) {
FileLike tailEntry = entries.get(tail);
if ((tailEntry != null) && !primaryOut.containsEntry(tailEntry) && secondaryTail.contains(tail)) {
secondaryDexWriter.getOutputToWriteTo(tailEntry).putEntry(tailEntry);
}
}
}
primaryOut.close();
secondaryDexWriter.close();
ImmutableMultimap.Builder<APKModule, Path> outputFilesBuilder = ImmutableMultimap.builder();
APKModule secondaryDexStore = apkModuleGraph.getRootAPKModule();
outputFilesBuilder.putAll(secondaryDexStore, secondaryDexWriter.getFiles());
for (Map.Entry<APKModule, MySecondaryDexHelper> entry : additionalDexWriters.entrySet()) {
if (!entry.getKey().equals(secondaryDexStore)) {
entry.getValue().close();
outputFilesBuilder.putAll(entry.getKey(), entry.getValue().getFiles());
}
}
return outputFilesBuilder.build();
}
use of com.google.common.collect.ImmutableMultimap in project buck by facebook.
the class RuleUtils method createGroupsFromSourcePaths.
public static ImmutableList<GroupedSource> createGroupsFromSourcePaths(Function<SourcePath, Path> resolver, Iterable<SourceWithFlags> sources, Iterable<SourcePath> extraXcodeSources, Iterable<SourcePath> publicHeaders, Iterable<SourcePath> privateHeaders) {
Path rootPath = Paths.get("root");
ImmutableMultimap.Builder<Path, GroupedSource> entriesBuilder = ImmutableMultimap.builder();
for (SourceWithFlags sourceWithFlags : sources) {
Path path = rootPath.resolve(resolver.apply(sourceWithFlags.getSourcePath()));
GroupedSource groupedSource = GroupedSource.ofSourceWithFlags(sourceWithFlags);
entriesBuilder.put(Preconditions.checkNotNull(path.getParent()), groupedSource);
}
for (SourcePath sourcePath : extraXcodeSources) {
Path path = rootPath.resolve(resolver.apply(sourcePath));
GroupedSource groupedSource = GroupedSource.ofSourceWithFlags(SourceWithFlags.of(sourcePath));
entriesBuilder.put(Preconditions.checkNotNull(path.getParent()), groupedSource);
}
for (SourcePath publicHeader : publicHeaders) {
Path path = rootPath.resolve(resolver.apply(publicHeader));
GroupedSource groupedSource = GroupedSource.ofPublicHeader(publicHeader);
entriesBuilder.put(Preconditions.checkNotNull(path.getParent()), groupedSource);
}
for (SourcePath privateHeader : privateHeaders) {
Path path = rootPath.resolve(resolver.apply(privateHeader));
GroupedSource groupedSource = GroupedSource.ofPrivateHeader(privateHeader);
entriesBuilder.put(Preconditions.checkNotNull(path.getParent()), groupedSource);
}
ImmutableMultimap<Path, GroupedSource> entries = entriesBuilder.build();
ImmutableMultimap.Builder<Path, String> subgroupsBuilder = ImmutableMultimap.builder();
for (Path groupPath : entries.keys()) {
Path parent = groupPath.getParent();
while (parent != null) {
subgroupsBuilder.put(parent, groupPath.getFileName().toString());
groupPath = parent;
parent = groupPath.getParent();
}
}
ImmutableMultimap<Path, String> subgroups = subgroupsBuilder.build();
GroupedSourceNameComparator groupedSourceNameComparator = new GroupedSourceNameComparator(resolver);
ImmutableList<GroupedSource> groupedSources = createGroupsFromEntryMaps(subgroups, entries, groupedSourceNameComparator, rootPath, rootPath);
// Remove the longest common prefix from all paths.
while (groupedSources.size() == 1 && groupedSources.get(0).getType() == GroupedSource.Type.SOURCE_GROUP) {
groupedSources = ImmutableList.copyOf(groupedSources.get(0).getSourceGroup().get());
}
return groupedSources;
}
use of com.google.common.collect.ImmutableMultimap in project error-prone by google.
the class WakelockReleasedDangerously method wakelockMayThrow.
/**
* Whether the given WakeLock may throw an unexpected RuntimeException when released.
*
* <p>Returns true if: 1) the given WakeLock was acquired with timeout, and 2) the given WakeLock
* is reference counted.
*/
private boolean wakelockMayThrow(Symbol wakelockSymbol, VisitorState state) {
ClassTree enclosingClass = getTopLevelClass(state);
ImmutableMultimap<String, MethodInvocationTree> map = methodCallsForSymbol(wakelockSymbol, enclosingClass);
// Was acquired with timeout.
return map.get("acquire").stream().anyMatch(m -> m.getArguments().size() == 1) && // Is reference counted, i.e., referenceCounted not explicitly set to false.
map.get("setReferenceCounted").stream().noneMatch(m -> Boolean.FALSE.equals(constValue(m.getArguments().get(0), Boolean.class)));
}
use of com.google.common.collect.ImmutableMultimap in project presto by prestodb.
the class SourcePartitionedScheduler method assignSplits.
private Set<RemoteTask> assignSplits(Multimap<InternalNode, Split> splitAssignment, Multimap<InternalNode, Lifespan> noMoreSplitsNotification) {
ImmutableSet.Builder<RemoteTask> newTasks = ImmutableSet.builder();
ImmutableSet<InternalNode> nodes = ImmutableSet.<InternalNode>builder().addAll(splitAssignment.keySet()).addAll(noMoreSplitsNotification.keySet()).build();
for (InternalNode node : nodes) {
ImmutableMultimap<PlanNodeId, Split> splits = ImmutableMultimap.<PlanNodeId, Split>builder().putAll(partitionedNode, splitAssignment.get(node)).build();
ImmutableMultimap.Builder<PlanNodeId, Lifespan> noMoreSplits = ImmutableMultimap.builder();
if (noMoreSplitsNotification.containsKey(node)) {
noMoreSplits.putAll(partitionedNode, noMoreSplitsNotification.get(node));
}
newTasks.addAll(stage.scheduleSplits(node, splits, noMoreSplits.build()));
}
return newTasks.build();
}
Aggregations