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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
5
6 """
7 Generates shim headers that mirror the directory structure of bundled headers,
8 but just forward to the system ones.
9
10 This allows seamless compilation against system headers with no changes
11 to our source code.
12 """
13
14
15 import optparse
16 import os.path
17 import sys
18
19
20 SHIM_TEMPLATE = """
21 #if defined(OFFICIAL_BUILD)
22 #error shim headers must not be used in official builds!
23 #endif
24
25 #include <%s>
26 """
27
28
29 def GeneratorMain(argv):
30 parser = optparse.OptionParser()
31 parser.add_option('--headers-root')
32 parser.add_option('--output-directory')
33 parser.add_option('--outputs', action='store_true')
34 parser.add_option('--generate', action='store_true')
35
36 options, args = parser.parse_args(argv)
37
38 if not options.headers_root:
39 parser.error('Missing --headers-root parameter.')
40 if not options.output_directory:
41 parser.error('Missing --output-directory parameter.')
42
43 source_tree_root = os.path.abspath(
44 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
45
46 target_directory = os.path.join(
47 options.output_directory,
48 os.path.relpath(options.headers_root, source_tree_root))
49 for header_filename in args:
50 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.
51 os.makedirs(target_directory)
52 if options.outputs:
53 yield os.path.join(target_directory, header_filename)
54 if options.generate:
55 with open(os.path.join(target_directory, header_filename), 'w') as f:
56 f.write(SHIM_TEMPLATE % header_filename)
57
58
59 def DoMain(argv):
60 return '\n'.join(GeneratorMain(argv))
61
62
63 if __name__ == '__main__':
64 DoMain(sys.argv[1:])
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698