OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import argparse | 5 import argparse |
6 import os | 6 import os |
7 import sys | 7 import sys |
8 | 8 |
9 from distutils import sysconfig | 9 from distutils import sysconfig |
10 from distutils.command import build_ext | 10 from distutils.command import build_ext |
11 from distutils.dist import Distribution | 11 from distutils.dist import Distribution |
12 from distutils.extension import Extension | 12 from distutils.extension import Extension |
13 | 13 |
14 def main(): | 14 def main(): |
15 """Command line utility to retrieve compilation options for python modules' | 15 """Command line utility to retrieve compilation options for python modules' |
16 """ | 16 """ |
17 parser = argparse.ArgumentParser( | 17 parser = argparse.ArgumentParser( |
18 description='Retrieves compilation options for python modules.') | 18 description='Retrieves compilation options for python modules.') |
19 parser.add_argument('--gn', | |
20 help='Returns all values in a format suitable for gn', | |
21 action='store_true') | |
22 parser.add_argument('--libraries', help='Returns libraries', | 19 parser.add_argument('--libraries', help='Returns libraries', |
23 action='store_true') | 20 action='store_true') |
24 parser.add_argument('--includes', help='Returns includes', | 21 parser.add_argument('--includes', help='Returns includes', |
25 action='store_true') | 22 action='store_true') |
26 parser.add_argument('--library_dirs', help='Returns library_dirs', | 23 parser.add_argument('--library_dirs', help='Returns library_dirs', |
27 action='store_true') | 24 action='store_true') |
28 opts = parser.parse_args() | 25 opts = parser.parse_args() |
29 | 26 |
30 ext = Extension('Dummy', []) | 27 ext = Extension('Dummy', []) |
31 b = build_ext.build_ext(Distribution()) | 28 b = build_ext.build_ext(Distribution()) |
32 b.initialize_options() | 29 b.initialize_options() |
33 b.finalize_options() | 30 b.finalize_options() |
34 result = [] | 31 result = [] |
35 if opts.libraries: | 32 if opts.libraries: |
36 libraries = b.get_libraries(ext) | 33 libraries = b.get_libraries(ext) |
37 if sys.platform == 'darwin': | 34 if sys.platform == 'darwin': |
38 libraries.append('python%s' % sys.version[:3]) | 35 libraries.append('python%s' % sys.version[:3]) |
39 if not opts.gn and sys.platform in ['darwin', 'linux2']: | |
40 # In case of GYP output for darwin and linux prefix all | |
41 # libraries (if there are any) so the result can be used as a | |
42 # compiler argument. GN handles platform-appropriate prefixing itself. | |
43 libraries = ['-l%s' % library for library in libraries] | |
44 result.extend(libraries) | 36 result.extend(libraries) |
45 if opts.includes: | 37 if opts.includes: |
46 result = result + b.include_dirs | 38 result = result + b.include_dirs |
47 if opts.library_dirs: | 39 if opts.library_dirs: |
48 if sys.platform == 'darwin': | 40 if sys.platform == 'darwin': |
49 result.append('%s/lib' % sysconfig.get_config_vars('prefix')[0]) | 41 result.append('%s/lib' % sysconfig.get_config_vars('prefix')[0]) |
50 | 42 |
51 if opts.gn: | 43 for x in result: |
52 for x in result: | 44 print x |
53 print x | |
54 else: | |
55 print ''.join(['"%s"' % x for x in result]) | |
56 | 45 |
57 if __name__ == '__main__': | 46 if __name__ == '__main__': |
58 main() | 47 main() |
OLD | NEW |