Search in sources :

Example 21 with ImmutableSortedMap

use of com.google.common.collect.ImmutableSortedMap in project buck by facebook.

the class LuaBinaryDescription method addVersionLessLibraries.

/**
   * @return the native library map with additional entries for library names with the version
   *     suffix stripped (e.g. libfoo.so.1.0 -> libfoo.so) to appease LuaJIT, which wants to load
   *     libraries using the build-time name.
   */
private ImmutableSortedMap<String, SourcePath> addVersionLessLibraries(CxxPlatform cxxPlatform, ImmutableSortedMap<String, SourcePath> libraries) {
    Pattern versionedExtension = Pattern.compile(Joiner.on("[.\\d]*").join(Iterables.transform(Splitter.on("%s").split(cxxPlatform.getSharedLibraryVersionedExtensionFormat()), input -> input.isEmpty() ? input : Pattern.quote(input))));
    Map<String, SourcePath> librariesPaths = new HashMap<>();
    for (Map.Entry<String, SourcePath> ent : libraries.entrySet()) {
        String name = ent.getKey();
        if (librariesPaths.containsKey(name) && librariesPaths.get(name) != ent.getValue()) {
            throw new HumanReadableException("Library %s has multiple possible paths: %s and %s", name, ent.getValue(), librariesPaths.get(name));
        }
        librariesPaths.put(name, ent.getValue());
        Matcher matcher = versionedExtension.matcher(name);
        String versionLessName = matcher.replaceAll(cxxPlatform.getSharedLibraryExtension());
        if (!versionLessName.equals(ent.getKey()) && !libraries.containsKey(versionLessName)) {
            librariesPaths.put(versionLessName, ent.getValue());
        }
    }
    return ImmutableSortedMap.copyOf(librariesPaths);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Pattern(java.util.regex.Pattern) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Matcher(java.util.regex.Matcher) HumanReadableException(com.facebook.buck.util.HumanReadableException) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap)

Example 22 with ImmutableSortedMap

use of com.google.common.collect.ImmutableSortedMap in project buck by facebook.

the class ProjectGenerator method setTargetBuildConfigurations.

/**
   * Create target level configuration entries.
   *
   * @param target      Xcode target for which the configurations will be set.
   * @param targetGroup Xcode group in which the configuration file references will be placed.
   * @param configurations  Configurations as extracted from the BUCK file.
   * @param overrideBuildSettings Build settings that will override ones defined elsewhere.
   * @param defaultBuildSettings  Target-inline level build settings that will be set if not already
   *                              defined.
   * @param appendBuildSettings   Target-inline level build settings that will incorporate the
   *                              existing value or values at a higher level.
   */
