summaryrefslogtreecommitdiffstats
path: root/tools/generate_shim_headers
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-18 01:51:37 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-18 01:51:37 +0000
commitddc6d877066d01a136e1b40c86865760d8cf414a (patch)
tree35b8c1ca59daebf2cf2c8770943fed28206ea094 /tools/generate_shim_headers
parent0a57c025d1e88036c4ae01b3293a74fc84834d04 (diff)
downloadchromium_src-ddc6d877066d01a136e1b40c86865760d8cf414a.zip
chromium_src-ddc6d877066d01a136e1b40c86865760d8cf414a.tar.gz
chromium_src-ddc6d877066d01a136e1b40c86865760d8cf414a.tar.bz2
Generate shim headers for libpng
BUG=165264 Review URL: https://codereview.chromium.org/11470020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173618 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/generate_shim_headers')
-rwxr-xr-xtools/generate_shim_headers/generate_shim_headers.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/tools/generate_shim_headers/generate_shim_headers.py b/tools/generate_shim_headers/generate_shim_headers.py
new file mode 100755
index 0000000..068a2ac
--- /dev/null
+++ b/tools/generate_shim_headers/generate_shim_headers.py
@@ -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.
+
+"""
+Generates shim headers that mirror the directory structure of bundled headers,
+but just forward to the system ones.
+
+This allows seamless compilation against system headers with no changes
+to our source code.
+"""
+
+
+import optparse
+import os.path
+import sys
+
+
+SHIM_TEMPLATE = """
+#if defined(OFFICIAL_BUILD)
+#error shim headers must not be used in official builds!
+#endif
+
+#include <%s>
+"""
+
+
+def GeneratorMain(argv):
+ parser = optparse.OptionParser()
+ parser.add_option('--headers-root')
+ parser.add_option('--output-directory')
+ parser.add_option('--outputs', action='store_true')
+ parser.add_option('--generate', action='store_true')
+
+ options, args = parser.parse_args(argv)
+
+ if not options.headers_root:
+ parser.error('Missing --headers-root parameter.')
+ if not options.output_directory:
+ parser.error('Missing --output-directory parameter.')
+ if not args:
+ parser.error('Missing arguments - header file names.')
+
+ source_tree_root = os.path.abspath(
+ os.path.join(os.path.dirname(__file__), '..', '..'))
+
+ target_directory = os.path.join(
+ options.output_directory,
+ os.path.relpath(options.headers_root, source_tree_root))
+ if options.generate and not os.path.exists(target_directory):
+ os.makedirs(target_directory)
+ for header_filename in args:
+ if options.outputs:
+ yield os.path.join(target_directory, header_filename)
+ if options.generate:
+ with open(os.path.join(target_directory, header_filename), 'w') as f:
+ f.write(SHIM_TEMPLATE % header_filename)
+
+
+def DoMain(argv):
+ return '\n'.join(GeneratorMain(argv))
+
+
+if __name__ == '__main__':
+ DoMain(sys.argv[1:])