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

Unified Diff: printing/cups_config_helper.py

Issue 7633022: cups: parse cups-config output to reduce flags spew (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 9 years, 4 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 | « no previous file | printing/printing.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: printing/cups_config_helper.py
diff --git a/printing/cups_config_helper.py b/printing/cups_config_helper.py
new file mode 100755
index 0000000000000000000000000000000000000000..e9ecbb5a8cf3032542552ca48fa7f7a383a83f98
--- /dev/null
+++ b/printing/cups_config_helper.py
@@ -0,0 +1,54 @@
+#!/usr/bin/python
+# Copyright (c) 2011 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""cups-config wrapper.
+
+cups-config, at least on Ubuntu Lucid and Natty, dumps all
+cflags/ldflags/libs when passed the --libs argument. gyp would like
+to keep these separate: cflags are only needed when compiling files
+that use cups directly, while libs are only needed on the final link
+line.
+"""
+
+import subprocess
+import sys
+
+def usage():
+ print 'usage: %s {--cflags|--ldflags|--libs}' % sys.argv[0]
+ sys.exit(1)
+
+def run_cups_config(mode):
+ """Run cups-config with all --cflags etc modes, parse out the mode we want,
+ and return those flags as a list."""
+
+ cups = subprocess.Popen(['cups-config', '--cflags', '--ldflags', '--libs'],
+ stdout=subprocess.PIPE)
+ flags = cups.communicate()[0].strip()
+
+ flags_subset = []
+ for flag in flags.split(' '):
+ flag_mode = None
+ if flag.startswith('-l'):
+ flag_mode = '--libs'
+ elif (flag.startswith('-L') or flag.startswith('-Wl,')):
+ flag_mode = '--ldflags'
+ elif (flag.startswith('-I') or flag.startswith('-D')):
+ flag_mode = '--cflags'
+
+ # Be conservative: for flags where we don't know which mode they
+ # belong in, always include them.
+ if flag_mode is None or flag_mode == mode:
+ flags_subset.append(flag)
+
+ return flags_subset
+
+if len(sys.argv) != 2:
+ usage()
+
+mode = sys.argv[1]
+if mode not in ('--cflags', '--libs', '--ldflags'):
+ usage()
+flags = run_cups_config(mode)
+print ' '.join(flags)
« no previous file with comments | « no previous file | printing/printing.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698