diff options
author | 2015-02-25 00:42:09 +0000 | |
---|---|---|
committer | 2015-02-25 00:42:09 +0000 | |
commit | faa66ade02667a849d532768458d5e1645506081 (patch) | |
tree | 2425135298344ad867affea99a3797c65f00e951 | |
parent | c5102fc5cec4336140889510a87ef1c57810911c (diff) |
Pass bundle_id attribute to PlMerge if it is explicitly set
* Adds primary and fallback bundle ID fields
* Adds conflict resolution that considers IDs in order: plist file, primary ID (set in BUILD file), fallback ID (Blaze default). If plist and primary are both set, they should be equal, otherwise an error is thrown.
--
MOS_MIGRATED_REVID=87106031
5 files changed, 66 insertions, 3 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 224e9bf449..a03acd46ff 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 @@ -42,14 +42,19 @@ final class BundleMergeControlBytes extends ByteSource { private final Artifact mergedIpa; private final ObjcConfiguration objcConfiguration; private final ImmutableSet<TargetDeviceFamily> families; + private final String primaryBundleIdentifier; + private final String fallbackBundleIdentifier; public BundleMergeControlBytes( Bundling rootBundling, Artifact mergedIpa, ObjcConfiguration objcConfiguration, - ImmutableSet<TargetDeviceFamily> families) { + ImmutableSet<TargetDeviceFamily> families, + String primaryBundleIdentifer, String fallbackBundleIdentifier) { this.rootBundling = Preconditions.checkNotNull(rootBundling); this.mergedIpa = Preconditions.checkNotNull(mergedIpa); this.objcConfiguration = Preconditions.checkNotNull(objcConfiguration); this.families = Preconditions.checkNotNull(families); + this.primaryBundleIdentifier = primaryBundleIdentifer; + this.fallbackBundleIdentifier = fallbackBundleIdentifier; } @Override @@ -114,7 +119,15 @@ final class BundleMergeControlBytes extends ByteSource { for (Bundling nestedBundling : bundling.getObjcProvider().get(NESTED_BUNDLE)) { control.addNestedBundle(control(mergeZipPrefix, nestedBundling)); } - + + if (primaryBundleIdentifier != null) { + control.setPrimaryBundleIdentifier(primaryBundleIdentifier); + } + + if (fallbackBundleIdentifier != null) { + control.setFallbackBundleIdentifier(fallbackBundleIdentifier); + } + return control.build(); } } 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 e0dfb9c1af..b4aebb4cb6 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 @@ -184,9 +184,18 @@ public final class ReleaseBundlingSupport { } else { maybeSignedIpa = registerBundleSigningActions(ipaOutput); } + + String primaryBundleId = null; + String fallbackBundleId = null; + if (ruleContext.attributes().isAttributeValueExplicitlySpecified("bundle_id")) { + primaryBundleId = attributes.bundleId(); + } else { + fallbackBundleId = attributes.bundleId(); + } + BundleMergeControlBytes bundleMergeControlBytes = new BundleMergeControlBytes( - bundling, maybeSignedIpa, objcConfiguration, families); + bundling, maybeSignedIpa, objcConfiguration, families, primaryBundleId, fallbackBundleId); registerBundleMergeActions( maybeSignedIpa, bundling.getBundleContentArtifacts(), bundleMergeControlBytes); diff --git a/src/main/protobuf/bundlemerge.proto b/src/main/protobuf/bundlemerge.proto index b04eba3aa6..b124d7edbc 100644 --- a/src/main/protobuf/bundlemerge.proto +++ b/src/main/protobuf/bundlemerge.proto @@ -65,6 +65,12 @@ message Control { // 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; + + // A fallback bundle identifier used when primary is not filled. + optional string fallback_bundle_identifier = 15; } // Represents a zip file to merge with the final zip. 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 3a061db304..20b8b72c7d 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 @@ -119,6 +119,11 @@ public final class BundleMerging { if (control.hasExecutableName()) { plistMerging.setExecutableName(control.getExecutableName()); } + + plistMerging.setBundleIdentifier( + control.hasPrimaryBundleIdentifier() ? control.getPrimaryBundleIdentifier() : null, + control.hasFallbackBundleIdentifier() ? control.getFallbackBundleIdentifier() : null); + plistMerging.write(tempMergedPlist, tempPkgInfo); 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 dba8f84ac3..6b7f441945 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 @@ -56,6 +56,7 @@ import javax.xml.parsers.ParserConfigurationException; * Utility code for merging project files. */ public class PlistMerging extends Value<PlistMerging> { + private static final String BUNDLE_IDENTIFIER_PLIST_KEY = "CFBundleIdentifier"; /** * Exception type thrown when validation of the plist file fails. @@ -251,6 +252,35 @@ public class PlistMerging extends Value<PlistMerging> { return this; } + + /** + * Sets the given identifier on this merged plist in the {@code CFBundleIdentifier} + * attribute. + * + * @param primaryIdentifier used if the bundle doesn't have an identifier already, can be null + * @param fallbackIdentifier used if neither bundle, nor primary identifier is set, can be null + * @return this plist merging + * @throws ValidationException if both plist and control contain bundle identifiers and they + * don't match + */ + public PlistMerging setBundleIdentifier(String primaryIdentifier, String fallbackIdentifier) { + NSString bundleIdentifier = (NSString) merged.get(BUNDLE_IDENTIFIER_PLIST_KEY); + + if (bundleIdentifier == null) { + if (primaryIdentifier != null) { + merged.put(BUNDLE_IDENTIFIER_PLIST_KEY, primaryIdentifier); + } else if (fallbackIdentifier != null) { + merged.put(BUNDLE_IDENTIFIER_PLIST_KEY, fallbackIdentifier); + } + } else if (primaryIdentifier != null + && !primaryIdentifier.equals(bundleIdentifier.getContent())) { + throw new ValidationException(String.format( + "Blaze generated bundle_id is %s but the Plist %s is %s", + primaryIdentifier, BUNDLE_IDENTIFIER_PLIST_KEY, bundleIdentifier)); + } + + return this; + } private static class Utf8BomSkippingByteSource extends ByteSource { |