~ubuntu-branches/ubuntu/raring/xmms2/raring

« back to all changes in this revision

Viewing changes to waflib/Options.py

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2012-11-25 19:23:15 UTC
  • mto: This revision was merged to the branch mainline in revision 51.
  • Revision ID: package-import@ubuntu.com-20121125192315-m9z6nu9wwlzrrz9z
ImportĀ upstreamĀ versionĀ 0.8+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
# encoding: utf-8
 
3
# WARNING! Do not edit! http://waf.googlecode.com/svn/docs/wafbook/single.html#_obtaining_the_waf_file
 
4
 
 
5
import os,tempfile,optparse,sys,re
 
6
from waflib import Logs,Utils,Context
 
7
cmds='distclean configure build install clean uninstall check dist distcheck'.split()
 
8
options={}
 
9
commands=[]
 
10
lockfile=os.environ.get('WAFLOCK','.lock-wafbuild')
 
11
try:cache_global=os.path.abspath(os.environ['WAFCACHE'])
 
12
except KeyError:cache_global=''
 
13
platform=Utils.unversioned_sys_platform()
 
14
class opt_parser(optparse.OptionParser):
 
15
        def __init__(self,ctx):
 
16
                optparse.OptionParser.__init__(self,conflict_handler="resolve",version='waf %s (%s)'%(Context.WAFVERSION,Context.WAFREVISION))
 
17
                self.formatter.width=Logs.get_term_cols()
 
18
                p=self.add_option
 
19
                self.ctx=ctx
 
20
                jobs=ctx.jobs()
 
21
                p('-j','--jobs',dest='jobs',default=jobs,type='int',help='amount of parallel jobs (%r)'%jobs)
 
22
                p('-k','--keep',dest='keep',default=0,action='count',help='keep running happily even if errors are found')
 
23
                p('-v','--verbose',dest='verbose',default=0,action='count',help='verbosity level -v -vv or -vvv [default: 0]')
 
24
                p('--nocache',dest='nocache',default=False,action='store_true',help='ignore the WAFCACHE (if set)')
 
25
                p('--zones',dest='zones',default='',action='store',help='debugging zones (task_gen, deps, tasks, etc)')
 
26
                gr=optparse.OptionGroup(self,'configure options')
 
27
                self.add_option_group(gr)
 
28
                gr.add_option('-o','--out',action='store',default='',help='build dir for the project',dest='out')
 
29
                gr.add_option('-t','--top',action='store',default='',help='src dir for the project',dest='top')
 
30
                default_prefix=os.environ.get('PREFIX')
 
31
                if not default_prefix:
 
32
                        if platform=='win32':
 
33
                                d=tempfile.gettempdir()
 
34
                                default_prefix=d[0].upper()+d[1:]
 
35
                        else:
 
36
                                default_prefix='/usr/local/'
 
37
                gr.add_option('--prefix',dest='prefix',default=default_prefix,help='installation prefix [default: %r]'%default_prefix)
 
38
                gr.add_option('--download',dest='download',default=False,action='store_true',help='try to download the tools if missing')
 
39
                gr=optparse.OptionGroup(self,'build and install options')
 
40
                self.add_option_group(gr)
 
41
                gr.add_option('-p','--progress',dest='progress_bar',default=0,action='count',help='-p: progress bar; -pp: ide output')
 
42
                gr.add_option('--targets',dest='targets',default='',action='store',help='task generators, e.g. "target1,target2"')
 
43
                gr=optparse.OptionGroup(self,'step options')
 
44
                self.add_option_group(gr)
 
45
                gr.add_option('--files',dest='files',default='',action='store',help='files to process, by regexp, e.g. "*/main.c,*/test/main.o"')
 
46
                default_destdir=os.environ.get('DESTDIR','')
 
47
                gr=optparse.OptionGroup(self,'install/uninstall options')
 
48
                self.add_option_group(gr)
 
