aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc_tools
diff options
context:
space:
mode:
authorGravatar Dave MacLachlan <dmaclach@google.com>2016-02-29 00:29:58 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2016-02-29 17:39:50 +0000
commitdb7a8163e47bd66cd0817981dde3ab215aa51b7b (patch)
treead6187dfbadcff0498db79385c15f3aedc398006 /src/objc_tools
parent9701a2817a7c81103c8d69ff7b753d1ceb17347c (diff)
Simplify plmerge and bundlemerge by removing deprecated functionality.
RELNOTES: -- MOS_MIGRATED_REVID=115804885
Diffstat (limited to 'src/objc_tools')
-rw-r--r--src/objc_tools/bundlemerge/java/com/google/devtools/build/xcode/bundlemerge/BundleMerging.java68
-rw-r--r--src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlistMerging.java72
2 files changed, 9 insertions, 131 deletions
diff --git a/src/objc_tools/bundlemerge/java/com/google/devtools/build/xcode/bundlemerge/BundleMerging.java b/src/objc_tools/bundlemerge/java/com/google/devtools/build/xcode/bundlemerge/BundleMerging.java
index c9714b637b..c4ac90dab9 100644
--- a/src/objc_tools/bundlemerge/java/com/google/devtools/build/xcode/bundlemerge/BundleMerging.java
+++ b/src/objc_tools/bundlemerge/java/com/google/devtools/build/xcode/bundlemerge/BundleMerging.java
@@ -20,14 +20,10 @@ import static com.google.devtools.build.singlejar.ZipCombiner.OutputMode.FORCE_D
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.singlejar.ZipCombiner;
import com.google.devtools.build.xcode.bundlemerge.proto.BundleMergeProtos.BundleFile;
import com.google.devtools.build.xcode.bundlemerge.proto.BundleMergeProtos.Control;
import com.google.devtools.build.xcode.bundlemerge.proto.BundleMergeProtos.MergeZip;
-import com.google.devtools.build.xcode.bundlemerge.proto.BundleMergeProtos.VariableSubstitution;
-import com.google.devtools.build.xcode.common.Platform;
-import com.google.devtools.build.xcode.plmerge.KeysToRemoveIfEmptyString;
import com.google.devtools.build.xcode.plmerge.PlistMerging;
import com.google.devtools.build.xcode.zip.ZipFiles;
import com.google.devtools.build.xcode.zip.ZipInputEntry;
@@ -87,25 +83,6 @@ public final class BundleMerging {
private static final String INFOPLIST_FILENAME = "Info.plist";
private static final String PKGINFO_FILENAME = "PkgInfo";
- @VisibleForTesting
- static final String BOTH_ARGS_ERR =
- "Only one of source_plist_file and bundle_info_plist_file may be specified";
-
- /**
- * A hack needed briefly to maintain backwards compatibility during rename of {@link Platform}
- * enums. Except for backwards-compatible names, falls back to usage of {@link Platform#valueOf}.
- */
- // TODO(bazel-team): Remove this hack.
- private static Platform platformFromName(String platformName) {
- if ("SIMULATOR".equals(platformName)) {
- return Platform.IOS_SIMULATOR;
- } else if ("DEVICE".equals(platformName)) {
- return Platform.IOS_DEVICE;
- } else {
- return Platform.valueOf(platformName);
- }
- }
-
/**
* Adds merge artifacts from the given {@code control} into builders that collect merge zips and
* individual files. {@code bundleRoot} is prepended to each path, except the paths in the merge
@@ -118,50 +95,14 @@ public final class BundleMerging {
Path tempMergedPlist = Files.createTempFile(tempDir, null, INFOPLIST_FILENAME);
Path tempPkgInfo = Files.createTempFile(tempDir, null, PKGINFO_FILENAME);
-
- if (control.hasBundleInfoPlistFile() && !control.getSourcePlistFileList().isEmpty()) {
- throw new IllegalArgumentException(BOTH_ARGS_ERR);
- }
if (control.hasBundleInfoPlistFile()) {
Path bundleInfoPlist = fileSystem.getPath(control.getBundleInfoPlistFile());
-
new PlistMerging(PlistMerging.readPlistFile(bundleInfoPlist))
.setBundleIdentifier(
control.hasPrimaryBundleIdentifier() ? control.getPrimaryBundleIdentifier() : null,
control.hasFallbackBundleIdentifier() ? control.getFallbackBundleIdentifier() : null)
- .write(tempMergedPlist, tempPkgInfo);
- } else {
- // TODO (cpeyser): Remove this branch once blaze uses bundle_info_plist_file
-
- // Generate the Info.plist and PkgInfo files to include in the app bundle.
- ImmutableList.Builder<Path> sourcePlistFilesBuilder = new ImmutableList.Builder<>();
- for (String sourcePlist : control.getSourcePlistFileList()) {
- sourcePlistFilesBuilder.add(fileSystem.getPath(sourcePlist));
- }
- ImmutableList<Path> sourcePlistFiles = sourcePlistFilesBuilder.build();
- ImmutableMap.Builder<String, String> substitutionMap = ImmutableMap.builder();
- for (VariableSubstitution substitution : control.getVariableSubstitutionList()) {
- substitutionMap.put(substitution.getName(), substitution.getValue());
- }
- PlistMerging plistMerging =
- PlistMerging.from(
- sourcePlistFiles,
- PlistMerging.automaticEntries(
- control.getTargetDeviceFamilyList(),
- platformFromName(control.getPlatform()),
- control.getSdkVersion(),
- control.getMinimumOsVersion()),
- substitutionMap.build(),
- new KeysToRemoveIfEmptyString("CFBundleIconFile", "NSPrincipalClass"),
- /*executableName*/ null);
- if (control.hasExecutableName()) {
- plistMerging.setExecutableName(control.getExecutableName());
- }
-
- plistMerging.setBundleIdentifier(
- control.hasPrimaryBundleIdentifier() ? control.getPrimaryBundleIdentifier() : null,
- control.hasFallbackBundleIdentifier() ? control.getFallbackBundleIdentifier() : null)
- .write(tempMergedPlist, tempPkgInfo);
+ .writePlist(tempMergedPlist)
+ .writePkgInfo(tempPkgInfo);
}
bundleRoot = joinPath(bundleRoot, control.getBundleRoot());
@@ -183,11 +124,6 @@ public final class BundleMerging {
externalFileAttribute));
}
- for (String mergeZip : control.getMergeWithoutNamePrefixZipList()) {
- mergeZipsBuilder.add(MergeZip.newBuilder()
- .setSourcePath(mergeZip)
- .build());
- }
mergeZipsBuilder.addAll(control.getMergeZipList());
for (Control nestedControl : control.getNestedBundleList()) {
diff --git a/src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlistMerging.java b/src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlistMerging.java
index d4be46aa42..0463039fac 100644
--- a/src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlistMerging.java
+++ b/src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlistMerging.java
@@ -18,23 +18,16 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Ordering;
import com.google.common.collect.Sets;
import com.google.common.io.ByteSource;
-import com.google.devtools.build.xcode.common.Platform;
import com.google.devtools.build.xcode.plmerge.proto.PlMergeProtos.Control;
import com.google.devtools.build.xcode.util.Equaling;
import com.google.devtools.build.xcode.util.Mapping;
import com.google.devtools.build.xcode.util.Value;
import com.dd.plist.BinaryPropertyListWriter;
-import com.dd.plist.NSArray;
import com.dd.plist.NSDictionary;
import com.dd.plist.NSObject;
import com.dd.plist.NSString;
@@ -54,7 +47,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.text.ParseException;
import java.util.Arrays;
-import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -72,8 +64,6 @@ public class PlistMerging extends Value<PlistMerging> {
private static final String BUNDLE_VERSION_DEFAULT = "1.0.0";
private static final String BUNDLE_SHORT_VERSION_STRING_PLIST_KEY = "CFBundleShortVersionString";
private static final String BUNDLE_SHORT_VERSION_STRING_DEFAULT = "1.0";
- private static final ImmutableBiMap<String, Integer> DEVICE_FAMILIES =
- ImmutableBiMap.of("IPHONE", 1, "IPAD", 2);
/**
* Exception type thrown when validation of the plist file fails.
@@ -135,10 +125,11 @@ public class PlistMerging extends Value<PlistMerging> {
* Writes the results of a merge operation to a plist file.
* @param plistPath the path of the plist to write in binary format
*/
- public void writePlist(Path plistPath) throws IOException {
+ public PlistMerging writePlist(Path plistPath) throws IOException {
try (OutputStream out = Files.newOutputStream(plistPath)) {
BinaryPropertyListWriter.write(out, merged);
}
+ return this;
}
/**
@@ -146,42 +137,16 @@ public class PlistMerging extends Value<PlistMerging> {
* @param pkgInfoPath the path of the PkgInfo file to write. In many iOS apps, this file just
* contains the raw string {@code APPL????}.
*/
- public void writePkgInfo(Path pkgInfoPath) throws IOException {
+ public PlistMerging writePkgInfo(Path pkgInfoPath) throws IOException {
String pkgInfo =
Mapping.of(merged, "CFBundlePackageType").or(NSObject.wrap("APPL")).toString()
+ Mapping.of(merged, "CFBundleSignature").or(NSObject.wrap("????")).toString();
Files.write(pkgInfoPath, pkgInfo.getBytes(StandardCharsets.UTF_8));
- }
-
- /** Invokes {@link #writePlist(Path)} and {@link #writePkgInfo(Path)}. */
- public void write(Path plistPath, Path pkgInfoPath) throws IOException {
- writePlist(plistPath);
- writePkgInfo(pkgInfoPath);
- }
-
- /**
- * Returns a map containing entries that should be added to the merged plist. These are usually
- * generated by Xcode automatically during the build process.
- */
- public static Map<String, NSObject> automaticEntries(
- Collection<String> targetedDeviceFamily, Platform platform, String sdkVersion,
- String minimumOsVersion) {
- ImmutableMap.Builder<String, NSObject> result = new ImmutableMap.Builder<>();
- List<Integer> uiDeviceFamily = FluentIterable.from(targetedDeviceFamily)
- .transform(Maps.asConverter(DEVICE_FAMILIES))
- .toSortedList(Ordering.natural());
-
- result.put("UIDeviceFamily", NSObject.wrap(uiDeviceFamily.toArray()));
- result.put("DTPlatformName", NSObject.wrap(platform.getLowerCaseNameInPlist()));
- result.put("DTSDKName", NSObject.wrap(platform.getLowerCaseNameInPlist() + sdkVersion));
- result.put("CFBundleSupportedPlatforms", new NSArray(NSObject.wrap(platform.getNameInPlist())));
- result.put("MinimumOSVersion", NSObject.wrap(minimumOsVersion));
-
- return result.build();
+ return this;
}
/**
- * Generates a Plistmerging combining values from sourceFiles and immutableSourceFiles, and
+ * Generates a Plistmerging combining values from sourceFiles and immutableSourceFiles, and
* modifying them based on substitutions and keysToRemoveIfEmptyString.
*/
public static PlistMerging from(
@@ -190,7 +155,7 @@ public class PlistMerging extends Value<PlistMerging> {
throws IOException {
FileSystem fileSystem = FileSystems.getDefault();
-
+
ImmutableList.Builder<Path> sourceFilePathsBuilder = new Builder<>();
for (String pathString : control.getSourceFileList()) {
sourceFilePathsBuilder.add(fileSystem.getPath(pathString));
@@ -219,31 +184,8 @@ public class PlistMerging extends Value<PlistMerging> {
KeysToRemoveIfEmptyString keysToRemoveIfEmptyString,
String executableName)
throws IOException {
- return from(
- sourceFiles,
- PlistMerging.merge(immutableSourceFiles),
- substitutions,
- keysToRemoveIfEmptyString,
- executableName);
- }
-
- /**
- * Generates a Plistmerging combining values from sourceFiles and immutableEntries, and modifying
- * them based on subsitutions and keysToRemoveIfEmptyString.
- *
- * This version of from() is required until bundlemerge no longer uses this method.
- * TODO (cpeyser): Remove this version to require from() accepts a list of immutable source file
- * paths instead of an already-merged map of entries.
- */
- public static PlistMerging from(
- List<Path> sourceFiles,
- Map<String, NSObject> immutableEntries,
- Map<String, String> substitutions,
- KeysToRemoveIfEmptyString keysToRemoveIfEmptyString,
- String executableName)
- throws IOException {
NSDictionary merged = PlistMerging.merge(sourceFiles);
-
+ NSDictionary immutableEntries = PlistMerging.merge(immutableSourceFiles);
Set<String> conflictingEntries = Sets.intersection(immutableEntries.keySet(), merged.keySet());
Preconditions.checkArgument(