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

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

Issue 702903004: Add chrome perf tests and sniffer to GN build. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
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 #
29 # Additionally, you can specify the option --atleast-version. This will skip
30 # 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.
28 32
29 # If this is run on non-Linux platforms, just return nothing and indicate 33 # 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 34 # success. This allows us to "kind of emulate" a Linux build from other
31 # platforms. 35 # platforms.
32 if sys.platform.find("linux") == -1: 36 if sys.platform.find("linux") == -1:
33 print "[[],[],[],[],[]]" 37 print "[[],[],[],[],[]]"
34 sys.exit(0) 38 sys.exit(0)
35 39
36 40
37 def SetConfigPath(options): 41 def SetConfigPath(options):
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 else: 103 else:
100 return path 104 return path
101 105
102 106
103 parser = OptionParser() 107 parser = OptionParser()
104 parser.add_option('-p', action='store', dest='pkg_config', type='string', 108 parser.add_option('-p', action='store', dest='pkg_config', type='string',
105 default='pkg-config') 109 default='pkg-config')
106 parser.add_option('-v', action='append', dest='strip_out', type='string') 110 parser.add_option('-v', action='append', dest='strip_out', type='string')
107 parser.add_option('-s', action='store', dest='sysroot', type='string') 111 parser.add_option('-s', action='store', dest='sysroot', type='string')
108 parser.add_option('-a', action='store', dest='arch', type='string') 112 parser.add_option('-a', action='store', dest='arch', type='string')
113 parser.add_option('--atleast-version', action='store',
114 dest='atleast_version', type='string')
109 (options, args) = parser.parse_args() 115 (options, args) = parser.parse_args()
110 116
111 # Make a list of regular expressions to strip out. 117 # Make a list of regular expressions to strip out.
112 strip_out = [] 118 strip_out = []
113 if options.strip_out != None: 119 if options.strip_out != None:
114 for regexp in options.strip_out: 120 for regexp in options.strip_out:
115 strip_out.append(re.compile(regexp)) 121 strip_out.append(re.compile(regexp))
116 122
117 SetConfigPath(options) 123 SetConfigPath(options)
118 if options.sysroot: 124 if options.sysroot:
119 prefix = GetPkgConfigPrefixToStrip(args) 125 prefix = GetPkgConfigPrefixToStrip(args)
120 else: 126 else:
121 prefix = '' 127 prefix = ''
122 128
129 if options.atleast_version:
130 # When asking for the return value, just run pkg-config and print the return
131 # value, no need to do other work.
132 if not subprocess.call([options.pkg_config,
133 "--atleast-version=" + options.atleast_version] +
134 args,
135 env=os.environ):
136 print "true"
137 else:
138 print "false"
139 sys.exit(0)
140
123 try: 141 try:
124 flag_string = subprocess.check_output( 142 flag_string = subprocess.check_output(
125 [ options.pkg_config, "--cflags", "--libs-only-l", "--libs-only-L" ] + 143 [ options.pkg_config, "--cflags", "--libs-only-l", "--libs-only-L" ] +
126 args, env=os.environ) 144 args, env=os.environ)
127 # For now just split on spaces to get the args out. This will break if 145 # For now just split on spaces to get the args out. This will break if
128 # pkgconfig returns quoted things with spaces in them, but that doesn't seem 146 # pkgconfig returns quoted things with spaces in them, but that doesn't seem
129 # to happen in practice. 147 # to happen in practice.
130 all_flags = flag_string.strip().split(' ') 148 all_flags = flag_string.strip().split(' ')
131 except: 149 except:
132 print "Could not run pkg-config." 150 print "Could not run pkg-config."
(...skipping 27 matching lines...) Expand all
160 # this anyway. Removing it here prevents a bunch of duplicate inclusions on 178 # this anyway. Removing it here prevents a bunch of duplicate inclusions on
161 # the command line. 179 # the command line.
162 pass 180 pass
163 else: 181 else:
164 cflags.append(flag) 182 cflags.append(flag)
165 183
166 # Output a GN array, the first one is the cflags, the second are the libs. The 184 # Output a GN array, the first one is the cflags, the second are the libs. The
167 # JSON formatter prints GN compatible lists when everything is a list of 185 # JSON formatter prints GN compatible lists when everything is a list of
168 # strings. 186 # strings.
169 print json.dumps([includes, cflags, libs, lib_dirs, ldflags]) 187 print json.dumps([includes, cflags, libs, lib_dirs, ldflags])
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | build/config/linux/pkg_config.gni » ('j') | third_party/harfbuzz-ng/BUILD.gn » ('J')

Powered by Google App Engine
This is Rietveld 408576698