49
                gr.add_option('--destdir',help='installation root [default: %r]'%default_destdir,default=default_destdir,dest='destdir')
 
50
                gr.add_option('-f','--force',dest='force',default=False,action='store_true',help='force file installation')
 
51
        def get_usage(self):
 
52
                cmds_str={}
 
53
                for cls in Context.classes:
 
54
                        if not cls.cmd or cls.cmd=='options':
 
55
                                continue
 
56
                        s=cls.__doc__ or''
 
57
                        cmds_str[cls.cmd]=s
 
58
                if Context.g_module:
 
59
                        for(k,v)in Context.g_module.__dict__.items():
 
60
                                if k in['options','init','shutdown']:
 
61
                                        continue
 
62
                                if type(v)is type(Context.create_context):
 
63
                                        if v.__doc__ and not k.startswith('_'):
 
64
                                                cmds_str[k]=v.__doc__
 
65
                just=0
 
66
                for k in cmds_str:
 
67
                        just=max(just,len(k))
 
68
                lst=['  %s: %s'%(k.ljust(just),v)for(k,v)in cmds_str.items()]
 
69
                lst.sort()
 
70
                ret='\n'.join(lst)
 
71
                return'''waf [commands] [options]
 
72
 
 
73
Main commands (example: ./waf build -j4)
 
74
%s
 
75
'''%ret
 
76
class OptionsContext(Context.Context):
 
77
        cmd='options'
 
78
        fun='options'
 
79
        def __init__(self,**kw):
 
80
                super(OptionsContext,self).__init__(**kw)
 
81
                self.parser=opt_parser(self)
 
82
                self.option_groups={}
 
83
        def jobs(self):
 
84
                count=int(os.environ.get('JOBS',0))
 
85
                if count<1:
 
86
                        if'NUMBER_OF_PROCESSORS'in os.environ:
 
87
                                count=int(os.environ.get('NUMBER_OF_PROCESSORS',1))
 
88
                        else:
 
89
                                if hasattr(os,'sysconf_names'):
 
90
                                        if'SC_NPROCESSORS_ONLN'in os.sysconf_names:
 
91
                                                count=int(os.sysconf('SC_NPROCESSORS_ONLN'))
 
92
                                        elif'SC_NPROCESSORS_CONF'in os.sysconf_names:
 
93
                                                count=int(os.sysconf('SC_NPROCESSORS_CONF'))
 
94
                                elif os.name not in('nt','java'):
 
95
                                        tmp=self.cmd_and_log(['sysctl','-n','hw.ncpu'])
 
96
                                        if re.match('^[0-9]+$',tmp):
 
97
                                                count=int(tmp)
 
98
                if count<1:
 
99
                        count=1
 
100
                elif count>1024:
 
101
                        count=1024
 
102
                return count
 
103
        def add_option(self,*k,**kw):
 
104
                self.parser.add_option(*k,**kw)
 
105
        def add_option_group(self,*k,**kw):
 
106
                try:
 
107
                        gr=self.option_groups[k[0]]
 
108
                except:
 
109
                        gr=self.parser.add_option_group(*k,**kw)
 
110
                self.option_groups[k[0]]=gr
 
111
                return gr
 
112
        def get_option_group(self,opt_str):
 
113
                try:
 
114
                        return self.option_groups[opt_str]
 
115
                except KeyError:
 
116
                        for group in self.parser.option_groups:
 
117
                                if group.title==opt_str:
 
118
                                        return group
 
119
                        return None
 
120
        def parse_args(self,_args=None):
 
121
                global options,commands
 
122
                (options,leftover_args)=self.parser.parse_args(args=_args)
 
123
                commands=leftover_args
 
124
                if options.destdir:
 
125
                        options.destdir=os.path.abspath(os.path.expanduser(options.destdir))
 
126
                if options.verbose>=1:
 
127
                        self.load('errcheck')
 
128
        def execute(self):
 
129
                super(OptionsContext,self).execute()
 
130
                self.parse_args()