| Index: tools/protoc_wrapper/protoc_wrapper.py
|
| ===================================================================
|
| --- tools/protoc_wrapper/protoc_wrapper.py (revision 0)
|
| +++ tools/protoc_wrapper/protoc_wrapper.py (revision 0)
|
| @@ -0,0 +1,66 @@
|
| +#!/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 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):
|
| + # Expected to be called as:
|
| + # protoc_wrapper header_to_include:/path/to/cpp.pb.h /path/to/protoc \
|
| + # [protoc args]
|
| + if len(argv) < 3:
|
| + return 1
|
| +
|
| + # Parse the first argument:
|
| + combined_wrapper_arg = argv[1]
|
| + if combined_wrapper_arg.count(':') > 1:
|
| + return 1
|
| + (extra_header, generated_header) = combined_wrapper_arg.split(':')
|
| + if not generated_header:
|
| + return 1
|
| +
|
| + # Run what is hopefully protoc.
|
| + try:
|
| + ret = subprocess.call(argv[2:])
|
| + if ret != 0:
|
| + return ret
|
| + except:
|
| + return 1
|
| +
|
| + # protoc succeeded, check to see if the generated cpp header needs editing.
|
| + if not extra_header:
|
| + return 0
|
| + return ModifyHeader(generated_header, extra_header)
|
| +
|
| +
|
| +if __name__ == '__main__':
|
| + sys.exit(main(sys.argv))
|
|
|
| Property changes on: tools/protoc_wrapper/protoc_wrapper.py
|
| ___________________________________________________________________
|
| Added: svn:executable
|
| + *
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|