Skip to content

Commit

Permalink
Add flags primary_bundle_id and fallback_bundle_id to PlMerge to set …
Browse files Browse the repository at this point in the history
…bundle identifiers. Also allow users to use bundle identifiers specified in BUILD files via "bundle_id" attribute on objc bundling rules to override the ones from plist files.

RELNOTES: bundle_id attribute on objc_* rules now overrides plist bundle id".

--
MOS_MIGRATED_REVID=92247814
  • Loading branch information
Googler authored and kchodorow committed Apr 28, 2015
1 parent cd68707 commit 67944d8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ public static class PlMergeOptions extends OptionsBase {
help = "Path to the output file. Required.",
defaultValue = "null")
public String outFile;

@Option(
name = "primary_bundle_id",
help = "A reverse-DNS string identifier for this bundle associated with output binary "
+ "plist. This flag overrides the bundle id specified in field CFBundleIdentifier in "
+ "the associated plist file.",
defaultValue = "null")
public String primaryBundleId;

@Option(
name = "fallback_bundle_id",
help = "A fallback reverse-DNS string identifier for this bundle when the bundle "
+ "identifier is not specified in flag primary_bundle_id or associated plist file",
defaultValue = "null")
public String fallbackBundleId;
}

public static void main(String[] args) throws IOException, OptionsParsingException {
Expand All @@ -74,6 +89,7 @@ public static void main(String[] args) throws IOException, OptionsParsingExcepti

PlistMerging merging = PlistMerging.from(sourceFilePaths, ImmutableMap.<String, NSObject>of(),
ImmutableMap.<String, String>of(), new KeysToRemoveIfEmptyString());
merging.setBundleIdentifier(options.primaryBundleId, options.fallbackBundleId);
merging.writePlist(fileSystem.getPath(options.outFile));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,28 +263,21 @@ public PlistMerging setExecutableName(String executableName) {
* 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
* @param primaryIdentifier used to set the bundle identifier or override the existing one from
* plist file, can be null
* @param fallbackIdentifier used to set the bundle identifier if it is not set by plist file or
* primary identifier, 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));
if (primaryIdentifier != null) {
merged.put(BUNDLE_IDENTIFIER_PLIST_KEY, primaryIdentifier);
} else if (bundleIdentifier == null && fallbackIdentifier != null) {
merged.put(BUNDLE_IDENTIFIER_PLIST_KEY, fallbackIdentifier);
}

return this;
}

Expand Down

0 comments on commit 67944d8

Please sign in to comment.