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);
}
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);
}
}
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);
}
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);
}
}
}
Aggregations