private void setTargetBuildConfigurations(Function<String, Path> configurationNameToXcconfigPath, PBXTarget target, PBXGroup targetGroup, ImmutableMap<String, ImmutableMap<String, String>> configurations, ImmutableMap<String, String> overrideBuildSettings, ImmutableMap<String, String> defaultBuildSettings, ImmutableMap<String, String> appendBuildSettings) throws IOException {
    if (shouldGenerateHeaderSymlinkTreesOnly()) {
        return;
    }
    for (Map.Entry<String, ImmutableMap<String, String>> configurationEntry : configurations.entrySet()) {
        targetConfigNamesBuilder.add(configurationEntry.getKey());
        ImmutableMap<String, String> targetLevelInlineSettings = configurationEntry.getValue();
        XCBuildConfiguration outputConfiguration = target.getBuildConfigurationList().getBuildConfigurationsByName().getUnchecked(configurationEntry.getKey());
        HashMap<String, String> combinedOverrideConfigs = Maps.newHashMap(overrideBuildSettings);
        for (Map.Entry<String, String> entry : defaultBuildSettings.entrySet()) {
            String existingSetting = targetLevelInlineSettings.get(entry.getKey());
            if (existingSetting == null) {
                combinedOverrideConfigs.put(entry.getKey(), entry.getValue());
            }
        }
        for (Map.Entry<String, String> entry : appendBuildSettings.entrySet()) {
            String existingSetting = targetLevelInlineSettings.get(entry.getKey());
            String settingPrefix = existingSetting != null ? existingSetting : "$(inherited)";
            combinedOverrideConfigs.put(entry.getKey(), settingPrefix + " " + entry.getValue());
        }
        ImmutableSortedMap<String, String> mergedSettings = MoreMaps.mergeSorted(targetLevelInlineSettings, combinedOverrideConfigs);
        Path xcconfigPath = configurationNameToXcconfigPath.apply(configurationEntry.getKey());
        projectFilesystem.mkdirs(Preconditions.checkNotNull(xcconfigPath).getParent());
        StringBuilder stringBuilder = new StringBuilder();
        for (Map.Entry<String, String> entry : mergedSettings.entrySet()) {
            stringBuilder.append(entry.getKey());
            stringBuilder.append(" = ");
            stringBuilder.append(entry.getValue());
            stringBuilder.append('\n');
        }
        String xcconfigContents = stringBuilder.toString();
        if (MoreProjectFilesystems.fileContentsDiffer(new ByteArrayInputStream(xcconfigContents.getBytes(Charsets.UTF_8)), xcconfigPath, projectFilesystem)) {
            if (shouldGenerateReadOnlyFiles()) {
                projectFilesystem.writeContentsToPath(xcconfigContents, xcconfigPath, READ_ONLY_FILE_ATTRIBUTE);
            } else {
                projectFilesystem.writeContentsToPath(xcconfigContents, xcconfigPath);
            }
        }
        PBXFileReference fileReference = getConfigurationFileReference(targetGroup, xcconfigPath);
        outputConfiguration.setBaseConfigurationReference(fileReference);
    }
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) XCBuildConfiguration(com.facebook.buck.apple.xcode.xcodeproj.XCBuildConfiguration) NSString(com.dd.plist.NSString) ImmutableMap(com.google.common.collect.ImmutableMap) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) HeaderMap(com.facebook.buck.apple.clang.HeaderMap) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)

Example 23 with ImmutableSortedMap

use of com.google.common.collect.ImmutableSortedMap in project buck by facebook.

the class ProjectGenerator method createHeaderSymlinkTree.

private void createHeaderSymlinkTree(Map<Path, SourcePath> contents, Path headerSymlinkTreeRoot, boolean shouldCreateHeadersSymlinks, boolean shouldCreateHeaderMap) throws IOException {
    if (!shouldCreateHeaderMap && !shouldCreateHeadersSymlinks) {
        return;
    }
    LOG.verbose("Building header symlink tree at %s with contents %s", headerSymlinkTreeRoot, contents);
    ImmutableSortedMap.Builder<Path, Path> resolvedContentsBuilder = ImmutableSortedMap.naturalOrder();
    for (Map.Entry<Path, SourcePath> entry : contents.entrySet()) {
        Path link = headerSymlinkTreeRoot.resolve(entry.getKey());
        Path existing = projectFilesystem.resolve(resolveSourcePath(entry.getValue()));
        resolvedContentsBuilder.put(link, existing);
    }
    ImmutableSortedMap<Path, Path> resolvedContents = resolvedContentsBuilder.build();
    Path headerMapLocation = getHeaderMapLocationFromSymlinkTreeRoot(headerSymlinkTreeRoot);
    Path hashCodeFilePath = headerSymlinkTreeRoot.resolve(".contents-hash");
    Optional<String> currentHashCode = projectFilesystem.readFileIfItExists(hashCodeFilePath);
    String newHashCode = getHeaderSymlinkTreeHashCode(resolvedContents, shouldCreateHeadersSymlinks, shouldCreateHeaderMap).toString();
    if (Optional.of(newHashCode).equals(currentHashCode)) {
        LOG.debug("Symlink tree at %s is up to date, not regenerating (key %s).", headerSymlinkTreeRoot, newHashCode);
    } else {
        LOG.debug("Updating symlink tree at %s (old key %s, new key %s).", headerSymlinkTreeRoot, currentHashCode, newHashCode);
        projectFilesystem.deleteRecursivelyIfExists(headerSymlinkTreeRoot);
        projectFilesystem.mkdirs(headerSymlinkTreeRoot);
        if (shouldCreateHeadersSymlinks) {
            for (Map.Entry<Path, Path> entry : resolvedContents.entrySet()) {
                Path link = entry.getKey();
                Path existing = entry.getValue();
                projectFilesystem.createParentDirs(link);
                projectFilesystem.createSymLink(link, existing, /* force */
                false);
            }
        }
        projectFilesystem.writeContentsToPath(newHashCode, hashCodeFilePath);
        if (shouldCreateHeaderMap) {
            HeaderMap.Builder headerMapBuilder = new HeaderMap.Builder();
            for (Map.Entry<Path, SourcePath> entry : contents.entrySet()) {
                if (shouldCreateHeadersSymlinks) {
                    headerMapBuilder.add(entry.getKey().toString(), Paths.get("../../").resolve(projectCell.getRoot().getFileName()).resolve(headerSymlinkTreeRoot).resolve(entry.getKey()));
                } else {
                    headerMapBuilder.add(entry.getKey().toString(), projectFilesystem.resolve(resolveSourcePath(entry.getValue())));
                }
            }
            projectFilesystem.writeBytesToPath(headerMapBuilder.build().getBytes(), headerMapLocation);
        }
    }
    headerSymlinkTrees.add(headerSymlinkTreeRoot);
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) CacheBuilder(com.google.common.cache.CacheBuilder) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) NSString(com.dd.plist.NSString) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) HeaderMap(com.facebook.buck.apple.clang.HeaderMap) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) HeaderMap(com.facebook.buck.apple.clang.HeaderMap)

