OLD | NEW |
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 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 (header_filename, | 58 (header_filename, |
59 include_before, | 59 include_before, |
60 include_after) = header_spec.split(';', 2) | 60 include_after) = header_spec.split(';', 2) |
61 else: | 61 else: |
62 header_filename = header_spec | 62 header_filename = header_spec |
63 include_before = '' | 63 include_before = '' |
64 include_after = '' | 64 include_after = '' |
65 if options.outputs: | 65 if options.outputs: |
66 yield os.path.join(target_directory, header_filename) | 66 yield os.path.join(target_directory, header_filename) |
67 if options.generate: | 67 if options.generate: |
68 with open(os.path.join(target_directory, header_filename), 'w') as f: | 68 header_path = os.path.join(target_directory, header_filename) |
| 69 header_dir = os.path.dirname(header_path) |
| 70 if not os.path.exists(header_dir): |
| 71 os.makedirs(header_dir) |
| 72 with open(header_path, 'w') as f: |
69 f.write(SHIM_TEMPLATE) | 73 f.write(SHIM_TEMPLATE) |
70 | 74 |
71 if options.define: | 75 if options.define: |
72 for define in options.define: | 76 for define in options.define: |
73 key, value = define.split('=', 1) | 77 key, value = define.split('=', 1) |
74 # This non-standard push_macro extension is supported | 78 # This non-standard push_macro extension is supported |
75 # by compilers we support (GCC, clang). | 79 # by compilers we support (GCC, clang). |
76 f.write('#pragma push_macro("%s")\n' % key) | 80 f.write('#pragma push_macro("%s")\n' % key) |
77 f.write('#undef %s\n' % key) | 81 f.write('#undef %s\n' % key) |
78 f.write('#define %s %s\n' % (key, value)) | 82 f.write('#define %s %s\n' % (key, value)) |
(...skipping 19 matching lines...) Expand all Loading... |
98 # by compilers we support (GCC, clang). | 102 # by compilers we support (GCC, clang). |
99 f.write('#pragma pop_macro("%s")\n' % key) | 103 f.write('#pragma pop_macro("%s")\n' % key) |
100 | 104 |
101 | 105 |
102 def DoMain(argv): | 106 def DoMain(argv): |
103 return '\n'.join(GeneratorMain(argv)) | 107 return '\n'.join(GeneratorMain(argv)) |
104 | 108 |
105 | 109 |
106 if __name__ == '__main__': | 110 if __name__ == '__main__': |
107 DoMain(sys.argv[1:]) | 111 DoMain(sys.argv[1:]) |
OLD | NEW |