[M120 Migration][VD] Remove accessing oom_score_adj in zygote process
[platform/framework/web/chromium-efl.git] / printing / cups_config_helper.py
1 #!/usr/bin/env python
2 # Copyright 2011 The Chromium Authors
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """cups-config wrapper.
7
8 cups-config, at least on Ubuntu Lucid and Natty, dumps all
9 cflags/ldflags/libs when passed the --libs argument.  gyp would like
10 to keep these separate: cflags are only needed when compiling files
11 that use cups directly, while libs are only needed on the final link
12 line.
13
14 This can be dramatically simplified or maybe removed (depending on GN
15 requirements) when this is fixed:
16   https://bugs.launchpad.net/ubuntu/+source/cupsys/+bug/163704
17 is fixed.
18 """
19
20 from __future__ import print_function
21
22 import os
23 import subprocess
24 import sys
25
26 def usage():
27   print('usage: %s {--api-version|--cflags|--ldflags|--libs|--libs-for-gn} '
28         '[sysroot]' % sys.argv[0])
29
30
31 def run_cups_config(cups_config, mode):
32   """Run cups-config with all --cflags etc modes, parse out the mode we want,
33   and return those flags as a list."""
34
35   cups = subprocess.Popen([cups_config, '--cflags', '--ldflags', '--libs'],
36                           stdout=subprocess.PIPE, universal_newlines=True)
37   flags = cups.communicate()[0].strip()
38
39   flags_subset = []
40   for flag in flags.split():
41     flag_mode = None
42     if flag.startswith('-l'):
43       flag_mode = '--libs'
44     elif (flag.startswith('-L') or flag.startswith('-Wl,')):
45       flag_mode = '--ldflags'
46     elif (flag.startswith('-I') or flag.startswith('-D')):
47       flag_mode = '--cflags'
48
49     # Be conservative: for flags where we don't know which mode they
50     # belong in, always include them.
51     if flag_mode is None or flag_mode == mode:
52       flags_subset.append(flag)
53
54   # Note: cross build is confused by the option, and may trigger linker
55   # warning causing build error.
56   if '-lgnutls' in flags_subset:
57     flags_subset.remove('-lgnutls')
58
59   return flags_subset
60
61
62 def main():
63   if len(sys.argv) < 2:
64     usage()
65     return 1
66
67   mode = sys.argv[1]
68   if len(sys.argv) > 2 and sys.argv[2]:
69     sysroot = sys.argv[2]
70     cups_config = os.path.join(sysroot, 'usr', 'bin', 'cups-config')
71     if not os.path.exists(cups_config):
72       print('cups-config not found: %s' % cups_config)
73       return 1
74   else:
75     cups_config = 'cups-config'
76
77   if mode == '--api-version':
78     subprocess.call([cups_config, '--api-version'])
79     return 0
80
81   # All other modes get the flags.
82   if mode not in ('--cflags', '--libs', '--libs-for-gn', '--ldflags'):
83     usage()
84     return 1
85
86   if mode == '--libs-for-gn':
87     gn_libs_output = True
88     mode = '--libs'
89   else:
90     gn_libs_output = False
91
92   flags = run_cups_config(cups_config, mode)
93
94   if gn_libs_output:
95     # Strip "-l" from beginning of libs, quote, and surround in [ ].
96     print('[')
97     for lib in flags:
98       if lib[:2] == "-l":
99         print('"%s", ' % lib[2:])
100     print(']')
101   else:
102     print(' '.join(flags))
103
104   return 0
105
106
107 if __name__ == '__main__':
108   sys.exit(main())