Example 24 with ImmutableSortedMap

use of com.google.common.collect.ImmutableSortedMap in project GeoGig by boundlessgeo.

the class FormatCommonV2 method writeTree.

public static void writeTree(RevTree tree, DataOutput data) throws IOException {
    writeUnsignedVarLong(tree.size(), data);
    writeUnsignedVarInt(tree.numTrees(), data);
    Envelope envBuff = new Envelope();
    final int nFeatures = tree.features().isPresent() ? tree.features().get().size() : 0;
    writeUnsignedVarInt(nFeatures, data);
    if (nFeatures > 0) {
        for (Node feature : tree.features().get()) {
            writeNode(feature, data, envBuff);
        }
    }
    final int nTrees = tree.trees().isPresent() ? tree.trees().get().size() : 0;
    writeUnsignedVarInt(nTrees, data);
    if (nTrees > 0) {
        for (Node subTree : tree.trees().get()) {
            writeNode(subTree, data, envBuff);
        }
    }
    final int nBuckets = tree.buckets().isPresent() ? tree.buckets().get().size() : 0;
    writeUnsignedVarInt(nBuckets, data);
    if (tree.buckets().isPresent()) {
        ImmutableSortedMap<Integer, Bucket> buckets = tree.buckets().get();
        for (Map.Entry<Integer, Bucket> bucket : buckets.entrySet()) {
            writeBucket(bucket.getKey(), bucket.getValue(), data, envBuff);
        }
    }
}
Also used : Bucket(org.locationtech.geogig.api.Bucket) Node(org.locationtech.geogig.api.Node) Envelope(com.vividsolutions.jts.geom.Envelope) Map(java.util.Map) SortedMap(java.util.SortedMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) TreeMap(java.util.TreeMap)

Aggregations

ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)24 Map (java.util.Map)13 SourcePath (com.facebook.buck.rules.SourcePath)11 ImmutableMap (com.google.common.collect.ImmutableMap)11 Path (java.nio.file.Path)10 PathSourcePath (com.facebook.buck.rules.PathSourcePath)8 BuildTarget (com.facebook.buck.model.BuildTarget)7 HumanReadableException (com.facebook.buck.util.HumanReadableException)7 HashMap (java.util.HashMap)7 BuildTargetSourcePath (com.facebook.buck.rules.BuildTargetSourcePath)6 NSString (com.dd.plist.NSString)5 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)5 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 BuildRule (com.facebook.buck.rules.BuildRule)4 TargetNode (com.facebook.buck.rules.TargetNode)4 ImmutableList (com.google.common.collect.ImmutableList)4 HeaderMap (com.facebook.buck.apple.clang.HeaderMap)3 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)3 ImmutableSet (com.google.common.collect.ImmutableSet)3