Chromium Code Reviews| 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> ] where each | 15 # The result will be [ <includes>, <cflags>, <libs>, <lib_dirs>, <ldflags> ] |
| 16 # 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 # If this is run on non-Linux platforms, just return nothing and indicate | 29 # If this is run on non-Linux platforms, just return nothing and indicate |
| 30 # success. This allows us to "kind of emulate" a Linux build from other | 30 # success. This allows us to "kind of emulate" a Linux build from other |
| 31 # platforms. | 31 # platforms. |
| 32 if sys.platform.find("linux") == -1: | 32 if sys.platform.find("linux") == -1: |
| 33 print "[[],[],[],[]]" | 33 print "[[],[],[],[]]" |
|
Nico
2014/02/19 05:09:10
I guess this should now read "[[],[],[],[],[]]"?
Nico
2014/02/19 05:18:23
=> https://codereview.chromium.org/171993002/
| |
| 34 sys.exit(0) | 34 sys.exit(0) |
| 35 | 35 |
| 36 | 36 |
| 37 def SetConfigPath(options): | 37 def SetConfigPath(options): |
| 38 """Set the PKG_CONFIG_PATH environment variable. | 38 """Set the PKG_CONFIG_PATH environment variable. |
| 39 This takes into account any sysroot and architecture specification from the | 39 This takes into account any sysroot and architecture specification from the |
| 40 options on the given command line.""" | 40 options on the given command line.""" |
| 41 | 41 |
| 42 sysroot = options.sysroot | 42 sysroot = options.sysroot |
| 43 if not sysroot: | 43 if not sysroot: |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 | 131 |
| 132 | 132 |
| 133 sysroot = options.sysroot | 133 sysroot = options.sysroot |
| 134 if not sysroot: | 134 if not sysroot: |
| 135 sysroot = '' | 135 sysroot = '' |
| 136 | 136 |
| 137 includes = [] | 137 includes = [] |
| 138 cflags = [] | 138 cflags = [] |
| 139 libs = [] | 139 libs = [] |
| 140 lib_dirs = [] | 140 lib_dirs = [] |
| 141 ldflags = [] | |
| 141 | 142 |
| 142 for flag in all_flags[:]: | 143 for flag in all_flags[:]: |
| 143 if len(flag) == 0 or MatchesAnyRegexp(flag, strip_out): | 144 if len(flag) == 0 or MatchesAnyRegexp(flag, strip_out): |
| 144 continue; | 145 continue; |
| 145 | 146 |
| 146 if flag[:2] == '-l': | 147 if flag[:2] == '-l': |
| 147 libs.append(RewritePath(flag[2:], prefix, sysroot)) | 148 libs.append(RewritePath(flag[2:], prefix, sysroot)) |
| 148 if flag[:2] == '-L': | 149 elif flag[:2] == '-L': |
| 149 lib_dirs.append(RewritePath(flag[2:], prefix, sysroot)) | 150 lib_dirs.append(RewritePath(flag[2:], prefix, sysroot)) |
| 150 elif flag[:2] == '-I': | 151 elif flag[:2] == '-I': |
| 151 includes.append(RewritePath(flag[2:], prefix, sysroot)) | 152 includes.append(RewritePath(flag[2:], prefix, sysroot)) |
| 153 elif flag[:3] == '-Wl': | |
| 154 ldflags.append(flag) | |
| 155 elif flag == '-pthread': | |
| 156 # Many libs specify "-pthread" which we don't need since we always include | |
| 157 # this anyway. Removing it here prevents a bunch of duplicate inclusions on | |
| 158 # the command line. | |
| 159 pass | |
| 152 else: | 160 else: |
| 153 cflags.append(flag) | 161 cflags.append(flag) |
| 154 | 162 |
| 155 # Output a GN array, the first one is the cflags, the second are the libs. The | 163 # Output a GN array, the first one is the cflags, the second are the libs. The |
| 156 # JSON formatter prints GN compatible lists when everything is a list of | 164 # JSON formatter prints GN compatible lists when everything is a list of |
| 157 # strings. | 165 # strings. |
| 158 print json.dumps([includes, cflags, libs, lib_dirs]) | 166 print json.dumps([includes, cflags, libs, lib_dirs, ldflags]) |
| OLD | NEW |