Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: build/config/linux/pkg-config.py

Issue 1564503002: Plumb system_libdir variable from GN to pkg-config.py (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: improved the comments Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | build/config/linux/pkg_config.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 systemroots place pkgconfig files at <systemroot>/usr/share/pkgconfig
30 # and one of <systemroot>/usr/lib/pkgconfig or <systemroot>/usr/lib64/pkgconfig
31 # depending on whether the systemroot is for a 32 or 64 bit architecture. They
32 # specify the 'lib' or 'lib64' of the pkgconfig path by defining the
33 # 'system_libdir' variable in the args.gn file. pkg_config.gni communicates this
34 # variable to this script with the "--system_libdir <system_libdir>" flag. If no
35 # flag is provided, then pkgconfig files are assumed to come from
36 # <systemroot>/usr/lib/pkgconfig.
37 #
29 # Additionally, you can specify the option --atleast-version. This will skip 38 # Additionally, you can specify the option --atleast-version. This will skip
30 # the normal outputting of a dictionary and instead print true or false, 39 # 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. 40 # depending on the return value of pkg-config for the given package.
32 41
33 # If this is run on non-Linux platforms, just return nothing and indicate 42 # 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 43 # success. This allows us to "kind of emulate" a Linux build from other
35 # platforms. 44 # platforms.
36 if sys.platform.find("linux") == -1: 45 if sys.platform.find("linux") == -1:
37 print "[[],[],[],[],[]]" 46 print "[[],[],[],[],[]]"
38 sys.exit(0) 47 sys.exit(0)
39 48
40 49
41 def SetConfigPath(options): 50 def SetConfigPath(options):
42 """Set the PKG_CONFIG_PATH environment variable. 51 """Set the PKG_CONFIG_PATH environment variable.
43 This takes into account any sysroot and architecture specification from the 52 This takes into account any sysroot and architecture specification from the
44 options on the given command line.""" 53 options on the given command line."""
45 54
46 sysroot = options.sysroot 55 sysroot = options.sysroot
47 if not sysroot: 56 if not sysroot:
48 sysroot = "" 57 sysroot = ""
49 58
50 # Compute the library path name based on the architecture. 59 # Compute the library path name based on the architecture.
51 arch = options.arch 60 arch = options.arch
52 if sysroot and not arch: 61 if sysroot and not arch:
53 print "You must specify an architecture via -a if using a sysroot." 62 print "You must specify an architecture via -a if using a sysroot."
54 sys.exit(1) 63 sys.exit(1)
55 64
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 65 # Add the sysroot path to the environment's PKG_CONFIG_PATH
62 config_path = sysroot + '/usr/' + libpath + '/pkgconfig' 66 config_path = sysroot + '/usr/' + options.system_libdir + '/pkgconfig'
63 config_path += ':' + sysroot + '/usr/share/pkgconfig' 67 config_path += ':' + sysroot + '/usr/share/pkgconfig'
64 if 'PKG_CONFIG_PATH' in os.environ: 68 if 'PKG_CONFIG_PATH' in os.environ:
65 os.environ['PKG_CONFIG_PATH'] += ':' + config_path 69 os.environ['PKG_CONFIG_PATH'] += ':' + config_path
66 else: 70 else:
67 os.environ['PKG_CONFIG_PATH'] = config_path 71 os.environ['PKG_CONFIG_PATH'] = config_path
68 72
69 73
70 def GetPkgConfigPrefixToStrip(args): 74 def GetPkgConfigPrefixToStrip(args):
71 """Returns the prefix from pkg-config where packages are installed. 75 """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 76 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
104 else: 108 else:
105 return path 109 return path
106 110
107 111
108 parser = OptionParser() 112 parser = OptionParser()
109 parser.add_option('-p', action='store', dest='pkg_config', type='string', 113 parser.add_option('-p', action='store', dest='pkg_config', type='string',
110 default='pkg-config') 114 default='pkg-config')
111 parser.add_option('-v', action='append', dest='strip_out', type='string') 115 parser.add_option('-v', action='append', dest='strip_out', type='string')
112 parser.add_option('-s', action='store', dest='sysroot', type='string') 116 parser.add_option('-s', action='store', dest='sysroot', type='string')
113 parser.add_option('-a', action='store', dest='arch', type='string') 117 parser.add_option('-a', action='store', dest='arch', type='string')
118 parser.add_option('--system_libdir', action='store', dest='system_libdir',
119 type='string', default='lib')
114 parser.add_option('--atleast-version', action='store', 120 parser.add_option('--atleast-version', action='store',
115 dest='atleast_version', type='string') 121 dest='atleast_version', type='string')
116 parser.add_option('--libdir', action='store_true', dest='libdir') 122 parser.add_option('--libdir', action='store_true', dest='libdir')
117 (options, args) = parser.parse_args() 123 (options, args) = parser.parse_args()
118 124
119 # Make a list of regular expressions to strip out. 125 # Make a list of regular expressions to strip out.
120 strip_out = [] 126 strip_out = []
121 if options.strip_out != None: 127 if options.strip_out != None:
122 for regexp in options.strip_out: 128 for regexp in options.strip_out:
123 strip_out.append(re.compile(regexp)) 129 strip_out.append(re.compile(regexp))
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 # this anyway. Removing it here prevents a bunch of duplicate inclusions on 198 # this anyway. Removing it here prevents a bunch of duplicate inclusions on
193 # the command line. 199 # the command line.
194 pass 200 pass
195 else: 201 else:
196 cflags.append(flag) 202 cflags.append(flag)
197 203
198 # Output a GN array, the first one is the cflags, the second are the libs. The 204 # 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 205 # JSON formatter prints GN compatible lists when everything is a list of
200 # strings. 206 # strings.
201 print json.dumps([includes, cflags, libs, lib_dirs, ldflags]) 207 print json.dumps([includes, cflags, libs, lib_dirs, ldflags])
OLDNEW
« no previous file with comments | « no previous file | build/config/linux/pkg_config.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698