common-mk: Mirror protoctxt.gypi from src/platform/

protoctxt.gypi was added to src/platform/common-mk in CL:189238 but is not yet
mirrored in src/platform2/. This CL copies the file over so that shill can start
using src/platform2/common-mk build files.

BUG=chromium:363865
TEST=cros_workon_make chromeos-base/platform2 --test
     build_packages
     FEATURES=test emerge-peppy platform2

Change-Id: Ifc9b9d03795b715ba98580a9b4b3f648b9ef8653
Reviewed-on: https://chromium-review.googlesource.com/195640
Reviewed-by: Ben Chan <benchan@chromium.org>
Commit-Queue: Prathmesh Prabhu <pprabhu@chromium.org>
Tested-by: Prathmesh Prabhu <pprabhu@chromium.org>
diff --git a/common-mk/protoctxt.gypi b/common-mk/protoctxt.gypi
new file mode 100644
index 0000000..834915f
--- /dev/null
+++ b/common-mk/protoctxt.gypi
@@ -0,0 +1,48 @@
+# Helper file to convert text format protobuf files to binary format.
+
+# Note: This file is similar to protoc.gypi, but is kept separate because
+# - They expect different inputs/outputs: both rules would have to set default
+#   values for variables that are not really sensible.
+# - protoc.gypi exports a hard dependency, while protoctxt.gypi does not.
+
+# To use this rule, add a target to your gyp file defining:
+# protoc_proto_dir: The directory where the proto definition can be found.
+# protoc_proto_def: Relative path to proto definition from |protoc_proto_dir|.
+# protoc_message_name: The fully qualified name of the message contained in
+#     the protobuf.
+# protoc_text_dir: The directory where the text format protobuf[s] can be found.
+# protoc_bin_dir: The full path to the output directory. Note that this path is
+#     not relative to the <(SHARED_INTERMEDIATE_DIR). You must ensure that this
+#     directory is unique across all platform2 projects to avoid collisions. One
+#     way to do this is to include your project name in the directory path.
+# Finally, specify the protobuf files in text format as the sources. These files
+# should have a '.prototxt' file extension.
+{
+  'variables': {
+    'protoc_proto_dir%': '.',
+    'protoc_text_dir%': '.',
+    'protoc': '<!(which protoc)',
+  },
+  'rules': [
+    {
+      'rule_name': 'protoc_text_to_bin',
+      'extension': 'prototxt',
+      'inputs': [
+        '<(protoc)',
+        '<(protoc_proto_dir)/<(protoc_proto_def)',
+      ],
+      'outputs': [
+        '<(protoc_bin_dir)/<(RULE_INPUT_ROOT).pbf',
+      ],
+      'action': [
+        '<(protoc)',
+        '--proto_path', '<(protoc_proto_dir)',
+        '--encode', '<(protoc_message_name)',
+        '--protobuf_in', '<(protoc_text_dir)/<(RULE_INPUT_NAME)',
+        '--protobuf_out', '<(protoc_bin_dir)/<(RULE_INPUT_ROOT).pbf',
+        '<(protoc_proto_dir)/<(protoc_proto_def)',
+      ],
+      'message': 'Encoding text format protobuf file <(RULE_INPUT_ROOT).',
+    },
+  ],
+}