| OLD | NEW |
| 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 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 json | 5 import json |
| 6 import os | 6 import os |
| 7 import subprocess | 7 import subprocess |
| 8 import sys | 8 import sys |
| 9 import re | 9 import re |
| 10 from optparse import OptionParser | 10 from optparse import OptionParser |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 if os.path.isabs(path) and not path.startswith(sysroot): | 94 if os.path.isabs(path) and not path.startswith(sysroot): |
| 95 if path.startswith(strip_prefix): | 95 if path.startswith(strip_prefix): |
| 96 path = path[len(strip_prefix):] | 96 path = path[len(strip_prefix):] |
| 97 path = path.lstrip('/') | 97 path = path.lstrip('/') |
| 98 return os.path.join(sysroot, path) | 98 return os.path.join(sysroot, path) |
| 99 else: | 99 else: |
| 100 return path | 100 return path |
| 101 | 101 |
| 102 | 102 |
| 103 parser = OptionParser() | 103 parser = OptionParser() |
| 104 parser.add_option('-p', action='store', dest='pkg_config', type='string', |
| 105 default='pkg-config') |
| 104 parser.add_option('-v', action='append', dest='strip_out', type='string') | 106 parser.add_option('-v', action='append', dest='strip_out', type='string') |
| 105 parser.add_option('-s', action='store', dest='sysroot', type='string') | 107 parser.add_option('-s', action='store', dest='sysroot', type='string') |
| 106 parser.add_option('-a', action='store', dest='arch', type='string') | 108 parser.add_option('-a', action='store', dest='arch', type='string') |
| 107 (options, args) = parser.parse_args() | 109 (options, args) = parser.parse_args() |
| 108 | 110 |
| 109 # Make a list of regular expressions to strip out. | 111 # Make a list of regular expressions to strip out. |
| 110 strip_out = [] | 112 strip_out = [] |
| 111 if options.strip_out != None: | 113 if options.strip_out != None: |
| 112 for regexp in options.strip_out: | 114 for regexp in options.strip_out: |
| 113 strip_out.append(re.compile(regexp)) | 115 strip_out.append(re.compile(regexp)) |
| 114 | 116 |
| 115 SetConfigPath(options) | 117 SetConfigPath(options) |
| 116 if options.sysroot: | 118 if options.sysroot: |
| 117 prefix = GetPkgConfigPrefixToStrip(args) | 119 prefix = GetPkgConfigPrefixToStrip(args) |
| 118 else: | 120 else: |
| 119 prefix = '' | 121 prefix = '' |
| 120 | 122 |
| 121 try: | 123 try: |
| 122 flag_string = subprocess.check_output( | 124 flag_string = subprocess.check_output( |
| 123 [ "pkg-config", "--cflags", "--libs-only-l", "--libs-only-L" ] + | 125 [ options.pkg_config, "--cflags", "--libs-only-l", "--libs-only-L" ] + |
| 124 args, env=os.environ) | 126 args, env=os.environ) |
| 125 # For now just split on spaces to get the args out. This will break if | 127 # For now just split on spaces to get the args out. This will break if |
| 126 # pkgconfig returns quoted things with spaces in them, but that doesn't seem | 128 # pkgconfig returns quoted things with spaces in them, but that doesn't seem |
| 127 # to happen in practice. | 129 # to happen in practice. |
| 128 all_flags = flag_string.strip().split(' ') | 130 all_flags = flag_string.strip().split(' ') |
| 129 except: | 131 except: |
| 130 print "Could not run pkg-config." | 132 print "Could not run pkg-config." |
| 131 sys.exit(1) | 133 sys.exit(1) |
| 132 | 134 |
| 133 | 135 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 158 # this anyway. Removing it here prevents a bunch of duplicate inclusions on | 160 # this anyway. Removing it here prevents a bunch of duplicate inclusions on |
| 159 # the command line. | 161 # the command line. |
| 160 pass | 162 pass |
| 161 else: | 163 else: |
| 162 cflags.append(flag) | 164 cflags.append(flag) |
| 163 | 165 |
| 164 # Output a GN array, the first one is the cflags, the second are the libs. The | 166 # Output a GN array, the first one is the cflags, the second are the libs. The |
| 165 # JSON formatter prints GN compatible lists when everything is a list of | 167 # JSON formatter prints GN compatible lists when everything is a list of |
| 166 # strings. | 168 # strings. |
| 167 print json.dumps([includes, cflags, libs, lib_dirs, ldflags]) | 169 print json.dumps([includes, cflags, libs, lib_dirs, ldflags]) |
| OLD | NEW |