~yolanda.robla/ubuntu/trusty/nodejs/add_distribution

« back to all changes in this revision

Viewing changes to tools/wafadmin/Options.py

  • Committer: Package Import Robot
  • Author(s): Jérémy Lal
  • Date: 2013-08-14 00:16:46 UTC
  • mfrom: (7.1.40 sid)
  • Revision ID: package-import@ubuntu.com-20130814001646-bzlysfh8sd6mukbo
Tags: 0.10.15~dfsg1-4
* Update 2005 patch, adding a handful of tests that can fail on
  slow platforms.
* Add 1004 patch to fix test failures when writing NaN to buffer
  on mipsel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
# encoding: utf-8
3
 
# Scott Newton, 2005 (scottn)
4
 
# Thomas Nagy, 2006 (ita)
5
 
 
6
 
"Custom command-line options"
7
 
 
8
 
import os, sys, imp, types, tempfile, optparse
9
 
import Logs, Utils
10
 
from Constants import *
11
 
 
12
 
cmds = 'distclean configure build install clean uninstall check dist distcheck'.split()
13
 
 
14
 
# TODO remove in waf 1.6 the following two
15
 
commands = {}
16
 
is_install = False
17
 
 
18
 
options = {}
19
 
arg_line = []
20
 
launch_dir = ''
21
 
tooldir = ''
22
 
lockfile = os.environ.get('WAFLOCK', '.lock-wscript')
23
 
try: cache_global = os.path.abspath(os.environ['WAFCACHE'])
24
 
except KeyError: cache_global = ''
25
 
platform = Utils.unversioned_sys_platform()
26
 
conf_file = 'conf-runs-%s-%d.pickle' % (platform, ABI)
27
 
 
28
 
remote_repo = ['http://waf.googlecode.com/svn/']
29
 
"""remote directory for the plugins"""
30
 
 
31
 
 
32
 
# Such a command-line should work:  JOBS=4 PREFIX=/opt/ DESTDIR=/tmp/ahoj/ waf configure
33
 
default_prefix = os.environ.get('PREFIX')
34
 
if not default_prefix:
35
 
        if platform == 'win32': default_prefix = tempfile.gettempdir()
36
 
        else: default_prefix = '/usr/local/'
37
 
 
38
 
default_jobs = os.environ.get('JOBS', -1)
39
 
if default_jobs < 1:
40
 
        try:
41
 
                if 'SC_NPROCESSORS_ONLN' in os.sysconf_names:
42
 
                        default_jobs = os.sysconf('SC_NPROCESSORS_ONLN')
43
 
                else:
44
 
                        default_jobs = int(Utils.cmd_output(['sysctl', '-n', 'hw.ncpu']))
45
 
        except:
46
 
                if os.name == 'java': # platform.system() == 'Java'
47
 
                        from java.lang import Runtime
48
 
                        default_jobs = Runtime.getRuntime().availableProcessors()
49
 
                else:
50
 
                        # environment var defined on win32
51
 
                        default_jobs = int(os.environ.get('NUMBER_OF_PROCESSORS', 1))
52
 
 
53
 
default_destdir = os.environ.get('DESTDIR', '')
54
 
 
55
 
def get_usage(self):
56
 
        cmds_str = []
57
 
        module = Utils.g_module
58
 
        if module:
59
 
                # create the help messages for commands
60
 
                tbl = module.__dict__
61
 
                keys = list(tbl.keys())
62
 
                keys.sort()
63
 
 
64
 
                if 'build' in tbl:
65
 
                        if not module.build.__doc__:
66
 
                                module.build.__doc__ = 'builds the project'
67
 
                if 'configure' in tbl:
68
 
                        if not module.configure.__doc__:
69
 
                                module.configure.__doc__ = 'configures the project'
70
 
 
71
 
                ban = ['set_options', 'init', 'shutdown']
72
 
 
73
 
                optlst = [x for x in keys if not x in ban
74
 
                        and type(tbl[x]) is type(parse_args_impl)
75
 
                        and tbl[x].__doc__
76
 
                        and not x.startswith('_')]
77
 
 
78
 
                just = max([len(x) for x in optlst])
