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

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

Issue 24657003: GN: Return array from pkgconfig wrapper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
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 subprocess 5 import subprocess
6 import sys 6 import sys
7 import re
8 from optparse import OptionParser
7 9
8 sys.exit(subprocess.call(["pkg-config"] + sys.argv[1:])) 10 # This script runs pkg-config, optionally filtering out some results, and
11 # returns the result.
12 #
13 # The result will be [ <cflags>, <ldflags> ] where both cflags and ldflags are
14 # lists of strings.
15 #
16 # You can filter out matches using "-v <regexp>" where all results from
17 # pkgconfig matching the given regular expression will be ignored. You can
18 # specify more than one regular expression my specifying "-v" more than once.
19
20 # If this is run on non-Linux platforms, just return nothing and indicate
21 # success. This allows us to "kind of emulate" a Linux build from other
22 # platforms.
23 if sys.platform.find("linux") == -1:
24 print "[[],[]]"
25 sys.exit(0)
26
27 parser = OptionParser()
28 parser.add_option('-v', action='append', dest='strip_out', type='string')
29 (options, args) = parser.parse_args()
30
31 # Make a list of regular expressions to strip out.
32 strip_out = []
33 if options.strip_out != None:
34 for regexp in options.strip_out:
35 strip_out.append(re.compile(regexp))
36
37 try:
38 flag_string = subprocess.check_output(["pkg-config", "--cflags", "--libs"] +
39 args)
40 # For now just split on spaces to get the args out. This will break if
41 # pkgconfig returns quoted things with spaces in them, but that doesn't seem
42 # to happen in practice.
43 all_flags = flag_string.strip().split(' ')
44 except:
45 print "Could not run pkg-config."
46 sys.exit(1)
47
48 cflags = []
49 libs = []
50
51 def MatchesAnyRegexp(flag, list_of_regexps):
52 for regexp in list_of_regexps:
53 if regexp.search(flag) != None:
54 return True
55 return False
56
57 for flag in all_flags[:]:
58 if len(flag) == 0 or MatchesAnyRegexp(flag, strip_out):
59 continue;
60
61 if flag[:2] == '-l':
62 libs.append(flag)
63 else:
64 cflags.append(flag)
65
66 # Output a GN array, the first one is the cflags, the second are the libs.
scottmg 2013/09/25 21:47:41 import json print json.dumps([cflags, libs]) (or
67 print '[['
68 for cflag in cflags:
69 print '"' + cflag + '",'
70 print '],['
71 for lib in libs:
72 print '"' + lib + '",'
73 print ']]'
OLDNEW
« no previous file with comments | « tools/gn/secondary/build/config/linux/BUILD.gn ('k') | tools/gn/secondary/third_party/nss/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698