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 |
11 | 11 |
12 # This script runs pkg-config, optionally filtering out some results, and | 12 # This script runs pkg-config, optionally filtering out some results, and |
13 # returns the result. | 13 # returns the result. |
14 # | 14 # |
15 # The result will be [ <includes>, <cflags>, <libs>, <lib_dirs>, <ldflags> ] | 15 # The result will be [ <includes>, <cflags>, <libs>, <lib_dirs>, <ldflags> ] |
16 # where each member is itself a list of strings. | 16 # where each member is itself a list of strings. |
17 # | 17 # |
18 # You can filter out matches using "-v <regexp>" where all results from | 18 # You can filter out matches using "-v <regexp>" where all results from |
19 # pkgconfig matching the given regular expression will be ignored. You can | 19 # pkgconfig matching the given regular expression will be ignored. You can |
20 # specify more than one regular expression my specifying "-v" more than once. | 20 # specify more than one regular expression my specifying "-v" more than once. |
21 # | 21 # |
22 # You can specify a sysroot using "-s <sysroot>" where sysroot is the absolute | 22 # You can specify a sysroot using "-s <sysroot>" where sysroot is the absolute |
23 # system path to the sysroot used for compiling. This script will attempt to | 23 # system path to the sysroot used for compiling. This script will attempt to |
24 # generate correct paths for the sysroot. | 24 # generate correct paths for the sysroot. |
25 # | 25 # |
26 # When using a sysroot, you must also specify the architecture via | 26 # When using a sysroot, you must also specify the architecture via |
27 # "-a <arch>" where arch is either "x86" or "x64". | 27 # "-a <arch>" where arch is either "x86" or "x64". |
28 # | 28 # |
| 29 # CrOS builds set the system_libdir. This is specified with |
| 30 # "--system_libdir <libdir>". It defaults to 'lib' |
| 31 # |
29 # Additionally, you can specify the option --atleast-version. This will skip | 32 # Additionally, you can specify the option --atleast-version. This will skip |
30 # the normal outputting of a dictionary and instead print true or false, | 33 # the normal outputting of a dictionary and instead print true or false, |
31 # depending on the return value of pkg-config for the given package. | 34 # depending on the return value of pkg-config for the given package. |
32 | 35 |
33 # If this is run on non-Linux platforms, just return nothing and indicate | 36 # If this is run on non-Linux platforms, just return nothing and indicate |
34 # success. This allows us to "kind of emulate" a Linux build from other | 37 # success. This allows us to "kind of emulate" a Linux build from other |
35 # platforms. | 38 # platforms. |
36 if sys.platform.find("linux") == -1: | 39 if sys.platform.find("linux") == -1: |
37 print "[[],[],[],[],[]]" | 40 print "[[],[],[],[],[]]" |
38 sys.exit(0) | 41 sys.exit(0) |
39 | 42 |
40 | 43 |
41 def SetConfigPath(options): | 44 def SetConfigPath(options): |
42 """Set the PKG_CONFIG_PATH environment variable. | 45 """Set the PKG_CONFIG_PATH environment variable. |
43 This takes into account any sysroot and architecture specification from the | 46 This takes into account any sysroot and architecture specification from the |
44 options on the given command line.""" | 47 options on the given command line.""" |
45 | 48 |
46 sysroot = options.sysroot | 49 sysroot = options.sysroot |
47 if not sysroot: | 50 if not sysroot: |
48 sysroot = "" | 51 sysroot = "" |
49 | 52 |
50 # Compute the library path name based on the architecture. | 53 # Compute the library path name based on the architecture. |
51 arch = options.arch | 54 arch = options.arch |
52 if sysroot and not arch: | 55 if sysroot and not arch: |
53 print "You must specify an architecture via -a if using a sysroot." | 56 print "You must specify an architecture via -a if using a sysroot." |
54 sys.exit(1) | 57 sys.exit(1) |
55 | 58 |
56 # In the gyp world this is configurable via the 'system_libdir' variable, | |
57 # which doesn't seem to have an equivelent in gn yet. | |
58 # TOOD(sbc): Make this configurable like it is under gyp. | |
59 libpath = 'lib' | |
60 | |
61 # Add the sysroot path to the environment's PKG_CONFIG_PATH | 59 # Add the sysroot path to the environment's PKG_CONFIG_PATH |
62 config_path = sysroot + '/usr/' + libpath + '/pkgconfig' | 60 config_path = sysroot + '/usr/' + options.system_libdir + '/pkgconfig' |
63 config_path += ':' + sysroot + '/usr/share/pkgconfig' | 61 config_path += ':' + sysroot + '/usr/share/pkgconfig' |
64 if 'PKG_CONFIG_PATH' in os.environ: | 62 if 'PKG_CONFIG_PATH' in os.environ: |
65 os.environ['PKG_CONFIG_PATH'] += ':' + config_path | 63 os.environ['PKG_CONFIG_PATH'] += ':' + config_path |
66 else: | 64 else: |
67 os.environ['PKG_CONFIG_PATH'] = config_path | 65 os.environ['PKG_CONFIG_PATH'] = config_path |
68 | 66 |
69 | 67 |
70 def GetPkgConfigPrefixToStrip(args): | 68 def GetPkgConfigPrefixToStrip(args): |
71 """Returns the prefix from pkg-config where packages are installed. | 69 """Returns the prefix from pkg-config where packages are installed. |
72 This returned prefix is the one that should be stripped from the beginning of | 70 This returned prefix is the one that should be stripped from the beginning of |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 else: | 102 else: |
105 return path | 103 return path |
106 | 104 |
107 | 105 |
108 parser = OptionParser() | 106 parser = OptionParser() |
109 parser.add_option('-p', action='store', dest='pkg_config', type='string', | 107 parser.add_option('-p', action='store', dest='pkg_config', type='string', |
110 default='pkg-config') | 108 default='pkg-config') |
111 parser.add_option('-v', action='append', dest='strip_out', type='string') | 109 parser.add_option('-v', action='append', dest='strip_out', type='string') |
112 parser.add_option('-s', action='store', dest='sysroot', type='string') | 110 parser.add_option('-s', action='store', dest='sysroot', type='string') |
113 parser.add_option('-a', action='store', dest='arch', type='string') | 111 parser.add_option('-a', action='store', dest='arch', type='string') |
| 112 parser.add_option('--system_libdir', action='store', dest='system_libdir', |
| 113 type='string', default='lib') |
114 parser.add_option('--atleast-version', action='store', | 114 parser.add_option('--atleast-version', action='store', |
115 dest='atleast_version', type='string') | 115 dest='atleast_version', type='string') |
116 parser.add_option('--libdir', action='store_true', dest='libdir') | 116 parser.add_option('--libdir', action='store_true', dest='libdir') |
117 (options, args) = parser.parse_args() | 117 (options, args) = parser.parse_args() |
118 | 118 |
119 # Make a list of regular expressions to strip out. | 119 # Make a list of regular expressions to strip out. |
120 strip_out = [] | 120 strip_out = [] |
121 if options.strip_out != None: | 121 if options.strip_out != None: |
122 for regexp in options.strip_out: | 122 for regexp in options.strip_out: |
123 strip_out.append(re.compile(regexp)) | 123 strip_out.append(re.compile(regexp)) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 # this anyway. Removing it here prevents a bunch of duplicate inclusions on | 192 # this anyway. Removing it here prevents a bunch of duplicate inclusions on |
193 # the command line. | 193 # the command line. |
194 pass | 194 pass |
195 else: | 195 else: |
196 cflags.append(flag) | 196 cflags.append(flag) |
197 | 197 |
198 # Output a GN array, the first one is the cflags, the second are the libs. The | 198 # Output a GN array, the first one is the cflags, the second are the libs. The |
199 # JSON formatter prints GN compatible lists when everything is a list of | 199 # JSON formatter prints GN compatible lists when everything is a list of |
200 # strings. | 200 # strings. |
201 print json.dumps([includes, cflags, libs, lib_dirs, ldflags]) | 201 print json.dumps([includes, cflags, libs, lib_dirs, ldflags]) |
OLD | NEW |