79
 
 
80
 
                for x in optlst:
81
 
                        cmds_str.append('  %s: %s' % (x.ljust(just), tbl[x].__doc__))
82
 
                ret = '\n'.join(cmds_str)
83
 
        else:
84
 
                ret = ' '.join(cmds)
85
 
        return '''waf [command] [options]
86
 
 
87
 
Main commands (example: ./waf build -j4)
88
 
%s
89
 
''' % ret
90
 
 
91
 
 
92
 
setattr(optparse.OptionParser, 'get_usage', get_usage)
93
 
 
94
 
def create_parser(module=None):
95
 
        Logs.debug('options: create_parser is called')
96
 
        parser = optparse.OptionParser(conflict_handler="resolve", version = 'waf %s (%s)' % (WAFVERSION, WAFREVISION))
97
 
 
98
 
        parser.formatter.width = Utils.get_term_cols()
99
 
        p = parser.add_option
100
 
 
101
 
        p('-j', '--jobs',
102
 
                type    = 'int',
103
 
                default = default_jobs,
104
 
                help    = 'amount of parallel jobs (%r)' % default_jobs,
105
 
                dest    = 'jobs')
106
 
 
107
 
        p('-k', '--keep',
108
 
                action  = 'store_true',
109
 
                default = False,
110
 
                help    = 'keep running happily on independent task groups',
111
 
                dest    = 'keep')
112
 
 
113
 
        p('-v', '--verbose',
114
 
                action  = 'count',
115
 
                default = 0,
116
 
                help    = 'verbosity level -v -vv or -vvv [default: 0]',
117
 
                dest    = 'verbose')
118
 
 
119
 
        p('--nocache',
120
 
                action  = 'store_true',
121
 
                default = False,
122
 
                help    = 'ignore the WAFCACHE (if set)',
123
 
                dest    = 'nocache')
124
 
 
125
 
        p('--zones',
126
 
                action  = 'store',
127
 
                default = '',
128
 
                help    = 'debugging zones (task_gen, deps, tasks, etc)',
129
 
                dest    = 'zones')
130
 
 
131
 
        p('-p', '--progress',
132
 
                action  = 'count',
133
 
                default = 0,
134
 
                help    = '-p: progress bar; -pp: ide output',
135
 
                dest    = 'progress_bar')
136
 
 
137
 
        p('--targets',
138
 
                action  = 'store',
139
 
                default = '',
140
 
                help    = 'build given task generators, e.g. "target1,target2"',
141
 
                dest    = 'compile_targets')
142
 
 
143
 
        gr = optparse.OptionGroup(parser, 'configuration options')
144
 
        parser.add_option_group(gr)
145
 
        gr.add_option('-b', '--blddir',
146
 
                action  = 'store',
147
 
                default = '',
148
 
                help    = 'build dir for the project (configuration)',
149
 
                dest    = 'blddir')
150
 
        gr.add_option('-s', '--srcdir',
151
 
                action  = 'store',
152
 
                default = '',
153
 
                help    = 'src dir for the project (configuration)',
154
 
                dest    = 'srcdir')
155
 
        gr.add_option('--prefix',
156
 
                help    = 'installation prefix (configuration) [default: %r]' % default_prefix,
157
 
                default = default_prefix,
158
 
                dest    = 'prefix')
159
 
 
160
 
        gr = optparse.OptionGroup(parser, 'installation options')
161
 
        parser.add_option_group(gr)
162
 
        gr.add_option('--destdir',
163
 
                help    = 'installation root [default: %r]' % default_destdir,
164
 
                default = default_destdir,
165
 
                dest    = 'destdir')
166
 
        gr.add_option('-f', '--force',
167
 
                action  = 'store_true',
168
 
                default = False,
169
 
                help    = 'force file installation',
170
 
                dest    = 'force')
171
 
 
172
 
        return parser
173
 
 
174
 
def parse_args_impl(parser, _args=None):
175
 
        global options, commands, arg_line
176
 
        (options, args) = parser.parse_args(args=_args)
177
 
 
178
 
        arg_line = args
179
 
        #arg_line = args[:] # copy
