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

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

Powered by Google App Engine
This is Rietveld 408576698