Always output entitlements plist in the XML format
Adding --extra_entitlements flag to a build triggers a merge of entitlements files using plmerge tool. Configure build rules to output the resulting plist file in the XML format. Bundles signed with entitlements in the binary format fail to load on device.
--
MOS_MIGRATED_REVID=120588271
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/PlMergeControlBytes.java b/src/main/java/com/google/devtools/build/lib/rules/objc/PlMergeControlBytes.java
index 548f6b6..fc04505 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/PlMergeControlBytes.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/PlMergeControlBytes.java
@@ -14,6 +14,7 @@
package com.google.devtools.build.lib.rules.objc;
+import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.ByteSource;
import com.google.devtools.build.lib.actions.Artifact;
@@ -41,6 +42,7 @@
@Nullable private final Map<String, String> variableSubstitutions;
@Nullable private final String executableName;
private final Artifact mergedPlist;
+ private final OutputFormat outputFormat;
/**
* Creates a control based on the passed bundling's plists and values.
@@ -64,13 +66,17 @@
bundling.getFallbackBundleId(),
bundling.variableSubstitutions(),
bundling.getName(),
- mergedPlist);
+ mergedPlist,
+ OutputFormat.BINARY);
}
/**
* Creates a control that merges the given plists into the merged plist.
*/
- static PlMergeControlBytes fromPlists(NestedSet<Artifact> inputPlists, Artifact mergedPlist) {
+ static PlMergeControlBytes fromPlists(
+ NestedSet<Artifact> inputPlists,
+ Artifact mergedPlist,
+ OutputFormat outputFormat) {
return new PlMergeControlBytes(
inputPlists,
NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER),
@@ -78,7 +84,8 @@
null,
ImmutableMap.<String, String>of(),
null,
- mergedPlist);
+ mergedPlist,
+ outputFormat);
}
private PlMergeControlBytes(
@@ -88,7 +95,8 @@
@Nullable String fallbackBundleId,
@Nullable Map<String, String> variableSubstitutions,
@Nullable String executableName,
- Artifact mergedPlist) {
+ Artifact mergedPlist,
+ OutputFormat outputFormat) {
this.inputPlists = inputPlists;
this.immutableInputPlists = immutableInputPlists;
this.primaryBundleId = primaryBundleId;
@@ -96,6 +104,7 @@
this.variableSubstitutions = variableSubstitutions;
this.executableName = executableName;
this.mergedPlist = mergedPlist;
+ this.outputFormat = Preconditions.checkNotNull(outputFormat);
}
@Override
@@ -123,6 +132,26 @@
control.setExecutableName(executableName);
}
+ control.setOutputFormat(outputFormat.getProtoOutputFormat());
+
return control.build();
}
+
+ /**
+ * Plist output formats.
+ */
+ public enum OutputFormat {
+ BINARY(Control.OutputFormat.BINARY),
+ XML(Control.OutputFormat.XML);
+
+ private final Control.OutputFormat protoOutputFormat;
+
+ private OutputFormat(Control.OutputFormat protoOutputFormat) {
+ this.protoOutputFormat = protoOutputFormat;
+ }
+
+ Control.OutputFormat getProtoOutputFormat() {
+ return protoOutputFormat;
+ }
+ }
}
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 69ad78f..8068f3a 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
@@ -549,7 +549,7 @@
PlMergeControlBytes controlBytes =
PlMergeControlBytes.fromPlists(
NestedSetBuilder.create(Order.STABLE_ORDER, substitutedEntitlements, extraEntitlements),
- intermediateArtifacts.entitlements());
+ intermediateArtifacts.entitlements(), PlMergeControlBytes.OutputFormat.XML);
Artifact plMergeControlArtifact = ObjcRuleClasses.artifactByAppendingToBaseName(ruleContext,
artifactName(".merge-entitlements-control"));
diff --git a/src/main/protobuf/plmerge.proto b/src/main/protobuf/plmerge.proto
index 14eef6c..d26c712 100644
--- a/src/main/protobuf/plmerge.proto
+++ b/src/main/protobuf/plmerge.proto
@@ -19,8 +19,14 @@
// Contains necessary arguments for PlMerge, which is responsible for merging
// plist files.
-// Next Id: 8
+// Next Id: 9
message Control {
+ // Formats that plmerge can output to.
+ enum OutputFormat {
+ BINARY = 1;
+ XML = 2;
+ }
+
// Paths to the plist files to merge relative to execution root.
repeated string source_file = 1;
@@ -32,6 +38,9 @@
// Path to the output file to merge relative to execution root.
required string out_file = 2;
+ // Output format of the resulting plist file.
+ optional OutputFormat output_format = 8 [default = BINARY];
+
// Key-value substitutions to support templating for plists. A substitution
// is made if the substitution key appears as a value for any key-value pair
// in any source_file.
diff --git a/src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlMerge.java b/src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlMerge.java
index c204e2f..8f9f558 100644
--- a/src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlMerge.java
+++ b/src/objc_tools/plmerge/java/com/google/devtools/build/xcode/plmerge/PlMerge.java
@@ -27,6 +27,7 @@
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
+import java.nio.file.Path;
/**
* Entry point for the {@code plmerge} tool, which merges the data from one or more plists into a
@@ -75,7 +76,20 @@
// This prevents CFBundleIdentifiers being put into strings files.
merging.setBundleIdentifier(primaryBundleId, fallbackBundleId);
}
- merging.writePlist(fileSystem.getPath(control.getOutFile()));
+
+ Path outputPath = fileSystem.getPath(control.getOutFile());
+ switch (control.getOutputFormat()) {
+ case BINARY:
+ merging.writePlist(outputPath);
+ break;
+ case XML:
+ merging.writeXmlPlist(outputPath);
+ break;
+ default:
+ throw new IllegalArgumentException(String.format(
+ "Unknown output format in the control file: %s",
+ control.getOutputFormat()));
+ }
}
private static void validateControl(Control control) {
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 0463039..b292a65 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
@@ -122,7 +122,7 @@
}
/**
- * Writes the results of a merge operation to a plist file.
+ * Writes the results of a merge operation to a binary plist file.
* @param plistPath the path of the plist to write in binary format
*/
public PlistMerging writePlist(Path plistPath) throws IOException {
@@ -133,6 +133,17 @@
}
/**
+ * Writes the results of a merge operation to an XML plist file.
+ * @param plistPath the path of the plist to write in XML format
+ */
+ public PlistMerging writeXmlPlist(Path plistPath) throws IOException {
+ try (OutputStream out = Files.newOutputStream(plistPath)) {
+ PropertyListParser.saveAsXML(merged, out);
+ }
+ return this;
+ }
+
+ /**
* Writes a PkgInfo file based on certain keys in the merged plist.
* @param pkgInfoPath the path of the PkgInfo file to write. In many iOS apps, this file just
* contains the raw string {@code APPL????}.