summaryrefslogtreecommitdiffstats
path: root/tools/protoc_wrapper
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-13 02:27:52 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-13 02:27:52 +0000
commitc6ccf4205e05b3cee0b03b5774bd2cc828d012d4 (patch)
tree46b51909181f4b3d6de6a3ec32df7049d7181eb8 /tools/protoc_wrapper
parentda5665eb65fdf7f8e781150b4b4200a1b9f2c7ac (diff)
downloadchromium_src-c6ccf4205e05b3cee0b03b5774bd2cc828d012d4.zip
chromium_src-c6ccf4205e05b3cee0b03b5774bd2cc828d012d4.tar.gz
chromium_src-c6ccf4205e05b3cee0b03b5774bd2cc828d012d4.tar.bz2
CrOS: Convert MediaTransferProtocolDaemonClient to use protobufs.
BUG=chromium-os:29557 Review URL: https://chromiumcodereview.appspot.com/10913048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156468 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/protoc_wrapper')
-rwxr-xr-xtools/protoc_wrapper/protoc_wrapper.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/tools/protoc_wrapper/protoc_wrapper.py b/tools/protoc_wrapper/protoc_wrapper.py
new file mode 100755
index 0000000..be7f7a5
--- /dev/null
+++ b/tools/protoc_wrapper/protoc_wrapper.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""A simple wrapper for protoc to add includes in generated cpp headers."""
+
+import optparse
+import subprocess
+import sys
+
+PROTOC_INCLUDE_POINT = '// @@protoc_insertion_point(includes)\n'
+
+def ModifyHeader(header_file, extra_header):
+ """Adds |extra_header| to |header_file|. Returns 0 on success.
+
+ |extra_header| is the name of the header file to include.
+ |header_file| is a generated protobuf cpp header.
+ """
+ include_point_found = False
+ header_contents = []
+ with open(header_file) as f:
+ for line in f:
+ header_contents.append(line)
+ if line == PROTOC_INCLUDE_POINT:
+ extra_header_msg = '#include "%s"\n' % extra_header
+ header_contents.append(extra_header_msg)
+ include_point_found = True;
+ if not include_point_found:
+ return 1
+
+ with open(header_file, 'wb') as f:
+ f.write(''.join(header_contents))
+ return 0
+
+
+def main(argv):
+ parser = optparse.OptionParser()
+ parser.add_option('--include', dest='extra_header',
+ help='The extra header to include. This must be specified '
+ 'along with --protobuf.')
+ parser.add_option('--protobuf', dest='generated_header',
+ help='The c++ protobuf header to add the extra header to. '
+ 'This must be specified along with --include.')
+ (options, args) = parser.parse_args(sys.argv)
+ if len(args) < 2:
+ return 1
+
+ # Run what is hopefully protoc.
+ ret = subprocess.call(args[1:])
+ if ret != 0:
+ return ret
+
+ # protoc succeeded, check to see if the generated cpp header needs editing.
+ if not options.extra_header or not options.generated_header:
+ return 0
+ return ModifyHeader(options.generated_header, options.extra_header)
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))