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

Side by Side Diff: tools/generate_shim_headers/generate_shim_headers.py

Issue 11693007: Linux: use generated shim headers for system mesa. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes for windows Created 7 years, 11 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/mesa/mesa.gyp ('k') | ui/gl/generate_bindings.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """ 6 """
7 Generates shim headers that mirror the directory structure of bundled headers, 7 Generates shim headers that mirror the directory structure of bundled headers,
8 but just forward to the system ones. 8 but just forward to the system ones.
9 9
10 This allows seamless compilation against system headers with no changes 10 This allows seamless compilation against system headers with no changes
11 to our source code. 11 to our source code.
12 """ 12 """
13 13
14 14
15 import optparse 15 import optparse
16 import os.path 16 import os.path
17 import sys 17 import sys
18 18
19 19
20 SHIM_TEMPLATE = """ 20 SHIM_TEMPLATE = """
21 #if defined(OFFICIAL_BUILD) 21 #if defined(OFFICIAL_BUILD)
22 #error shim headers must not be used in official builds! 22 #error shim headers must not be used in official builds!
23 #endif 23 #endif
24
25 #include <%s>
26 """ 24 """
27 25
28 26
29 def GeneratorMain(argv): 27 def GeneratorMain(argv):
30 parser = optparse.OptionParser() 28 parser = optparse.OptionParser()
31 parser.add_option('--headers-root') 29 parser.add_option('--headers-root', action='append')
32 parser.add_option('--output-directory') 30 parser.add_option('--output-directory')
31 parser.add_option('--use-include-next', action='store_true')
33 parser.add_option('--outputs', action='store_true') 32 parser.add_option('--outputs', action='store_true')
34 parser.add_option('--generate', action='store_true') 33 parser.add_option('--generate', action='store_true')
35 34
36 options, args = parser.parse_args(argv) 35 options, args = parser.parse_args(argv)
37 36
38 if not options.headers_root: 37 if not options.headers_root:
39 parser.error('Missing --headers-root parameter.') 38 parser.error('Missing --headers-root parameter.')
40 if not options.output_directory: 39 if not options.output_directory:
41 parser.error('Missing --output-directory parameter.') 40 parser.error('Missing --output-directory parameter.')
42 if not args: 41 if not args:
43 parser.error('Missing arguments - header file names.') 42 parser.error('Missing arguments - header file names.')
44 43
45 source_tree_root = os.path.abspath( 44 source_tree_root = os.path.abspath(
46 os.path.join(os.path.dirname(__file__), '..', '..')) 45 os.path.join(os.path.dirname(__file__), '..', '..'))
47 46
48 target_directory = os.path.join( 47 for root in options.headers_root:
49 options.output_directory, 48 target_directory = os.path.join(
50 os.path.relpath(options.headers_root, source_tree_root)) 49 options.output_directory,
51 if options.generate and not os.path.exists(target_directory): 50 os.path.relpath(root, source_tree_root))
52 os.makedirs(target_directory) 51 if options.generate and not os.path.exists(target_directory):
53 for header_filename in args: 52 os.makedirs(target_directory)
54 if options.outputs: 53
55 yield os.path.join(target_directory, header_filename) 54 for header_spec in args:
56 if options.generate: 55 if ';' in header_spec:
57 with open(os.path.join(target_directory, header_filename), 'w') as f: 56 (header_filename,
58 f.write(SHIM_TEMPLATE % header_filename) 57 include_before,
58 include_after) = header_spec.split(';', 2)
59 else:
60 header_filename = header_spec
61 include_before = ''
62 include_after = ''
63 if options.outputs:
64 yield os.path.join(target_directory, header_filename)
65 if options.generate:
66 with open(os.path.join(target_directory, header_filename), 'w') as f:
67 f.write(SHIM_TEMPLATE)
68
69 if include_before:
70 for header in include_before.split(':'):
71 f.write('#include %s\n' % header)
72
73 if options.use_include_next:
74 f.write('#include_next <%s>\n' % header_filename)
75 else:
76 f.write('#include <%s>\n' % header_filename)
77
78 if include_after:
79 for header in include_after.split(':'):
80 f.write('#include %s\n' % header)
59 81
60 82
61 def DoMain(argv): 83 def DoMain(argv):
62 return '\n'.join(GeneratorMain(argv)) 84 return '\n'.join(GeneratorMain(argv))
63 85
64 86
65 if __name__ == '__main__': 87 if __name__ == '__main__':
66 DoMain(sys.argv[1:]) 88 DoMain(sys.argv[1:])
OLDNEW
« no previous file with comments | « third_party/mesa/mesa.gyp ('k') | ui/gl/generate_bindings.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698