| 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 Creates a library loader (a header and implementation file), | 7 Creates a library loader (a header and implementation file), |
| 8 which is a wrapper for dlopen or direct linking with given library. | 8 which is a wrapper for dlopen or direct linking with given library. |
| 9 | 9 |
| 10 The loader makes it possible to have the same client code for both cases, | 10 The loader makes it possible to have the same client code for both cases, |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 IMPL_MEMBER_CLEANUP_TEMPLATE = """ %(function_name)s = NULL; | 139 IMPL_MEMBER_CLEANUP_TEMPLATE = """ %(function_name)s = NULL; |
| 140 """ | 140 """ |
| 141 | 141 |
| 142 def main(): | 142 def main(): |
| 143 parser = optparse.OptionParser() | 143 parser = optparse.OptionParser() |
| 144 parser.add_option('--name') | 144 parser.add_option('--name') |
| 145 parser.add_option('--output-cc') | 145 parser.add_option('--output-cc') |
| 146 parser.add_option('--output-h') | 146 parser.add_option('--output-h') |
| 147 parser.add_option('--header') | 147 parser.add_option('--header') |
| 148 | 148 |
| 149 parser.add_option('--bundled-header') |
| 149 parser.add_option('--use-extern-c', action='store_true', default=False) | 150 parser.add_option('--use-extern-c', action='store_true', default=False) |
| 150 parser.add_option('--link-directly', type=int, default=0) | 151 parser.add_option('--link-directly', type=int, default=0) |
| 151 | 152 |
| 152 options, args = parser.parse_args() | 153 options, args = parser.parse_args() |
| 153 | 154 |
| 154 if not options.name: | 155 if not options.name: |
| 155 parser.error('Missing --name parameter') | 156 parser.error('Missing --name parameter') |
| 156 if not options.output_cc: | 157 if not options.output_cc: |
| 157 parser.error('Missing --output-cc parameter') | 158 parser.error('Missing --output-cc parameter') |
| 158 if not options.output_h: | 159 if not options.output_h: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 183 }) | 184 }) |
| 184 member_init.append(IMPL_MEMBER_INIT_TEMPLATE % { | 185 member_init.append(IMPL_MEMBER_INIT_TEMPLATE % { |
| 185 'function_name': fn, | 186 'function_name': fn, |
| 186 'unique_prefix': unique_prefix | 187 'unique_prefix': unique_prefix |
| 187 }) | 188 }) |
| 188 member_cleanup.append(IMPL_MEMBER_CLEANUP_TEMPLATE % { | 189 member_cleanup.append(IMPL_MEMBER_CLEANUP_TEMPLATE % { |
| 189 'function_name': fn, | 190 'function_name': fn, |
| 190 'unique_prefix': unique_prefix | 191 'unique_prefix': unique_prefix |
| 191 }) | 192 }) |
| 192 | 193 |
| 193 wrapped_header_include = '#include %s' % options.header | 194 header = options.header |
| 195 if options.link_directly == 0 and options.bundled_header: |
| 196 header = options.bundled_header |
| 197 wrapped_header_include = '#include %s\n' % header |
| 194 | 198 |
| 195 # Some libraries (e.g. libpci) have headers that cannot be included | 199 # Some libraries (e.g. libpci) have headers that cannot be included |
| 196 # without extern "C", otherwise they cause the link to fail. | 200 # without extern "C", otherwise they cause the link to fail. |
| 197 # TODO(phajdan.jr): This is a workaround for broken headers. Remove it. | 201 # TODO(phajdan.jr): This is a workaround for broken headers. Remove it. |
| 198 if options.use_extern_c: | 202 if options.use_extern_c: |
| 199 wrapped_header_include = 'extern "C" {\n%s\n}\n' % wrapped_header_include | 203 wrapped_header_include = 'extern "C" {\n%s\n}\n' % wrapped_header_include |
| 200 | 204 |
| 201 # It seems cleaner just to have a single #define here and #ifdefs in bunch | 205 # It seems cleaner just to have a single #define here and #ifdefs in bunch |
| 202 # of places, rather than having a different set of templates, duplicating | 206 # of places, rather than having a different set of templates, duplicating |
| 203 # or complicating more code. | 207 # or complicating more code. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 impl_file = open(options.output_cc, 'w') | 243 impl_file = open(options.output_cc, 'w') |
| 240 try: | 244 try: |
| 241 impl_file.write(impl_contents) | 245 impl_file.write(impl_contents) |
| 242 finally: | 246 finally: |
| 243 impl_file.close() | 247 impl_file.close() |
| 244 | 248 |
| 245 return 0 | 249 return 0 |
| 246 | 250 |
| 247 if __name__ == '__main__': | 251 if __name__ == '__main__': |
| 248 sys.exit(main()) | 252 sys.exit(main()) |
| OLD | NEW |