diff options
author | Dave MacLachlan <dmaclach@google.com> | 2016-02-29 00:29:58 +0000 |
---|---|---|
committer | Kristina Chodorow <kchodorow@google.com> | 2016-02-29 17:39:50 +0000 |
commit | db7a8163e47bd66cd0817981dde3ab215aa51b7b (patch) | |
tree | ad6187dfbadcff0498db79385c15f3aedc398006 /src | |
parent | 9701a2817a7c81103c8d69ff7b753d1ceb17347c (diff) |
Simplify plmerge and bundlemerge by removing deprecated functionality.
RELNOTES:
--
MOS_MIGRATED_REVID=115804885
Diffstat (limited to 'src')
5 files changed, 15 insertions, 180 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/BundleMergeControlBytes.java b/src/main/java/com/google/devtools/build/lib/rules/objc/BundleMergeControlBytes.java index 40a0b84479..70925770e5 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/BundleMergeControlBytes.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/BundleMergeControlBytes.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.rules.objc; -import com.google.common.collect.ImmutableSet; import com.google.common.io.ByteSource; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; @@ -36,22 +35,17 @@ final class BundleMergeControlBytes extends ByteSource { private final Bundling rootBundling; private final Artifact mergedIpa; private final AppleConfiguration appleConfiguration; - private final ImmutableSet<TargetDeviceFamily> families; public BundleMergeControlBytes( - Bundling rootBundling, Artifact mergedIpa, AppleConfiguration appleConfiguration, - ImmutableSet<TargetDeviceFamily> families) { + Bundling rootBundling, Artifact mergedIpa, AppleConfiguration appleConfiguration) { this.rootBundling = Preconditions.checkNotNull(rootBundling); this.mergedIpa = Preconditions.checkNotNull(mergedIpa); this.appleConfiguration = Preconditions.checkNotNull(appleConfiguration); - this.families = Preconditions.checkNotNull(families); } @Override public InputStream openStream() { - return control("", rootBundling) - .toByteString() - .newInput(); + return control("", rootBundling).toByteString().newInput(); } private Control control(String mergeZipPrefix, Bundling bundling) { @@ -77,10 +71,6 @@ final class BundleMergeControlBytes extends ByteSource { .build()); } - for (TargetDeviceFamily targetDeviceFamily : families) { - control.addTargetDeviceFamily(targetDeviceFamily.name()); - } - control.setOutFile(mergedIpa.getExecPathString()); for (Artifact linkedBinary : bundling.getCombinedArchitectureBinary().asSet()) { diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java index 9e15d8986d..9c4d7223f6 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java @@ -761,8 +761,7 @@ public final class ReleaseBundlingSupport { new BundleMergeControlBytes( bundling, intermediateArtifacts.unprocessedIpa(), - ruleContext.getFragment(AppleConfiguration.class), - bundleSupport.targetDeviceFamilies()); + ruleContext.getFragment(AppleConfiguration.class)); ruleContext.registerAction( new BinaryFileWriteAction( diff --git a/src/main/protobuf/bundlemerge.proto b/src/main/protobuf/bundlemerge.proto index 41a338a093..5392d778bd 100644 --- a/src/main/protobuf/bundlemerge.proto +++ b/src/main/protobuf/bundlemerge.proto @@ -22,27 +22,17 @@ option java_package = "com.google.devtools.build.xcode.bundlemerge.proto"; // bundle. // Next Id: 17 message Control { - // Paths to the plist files to merge into the final Plist.info file. These - // can be binary, XML, or ASCII format. - // This field is deprecated, but is supported for backwards compatibility. - // If bundle_info_plist_file is not supplied, this key will be used instead. - repeated string source_plist_file = 1; + // Previously used fields. + reserved 1, 3, 9, 11, 13; // The single info.plist file to be bundled into the archive. This plist will // not be modified by bundlemerge. - // This field replaces source_plist_file. optional string bundle_info_plist_file = 16; // Path to the .ipa file to write. This is the final application bundle. Note // this is ignored for nested bundles. optional string out_file = 2; - // Which devices the app targets, which corresponds to the UIDeviceFamily - // setting. Should be one or more of the symbols in the - // com.google.devtools.build.xcode.common.TargetDeviceFamily enum (e.g. - // "IPAD", "IPHONE"). - repeated string target_device_family = 3; - // One of the symbols in the com.google.devtools.build.xcode.common.Platform // (e.g. "DEVICE", "SIMULATOR"). optional string platform = 4; @@ -63,8 +53,6 @@ message Control { // as Info.plist and PkgInfo. This should include the application binary. repeated BundleFile bundle_file = 8; - repeated string merge_without_name_prefix_zip = 9 [deprecated=true]; - // Zip files to merge with the final zip. Note that bundle_root is ignored // when merging zips, so to place items in the bundle root, you should do one // of the following: @@ -75,22 +63,10 @@ message Control { // - they are not relative to the containing bundle. repeated MergeZip merge_zip = 10; - // Variable substitutions to perform on property values in the merged - // .plist file. - // This field is deprecated, and will not be used if a bundle_info_plist_file - // is specified. For backwards compatibility, if a bundle_info_plist_file - // is not specified, source_plist_file will be used instead and variable - // substitutions will be applied. - repeated VariableSubstitution variable_substitution = 11; - // Bundles that are nested within this one. bundle_root in these bundles is // relative to the containing bundle's bundle_root. repeated Control nested_bundle = 12; - // Name of the executable for this bundle or unset if no such executable - // exists. - optional string executable_name = 13; - // A reverse-DNS string identifier for this bundle. optional string primary_bundle_identifier = 14; @@ -102,7 +78,7 @@ message Control { message MergeZip { // The prefix to prepend to every entry name before putting it in the final // zip. For instance, "Payload/Foo.app/" (notice the final slash). - optional string entry_name_prefix = 1 [default = ""]; + optional string entry_name_prefix = 1; // The path to the source file to merge. optional string source_path = 2; @@ -120,11 +96,3 @@ message BundleFile { // constant is used. optional int32 external_file_attribute = 3; } - -message VariableSubstitution { - // The name of the varaible to substitute. - required string name = 1; - - // The substitution value. - required string value = 2; -} 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( |