Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Unified Diff: tools/generate_shim_headers/generate_shim_headers.py

Issue 11470020: Generate shim headers for libpng (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: don't return directory as an output Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/generate_shim_headers/generate_shim_headers.py
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 0000000000000000000000000000000000000000..23aca3449d3ef1abfbc0217205cbb0679ba6ed50
--- /dev/null
+++ b/tools/generate_shim_headers/generate_shim_headers.py
@@ -0,0 +1,64 @@
+#!/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.')
+
+ source_tree_root = os.path.abspath(
+ os.path.join(os.path.dirname(__file__), '..', '..'))
Mark Mentovai 2012/12/17 23:02:41 I’m surprised we don’t have a better way to find t
Paweł Hajdan Jr. 2012/12/17 23:18:26 I'd prefer to use that one, to avoid various issue
Mark Mentovai 2012/12/17 23:23:24 Paweł Hajdan Jr. wrote:
Paweł Hajdan Jr. 2012/12/17 23:35:48 There are path_utils.py in tools/python/google, bu
+
+ target_directory = os.path.join(
+ options.output_directory,
+ os.path.relpath(options.headers_root, source_tree_root))
+ for header_filename in args:
+ if options.generate and not os.path.exists(target_directory):
Mark Mentovai 2012/12/17 23:02:41 You can pull this outside the loop. (Either add l
Paweł Hajdan Jr. 2012/12/17 23:18:26 Done.
+ os.makedirs(target_directory)
+ 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:])

Powered by Google App Engine
This is Rietveld 408576698