180
 
 
181
 
        # By default, 'waf' is equivalent to 'waf build'
182
 
        commands = {}
183
 
        for var in cmds: commands[var] = 0
184
 
        if not args:
185
 
                commands['build'] = 1
186
 
                args.append('build')
187
 
 
188
 
        # Parse the command arguments
189
 
        for arg in args:
190
 
                commands[arg] = True
191
 
 
192
 
        # the check thing depends on the build
193
 
        if 'check' in args:
194
 
                idx = args.index('check')
195
 
                try:
196
 
                        bidx = args.index('build')
197
 
                        if bidx > idx:
198
 
                                raise ValueError('build before check')
199
 
                except ValueError, e:
200
 
                        args.insert(idx, 'build')
201
 
 
202
 
        if args[0] != 'init':
203
 
                args.insert(0, 'init')
204
 
 
205
 
        # TODO -k => -j0
206
 
        if options.keep: options.jobs = 1
207
 
        if options.jobs < 1: options.jobs = 1
208
 
 
209
 
        if 'install' in sys.argv or 'uninstall' in sys.argv:
210
 
                # absolute path only if set
211
 
                options.destdir = options.destdir and os.path.abspath(os.path.expanduser(options.destdir))
212
 
 
213
 
        Logs.verbose = options.verbose
214
 
        Logs.init_log()
215
 
 
216
 
        if options.zones:
217
 
                Logs.zones = options.zones.split(',')
218
 
                if not Logs.verbose: Logs.verbose = 1
219
 
        elif Logs.verbose > 0:
220
 
                Logs.zones = ['runner']
221
 
        if Logs.verbose > 2:
222
 
                Logs.zones = ['*']
223
 
 
224
 
# TODO waf 1.6
225
 
# 1. rename the class to OptionsContext
226
 
# 2. instead of a class attribute, use a module (static 'parser')
227
 
# 3. parse_args_impl was made in times when we did not know about binding new methods to classes
228
 
 
229
 
class Handler(Utils.Context):
230
 
        """loads wscript modules in folders for adding options
231
 
        This class should be named 'OptionsContext'
232
 
        A method named 'recurse' is bound when used by the module Scripting"""
233
 
 
234
 
        parser = None
235
 
        # make it possible to access the reference, like Build.bld
236
 
 
237
 
        def __init__(self, module=None):
238
 
                self.parser = create_parser(module)
239
 
                self.cwd = os.getcwd()
240
 
                Handler.parser = self
241
 
 
242
 
        def add_option(self, *k, **kw):
243
 
                self.parser.add_option(*k, **kw)
244
 
 
245
 
        def add_option_group(self, *k, **kw):
246
 
                return self.parser.add_option_group(*k, **kw)
247
 
 
248
 
        def get_option_group(self, opt_str):
249
 
                return self.parser.get_option_group(opt_str)
250
 
 
251
 
        def sub_options(self, *k, **kw):
252
 
                if not k: raise Utils.WscriptError('folder expected')
253
 
                self.recurse(k[0], name='set_options')
254
 
 
255
 
        def tool_options(self, *k, **kw):
256
 
                Utils.python_24_guard()
257
 
 
258
 
                if not k[0]:
259
 
                        raise Utils.WscriptError('invalid tool_options call %r %r' % (k, kw))
260
 
                tools = Utils.to_list(k[0])
261
 
 
262
 
                # TODO waf 1.6 remove the global variable tooldir
263
 
                path = Utils.to_list(kw.get('tdir', kw.get('tooldir', tooldir)))
264
 
 
265
 
                for tool in tools:
266
 
                        tool = tool.replace('++', 'xx')
267
 
                        if tool == 'java': tool = 'javaw'
268
 
                        if tool.lower() == 'unittest': tool = 'unittestw'
269
 
                        module = Utils.load_tool(tool, path)
270
 
                        try:
271
 
                                fun = module.set_options
272
 
                        except AttributeError:
273
 
                                pass
274
 
                        else:
275
 
                                fun(kw.get('option_group', self))
276
 
 
277
 
        def parse_args(self, args=None):
278
 
                parse_args_impl(self.parser, args)
279