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

Unified 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, 3 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/secondary/build/config/linux/pkg-config.py
diff --git a/tools/gn/secondary/build/config/linux/pkg-config.py b/tools/gn/secondary/build/config/linux/pkg-config.py
index 1cee44883e14bef69851610cdabf3e25d3efbd4d..f1789c81ad0f1a0ebc8eb7d751a2fccbdf40ab88 100644
--- a/tools/gn/secondary/build/config/linux/pkg-config.py
+++ b/tools/gn/secondary/build/config/linux/pkg-config.py
@@ -4,5 +4,70 @@
import subprocess
import sys
+import re
+from optparse import OptionParser
-sys.exit(subprocess.call(["pkg-config"] + sys.argv[1:]))
+# This script runs pkg-config, optionally filtering out some results, and
+# returns the result.
+#
+# The result will be [ <cflags>, <ldflags> ] where both cflags and ldflags are
+# lists of strings.
+#
+# You can filter out matches using "-v <regexp>" where all results from
+# pkgconfig matching the given regular expression will be ignored. You can
+# specify more than one regular expression my specifying "-v" more than once.
+
+# If this is run on non-Linux platforms, just return nothing and indicate
+# success. This allows us to "kind of emulate" a Linux build from other
+# platforms.
+if sys.platform.find("linux") == -1:
+ print "[[],[]]"
+ sys.exit(0)
+
+parser = OptionParser()
+parser.add_option('-v', action='append', dest='strip_out', type='string')
+(options, args) = parser.parse_args()
+
+# Make a list of regular expressions to strip out.
+strip_out = []
+if options.strip_out != None:
+ for regexp in options.strip_out:
+ strip_out.append(re.compile(regexp))
+
+try:
+ flag_string = subprocess.check_output(["pkg-config", "--cflags", "--libs"] +
+ args)
+ # For now just split on spaces to get the args out. This will break if
+ # pkgconfig returns quoted things with spaces in them, but that doesn't seem
+ # to happen in practice.
+ all_flags = flag_string.strip().split(' ')
+except:
+ print "Could not run pkg-config."
+ sys.exit(1)
+
+cflags = []
+libs = []
+
+def MatchesAnyRegexp(flag, list_of_regexps):
+ for regexp in list_of_regexps:
+ if regexp.search(flag) != None:
+ return True
+ return False
+
+for flag in all_flags[:]:
+ if len(flag) == 0 or MatchesAnyRegexp(flag, strip_out):
+ continue;
+
+ if flag[:2] == '-l':
+ libs.append(flag)
+ else:
+ cflags.append(flag)
+
+# 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
+print '[['
+for cflag in cflags:
+ print '"' + cflag + '",'
+print '],['
+for lib in libs:
+ print '"' + lib + '",'
+print ']]'
« 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