List of usage examples for com.google.common.collect ImmutableMap values
public ImmutableCollection<V> values()
From source file:com.facebook.buck.cxx.toolchain.nativelink.NativeLinkables.java
/** * Collect up and merge all {@link NativeLinkableInput} objects from transitively traversing all * unbroken dependency chains of {@link NativeLinkable} objects found via the passed in {@link * BuildRule} roots.//from w w w. j a va 2 s . c om */ public static <T> NativeLinkableInput getTransitiveNativeLinkableInput(CxxPlatform cxxPlatform, ActionGraphBuilder graphBuilder, Iterable<? extends T> inputs, Linker.LinkableDepType depType, Function<? super T, Optional<Iterable<? extends T>>> passthrough) { // Get the topologically sorted native linkables. ImmutableMap<BuildTarget, NativeLinkable> roots = getNativeLinkableRoots(inputs, passthrough); ImmutableList<NativeLinkable> nativeLinkables = getNativeLinkables(cxxPlatform, graphBuilder, roots.values(), depType); ImmutableList.Builder<NativeLinkableInput> nativeLinkableInputs = ImmutableList.builder(); for (NativeLinkable nativeLinkable : nativeLinkables) { nativeLinkableInputs.add(getNativeLinkableInput(cxxPlatform, depType, nativeLinkable, graphBuilder)); } return NativeLinkableInput.concat(nativeLinkableInputs.build()); }
From source file:com.facebook.buck.cxx.NativeLinkables.java
/** * Collect all the shared libraries generated by {@link NativeLinkable}s found by transitively * traversing all unbroken dependency chains of {@link com.facebook.buck.cxx.NativeLinkable} * objects found via the passed in {@link com.facebook.buck.rules.BuildRule} roots. * * @return a mapping of library name to the library {@link SourcePath}. *//* w w w.jav a 2s . c o m*/ public static ImmutableSortedMap<String, SourcePath> getTransitiveSharedLibraries(CxxPlatform cxxPlatform, Iterable<? extends BuildRule> inputs, Predicate<Object> traverse, Predicate<Object> skip) throws NoSuchBuildTargetException { ImmutableMap<BuildTarget, NativeLinkable> roots = getNativeLinkableRoots(inputs, traverse, skip); ImmutableMap<BuildTarget, NativeLinkable> nativeLinkables = getTransitiveNativeLinkables(cxxPlatform, roots.values()); Map<String, SourcePath> libraries = new LinkedHashMap<>(); for (NativeLinkable nativeLinkable : nativeLinkables.values()) { NativeLinkable.Linkage linkage = nativeLinkable.getPreferredLinkage(cxxPlatform); if (linkage != NativeLinkable.Linkage.STATIC) { ImmutableMap<String, SourcePath> libs = nativeLinkable.getSharedLibraries(cxxPlatform); for (Map.Entry<String, SourcePath> lib : libs.entrySet()) { SourcePath prev = libraries.put(lib.getKey(), lib.getValue()); if (prev != null && !prev.equals(lib.getValue())) { throw new HumanReadableException("conflicting libraries for key %s: %s != %s", lib.getKey(), lib.getValue(), prev); } } } } return ImmutableSortedMap.copyOf(libraries); }
From source file:com.google.caliper.runner.CaliperRun.java
private static Collection<BenchmarkMethod> chooseBenchmarkMethods(BenchmarkClass benchmarkClass, Instrument instrument, CaliperOptions options) throws InvalidBenchmarkException { ImmutableMap<String, BenchmarkMethod> methodMap = benchmarkClass.findAllBenchmarkMethods(instrument); ImmutableSet<String> names = options.benchmarkMethodNames(); // TODO(kevinb): this doesn't seem to prevent bogus names on cmd line yet return names.isEmpty() ? methodMap.values() : Maps.filterKeys(methodMap, Predicates.in(names)).values(); }
From source file:com.facebook.buck.cxx.toolchain.nativelink.NativeLinkables.java
/** * Collect all the shared libraries generated by {@link NativeLinkable}s found by transitively * traversing all unbroken dependency chains of {@link NativeLinkable} objects found via the * passed in {@link BuildRule} roots.// w ww .j a v a2 s .c o m * * @param alwaysIncludeRoots whether to include shared libraries from roots, even if they prefer * static linkage. * @return a mapping of library name to the library {@link SourcePath}. */ public static <T> ImmutableSortedMap<String, SourcePath> getTransitiveSharedLibraries(CxxPlatform cxxPlatform, ActionGraphBuilder graphBuilder, Iterable<? extends T> inputs, Function<? super T, Optional<Iterable<? extends T>>> passthrough, boolean alwaysIncludeRoots) { ImmutableMap<BuildTarget, NativeLinkable> roots = getNativeLinkableRoots(inputs, passthrough); ImmutableMap<BuildTarget, NativeLinkable> nativeLinkables = getTransitiveNativeLinkables(cxxPlatform, graphBuilder, roots.values()); SharedLibrariesBuilder builder = new SharedLibrariesBuilder(); nativeLinkables.entrySet().stream().filter( e -> e.getValue().getPreferredLinkage(cxxPlatform, graphBuilder) != NativeLinkable.Linkage.STATIC || (alwaysIncludeRoots && roots.containsKey(e.getKey()))) .forEach(e -> builder.add(cxxPlatform, e.getValue(), graphBuilder)); return builder.build(); }
From source file:com.facebook.buck.io.watchman.WatchmanFactory.java
private static Watchman getWatchman(WatchmanClient client, Path transportPath, ImmutableSet<Path> projectWatchList, Console console, Clock clock, long endTimeNanos) throws IOException, InterruptedException { long versionQueryStartTimeNanos = clock.nanoTime(); Optional<? extends Map<String, ?>> result = client.queryWithTimeout( endTimeNanos - versionQueryStartTimeNanos, "version", ImmutableMap.of("required", REQUIRED_CAPABILITIES, "optional", ALL_CAPABILITIES.keySet())); LOG.info("Took %d ms to query capabilities %s", TimeUnit.NANOSECONDS.toMillis(clock.nanoTime() - versionQueryStartTimeNanos), ALL_CAPABILITIES); if (!result.isPresent()) { LOG.warn("Could not get version response from Watchman, disabling Watchman"); return NULL_WATCHMAN; }/*from w w w .j a v a 2s .co m*/ ImmutableSet.Builder<Capability> capabilitiesBuilder = ImmutableSet.builder(); if (!extractCapabilities(result.get(), capabilitiesBuilder)) { LOG.warn("Could not extract capabilities, disabling Watchman"); return NULL_WATCHMAN; } ImmutableSet<Capability> capabilities = capabilitiesBuilder.build(); LOG.debug("Got Watchman capabilities: %s", capabilities); ImmutableMap.Builder<Path, ProjectWatch> projectWatchesBuilder = ImmutableMap.builder(); for (Path projectRoot : projectWatchList) { Optional<ProjectWatch> projectWatch = queryWatchProject(client, projectRoot, clock, endTimeNanos - clock.nanoTime()); if (!projectWatch.isPresent()) { return NULL_WATCHMAN; } projectWatchesBuilder.put(projectRoot, projectWatch.get()); } ImmutableMap<Path, ProjectWatch> projectWatches = projectWatchesBuilder.build(); Iterable<String> watchRoots = RichStream.from(projectWatches.values()).map(ProjectWatch::getWatchRoot) .distinct().toOnceIterable(); ImmutableMap.Builder<String, String> clockIdsBuilder = ImmutableMap.builder(); for (String watchRoot : watchRoots) { Optional<String> clockId = queryClock(client, watchRoot, capabilities, clock, endTimeNanos - clock.nanoTime()); if (clockId.isPresent()) { clockIdsBuilder.put(watchRoot, clockId.get()); } } return new Watchman(projectWatches, capabilities, clockIdsBuilder.build(), Optional.of(transportPath)) { @Override public WatchmanClient createClient() throws IOException { return createWatchmanClient(transportPath, console, clock); } }; }
From source file:org.chaston.oakfunds.storage.RecordType.java
private static ImmutableMap<String, JdbcTypeHandler> buildTypeHandlers( ImmutableMap<String, AttributeType> attributes, @Nullable RecordType<?> parentType) { ImmutableMap.Builder<String, JdbcTypeHandler> jdbcTypeHandlers = ImmutableMap.builder(); if (parentType != null) { jdbcTypeHandlers.putAll(parentType.jdbcTypeHandlers); }// w w w .j a v a 2 s . c om for (AttributeType attributeType : attributes.values()) { jdbcTypeHandlers.put(attributeType.getName(), createJdbcTypeHandler(attributeType)); } return jdbcTypeHandlers.build(); }
From source file:com.facebook.buck.cxx.SharedLibraryInterfacePlatforms.java
public static Optional<CxxPlatform> getTestPlatform(ProjectFilesystem filesystem, BuckConfig buckConfig, CxxBuckConfig cxxBuckConfig) {//w w w.j a va 2 s . co m Optional<AndroidNdk> androidNdk = AndroidNdkHelper.detectAndroidNdk(filesystem); if (!androidNdk.isPresent()) { return Optional.empty(); } Path ndkDir = androidNdk.get().getNdkRootPath(); String ndkVersion = androidNdk.get().getNdkVersion(); NdkCompilerType compilerType = NdkCxxPlatforms.getDefaultCompilerTypeForNdk(ndkVersion); String gccVersion = NdkCxxPlatforms.getDefaultGccVersionForNdk(ndkVersion); String clangVersion = NdkCxxPlatforms.getDefaultClangVersionForNdk(ndkVersion); String compilerVersion = compilerType == NdkCompilerType.GCC ? gccVersion : clangVersion; NdkCxxPlatformCompiler compiler = NdkCxxPlatformCompiler.builder().setType(compilerType) .setVersion(compilerVersion).setGccVersion(gccVersion).build(); ImmutableMap<TargetCpuType, UnresolvedNdkCxxPlatform> ndkPlatforms = NdkCxxPlatforms.getPlatforms( cxxBuckConfig, new AndroidBuckConfig(buckConfig, Platform.detect()), filesystem, ndkDir, compiler, NdkCxxPlatforms.getDefaultCxxRuntimeForNdk(ndkVersion), NdkCxxRuntimeType.DYNAMIC, AndroidNdkHelper.getDefaultCpuAbis(ndkVersion), Platform.detect()); // Just return one of the NDK platforms, which should be enough to test shared library interface // functionality. return Optional .of(ndkPlatforms.values().iterator().next().getCxxPlatform().resolve(new TestActionGraphBuilder())); }
From source file:com.facebook.buck.python.PythonUtil.java
public static PythonPackageComponents getAllComponents(BuildRuleParams params, BuildRuleResolver ruleResolver, SourcePathResolver pathResolver, SourcePathRuleFinder ruleFinder, final PythonPackageComponents packageComponents, final PythonPlatform pythonPlatform, CxxBuckConfig cxxBuckConfig, final CxxPlatform cxxPlatform, ImmutableList<? extends Arg> extraLdflags, final NativeLinkStrategy nativeLinkStrategy, final ImmutableSet<BuildTarget> preloadDeps) throws NoSuchBuildTargetException { final PythonPackageComponents.Builder allComponents = new PythonPackageComponents.Builder( params.getBuildTarget());/* w ww.j a v a 2 s . c o m*/ final Map<BuildTarget, CxxPythonExtension> extensions = new LinkedHashMap<>(); final Map<BuildTarget, NativeLinkable> nativeLinkableRoots = new LinkedHashMap<>(); final OmnibusRoots.Builder omnibusRoots = OmnibusRoots.builder(cxxPlatform, preloadDeps); // Add the top-level components. allComponents.addComponent(packageComponents, params.getBuildTarget()); // Walk all our transitive deps to build our complete package that we'll // turn into an executable. new AbstractBreadthFirstThrowingTraversal<BuildRule, NoSuchBuildTargetException>(params.getDeps()) { private final ImmutableList<BuildRule> empty = ImmutableList.of(); @Override public Iterable<BuildRule> visit(BuildRule rule) throws NoSuchBuildTargetException { Iterable<BuildRule> deps = empty; if (rule instanceof CxxPythonExtension) { CxxPythonExtension extension = (CxxPythonExtension) rule; NativeLinkTarget target = ((CxxPythonExtension) rule).getNativeLinkTarget(pythonPlatform); extensions.put(target.getBuildTarget(), extension); omnibusRoots.addIncludedRoot(target); List<BuildRule> cxxpydeps = new ArrayList<>(); for (BuildRule dep : rule.getDeps()) { if (dep instanceof CxxPythonExtension) { cxxpydeps.add(dep); } } deps = cxxpydeps; } else if (rule instanceof PythonPackagable) { PythonPackagable packagable = (PythonPackagable) rule; PythonPackageComponents comps = packagable.getPythonPackageComponents(pythonPlatform, cxxPlatform); allComponents.addComponent(comps, rule.getBuildTarget()); if (comps.hasNativeCode(cxxPlatform)) { for (BuildRule dep : rule.getDeps()) { if (dep instanceof NativeLinkable) { NativeLinkable linkable = (NativeLinkable) dep; nativeLinkableRoots.put(linkable.getBuildTarget(), linkable); omnibusRoots.addExcludedRoot(linkable); } } } deps = rule.getDeps(); } else if (rule instanceof NativeLinkable) { NativeLinkable linkable = (NativeLinkable) rule; nativeLinkableRoots.put(linkable.getBuildTarget(), linkable); omnibusRoots.addPotentialRoot(linkable); } return deps; } }.start(); // For the merged strategy, build up the lists of included native linkable roots, and the // excluded native linkable roots. if (nativeLinkStrategy == NativeLinkStrategy.MERGED) { OmnibusRoots roots = omnibusRoots.build(); OmnibusLibraries libraries = Omnibus.getSharedLibraries(params, ruleResolver, pathResolver, ruleFinder, cxxBuckConfig, cxxPlatform, extraLdflags, roots.getIncludedRoots().values(), roots.getExcludedRoots().values()); // Add all the roots from the omnibus link. If it's an extension, add it as a module. // Otherwise, add it as a native library. for (Map.Entry<BuildTarget, OmnibusRoot> root : libraries.getRoots().entrySet()) { CxxPythonExtension extension = extensions.get(root.getKey()); if (extension != null) { allComponents.addModule(extension.getModule(), root.getValue().getPath(), root.getKey()); } else { NativeLinkTarget target = Preconditions.checkNotNull( roots.getIncludedRoots().get(root.getKey()), "%s: linked unexpected omnibus root: %s", params.getBuildTarget(), root.getKey()); NativeLinkTargetMode mode = target.getNativeLinkTargetMode(cxxPlatform); String soname = Preconditions.checkNotNull(mode.getLibraryName().orElse(null), "%s: omnibus library for %s was built without soname", params.getBuildTarget(), root.getKey()); allComponents.addNativeLibraries(Paths.get(soname), root.getValue().getPath(), root.getKey()); } } // Add all remaining libraries as native libraries. for (OmnibusLibrary library : libraries.getLibraries()) { allComponents.addNativeLibraries(Paths.get(library.getSoname()), library.getPath(), params.getBuildTarget()); } } else { // For regular linking, add all extensions via the package components interface. Map<BuildTarget, NativeLinkable> extensionNativeDeps = new LinkedHashMap<>(); for (Map.Entry<BuildTarget, CxxPythonExtension> entry : extensions.entrySet()) { allComponents.addComponent(entry.getValue().getPythonPackageComponents(pythonPlatform, cxxPlatform), entry.getValue().getBuildTarget()); extensionNativeDeps.putAll(Maps.uniqueIndex( entry.getValue().getNativeLinkTarget(pythonPlatform).getNativeLinkTargetDeps(cxxPlatform), HasBuildTarget::getBuildTarget)); } // Add all the native libraries. ImmutableMap<BuildTarget, NativeLinkable> nativeLinkables = NativeLinkables .getTransitiveNativeLinkables(cxxPlatform, Iterables.concat(nativeLinkableRoots.values(), extensionNativeDeps.values())); for (NativeLinkable nativeLinkable : nativeLinkables.values()) { NativeLinkable.Linkage linkage = nativeLinkable.getPreferredLinkage(cxxPlatform); if (nativeLinkableRoots.containsKey(nativeLinkable.getBuildTarget()) || linkage != NativeLinkable.Linkage.STATIC) { ImmutableMap<String, SourcePath> libs = nativeLinkable.getSharedLibraries(cxxPlatform); for (Map.Entry<String, SourcePath> ent : libs.entrySet()) { allComponents.addNativeLibraries(Paths.get(ent.getKey()), ent.getValue(), nativeLinkable.getBuildTarget()); } } } } return allComponents.build(); }
From source file:com.google.polymer.JsRenamer.java
private static void renameKeyBindingsNode(ImmutableMap<String, String> renameMap, Node node) { ImmutableMap<String, Node> keyBindingsMap = convertObjectLitNodeToMap(node); for (Node keyBindingMethodStringNode : keyBindingsMap.values()) { if (!keyBindingMethodStringNode.isString()) { // A non-string means it's a map we don't expect. break; }/*from w w w. j a va2 s . co m*/ renameStringNode(renameMap, keyBindingMethodStringNode); } }
From source file:com.facebook.buck.features.python.PythonUtil.java
static PythonPackageComponents getAllComponents(CellPathResolver cellPathResolver, BuildTarget buildTarget, ProjectFilesystem projectFilesystem, BuildRuleParams params, ActionGraphBuilder graphBuilder, SourcePathRuleFinder ruleFinder, Iterable<BuildRule> deps, PythonPackageComponents packageComponents, PythonPlatform pythonPlatform, CxxBuckConfig cxxBuckConfig, CxxPlatform cxxPlatform, ImmutableList<? extends Arg> extraLdflags, NativeLinkStrategy nativeLinkStrategy, ImmutableSet<BuildTarget> preloadDeps) { PythonPackageComponents.Builder allComponents = new PythonPackageComponents.Builder(buildTarget); Map<BuildTarget, CxxPythonExtension> extensions = new LinkedHashMap<>(); Map<BuildTarget, NativeLinkable> nativeLinkableRoots = new LinkedHashMap<>(); OmnibusRoots.Builder omnibusRoots = OmnibusRoots.builder(cxxPlatform, preloadDeps, graphBuilder); // Add the top-level components. allComponents.addComponent(packageComponents, buildTarget); // Walk all our transitive deps to build our complete package that we'll // turn into an executable. new AbstractBreadthFirstTraversal<BuildRule>( Iterables.concat(deps, graphBuilder.getAllRules(preloadDeps))) { private final ImmutableList<BuildRule> empty = ImmutableList.of(); @Override/* w w w .j ava 2s. c om*/ public Iterable<BuildRule> visit(BuildRule rule) { Iterable<BuildRule> deps = empty; if (rule instanceof CxxPythonExtension) { CxxPythonExtension extension = (CxxPythonExtension) rule; NativeLinkTarget target = ((CxxPythonExtension) rule).getNativeLinkTarget(pythonPlatform); extensions.put(target.getBuildTarget(), extension); omnibusRoots.addIncludedRoot(target); List<BuildRule> cxxpydeps = new ArrayList<>(); for (BuildRule dep : extension.getPythonPackageDeps(pythonPlatform, cxxPlatform, graphBuilder)) { if (dep instanceof PythonPackagable) { cxxpydeps.add(dep); } } deps = cxxpydeps; } else if (rule instanceof PythonPackagable) { PythonPackagable packagable = (PythonPackagable) rule; PythonPackageComponents comps = packagable.getPythonPackageComponents(pythonPlatform, cxxPlatform, graphBuilder); allComponents.addComponent(comps, rule.getBuildTarget()); if (packagable.doesPythonPackageDisallowOmnibus() || comps.hasNativeCode(cxxPlatform)) { for (BuildRule dep : packagable.getPythonPackageDeps(pythonPlatform, cxxPlatform, graphBuilder)) { if (dep instanceof NativeLinkable) { NativeLinkable linkable = (NativeLinkable) dep; nativeLinkableRoots.put(linkable.getBuildTarget(), linkable); omnibusRoots.addExcludedRoot(linkable); } } } deps = packagable.getPythonPackageDeps(pythonPlatform, cxxPlatform, graphBuilder); } else if (rule instanceof NativeLinkable) { NativeLinkable linkable = (NativeLinkable) rule; nativeLinkableRoots.put(linkable.getBuildTarget(), linkable); omnibusRoots.addPotentialRoot(linkable); } return deps; } }.start(); // For the merged strategy, build up the lists of included native linkable roots, and the // excluded native linkable roots. if (nativeLinkStrategy == NativeLinkStrategy.MERGED) { OmnibusRoots roots = omnibusRoots.build(); OmnibusLibraries libraries = Omnibus.getSharedLibraries(buildTarget, projectFilesystem, params, cellPathResolver, graphBuilder, ruleFinder, cxxBuckConfig, cxxPlatform, extraLdflags, roots.getIncludedRoots().values(), roots.getExcludedRoots().values()); // Add all the roots from the omnibus link. If it's an extension, add it as a module. // Otherwise, add it as a native library. for (Map.Entry<BuildTarget, OmnibusRoot> root : libraries.getRoots().entrySet()) { CxxPythonExtension extension = extensions.get(root.getKey()); if (extension != null) { allComponents.addModule(extension.getModule(), root.getValue().getPath(), root.getKey()); } else { NativeLinkTarget target = Preconditions.checkNotNull( roots.getIncludedRoots().get(root.getKey()), "%s: linked unexpected omnibus root: %s", buildTarget, root.getKey()); NativeLinkTargetMode mode = target.getNativeLinkTargetMode(cxxPlatform); String soname = Preconditions.checkNotNull(mode.getLibraryName().orElse(null), "%s: omnibus library for %s was built without soname", buildTarget, root.getKey()); allComponents.addNativeLibraries(Paths.get(soname), root.getValue().getPath(), root.getKey()); } } // Add all remaining libraries as native libraries. for (OmnibusLibrary library : libraries.getLibraries()) { allComponents.addNativeLibraries(Paths.get(library.getSoname()), library.getPath(), buildTarget); } } else { // For regular linking, add all extensions via the package components interface. Map<BuildTarget, NativeLinkable> extensionNativeDeps = new LinkedHashMap<>(); for (Map.Entry<BuildTarget, CxxPythonExtension> entry : extensions.entrySet()) { allComponents.addComponent( entry.getValue().getPythonPackageComponents(pythonPlatform, cxxPlatform, graphBuilder), entry.getValue().getBuildTarget()); extensionNativeDeps.putAll(Maps.uniqueIndex(entry.getValue().getNativeLinkTarget(pythonPlatform) .getNativeLinkTargetDeps(cxxPlatform, graphBuilder), NativeLinkable::getBuildTarget)); } // Add all the native libraries. ImmutableMap<BuildTarget, NativeLinkable> nativeLinkables = NativeLinkables .getTransitiveNativeLinkables(cxxPlatform, graphBuilder, Iterables.concat(nativeLinkableRoots.values(), extensionNativeDeps.values())); for (NativeLinkable nativeLinkable : nativeLinkables.values()) { NativeLinkable.Linkage linkage = nativeLinkable.getPreferredLinkage(cxxPlatform, graphBuilder); if (nativeLinkableRoots.containsKey(nativeLinkable.getBuildTarget()) || linkage != NativeLinkable.Linkage.STATIC) { ImmutableMap<String, SourcePath> libs = nativeLinkable.getSharedLibraries(cxxPlatform, graphBuilder); for (Map.Entry<String, SourcePath> ent : libs.entrySet()) { allComponents.addNativeLibraries(Paths.get(ent.getKey()), ent.getValue(), nativeLinkable.getBuildTarget()); } } } } return allComponents.build(); }