[0fa325b] | 1 | #! /usr/bin/env python |
---|
| 2 | # encoding: utf-8 |
---|
| 3 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file |
---|
| 4 | |
---|
| 5 | import os,sys,errno,re,shutil |
---|
| 6 | try: |
---|
| 7 | import cPickle |
---|
| 8 | except ImportError: |
---|
| 9 | import pickle as cPickle |
---|
| 10 | from waflib import Runner,TaskGen,Utils,ConfigSet,Task,Logs,Options,Context,Errors |
---|
| 11 | import waflib.Node |
---|
| 12 | CACHE_DIR='c4che' |
---|
| 13 | CACHE_SUFFIX='_cache.py' |
---|
| 14 | INSTALL=1337 |
---|
| 15 | UNINSTALL=-1337 |
---|
| 16 | SAVED_ATTRS='root node_deps raw_deps task_sigs'.split() |
---|
| 17 | CFG_FILES='cfg_files' |
---|
| 18 | POST_AT_ONCE=0 |
---|
| 19 | POST_LAZY=1 |
---|
| 20 | POST_BOTH=2 |
---|
| 21 | class BuildContext(Context.Context): |
---|
| 22 | '''executes the build''' |
---|
| 23 | cmd='build' |
---|
| 24 | variant='' |
---|
| 25 | def __init__(self,**kw): |
---|
| 26 | super(BuildContext,self).__init__(**kw) |
---|
| 27 | self.is_install=0 |
---|
| 28 | self.top_dir=kw.get('top_dir',Context.top_dir) |
---|
| 29 | self.run_dir=kw.get('run_dir',Context.run_dir) |
---|
| 30 | self.post_mode=POST_AT_ONCE |
---|
| 31 | self.out_dir=kw.get('out_dir',Context.out_dir) |
---|
| 32 | self.cache_dir=kw.get('cache_dir',None) |
---|
| 33 | if not self.cache_dir: |
---|
| 34 | self.cache_dir=self.out_dir+os.sep+CACHE_DIR |
---|
| 35 | self.all_envs={} |
---|
| 36 | self.task_sigs={} |
---|
| 37 | self.node_deps={} |
---|
| 38 | self.raw_deps={} |
---|
| 39 | self.cache_dir_contents={} |
---|
| 40 | self.task_gen_cache_names={} |
---|
| 41 | self.launch_dir=Context.launch_dir |
---|
| 42 | self.jobs=Options.options.jobs |
---|
| 43 | self.targets=Options.options.targets |
---|
| 44 | self.keep=Options.options.keep |
---|
| 45 | self.cache_global=Options.cache_global |
---|
| 46 | self.nocache=Options.options.nocache |
---|
| 47 | self.progress_bar=Options.options.progress_bar |
---|
| 48 | self.deps_man=Utils.defaultdict(list) |
---|
| 49 | self.current_group=0 |
---|
| 50 | self.groups=[] |
---|
| 51 | self.group_names={} |
---|
| 52 | def get_variant_dir(self): |
---|
| 53 | if not self.variant: |
---|
| 54 | return self.out_dir |
---|
| 55 | return os.path.join(self.out_dir,self.variant) |
---|
| 56 | variant_dir=property(get_variant_dir,None) |
---|
| 57 | def __call__(self,*k,**kw): |
---|
| 58 | kw['bld']=self |
---|
| 59 | ret=TaskGen.task_gen(*k,**kw) |
---|
| 60 | self.task_gen_cache_names={} |
---|
| 61 | self.add_to_group(ret,group=kw.get('group',None)) |
---|
| 62 | return ret |
---|
| 63 | def rule(self,*k,**kw): |
---|
| 64 | def f(rule): |
---|
| 65 | ret=self(*k,**kw) |
---|
| 66 | ret.rule=rule |
---|
| 67 | return ret |
---|
| 68 | return f |
---|
| 69 | def __copy__(self): |
---|
| 70 | raise Errors.WafError('build contexts are not supposed to be copied') |
---|
| 71 | def install_files(self,*k,**kw): |
---|
| 72 | pass |
---|
| 73 | def install_as(self,*k,**kw): |
---|
| 74 | pass |
---|
| 75 | def symlink_as(self,*k,**kw): |
---|
| 76 | pass |
---|
| 77 | def load_envs(self): |
---|
| 78 | node=self.root.find_node(self.cache_dir) |
---|
| 79 | if not node: |
---|
| 80 | raise Errors.WafError('The project was not configured: run "waf configure" first!') |
---|
| 81 | lst=node.ant_glob('**/*%s'%CACHE_SUFFIX,quiet=True) |
---|
| 82 | if not lst: |
---|
| 83 | raise Errors.WafError('The cache directory is empty: reconfigure the project') |
---|
| 84 | for x in lst: |
---|
| 85 | name=x.path_from(node).replace(CACHE_SUFFIX,'').replace('\\','/') |
---|
| 86 | env=ConfigSet.ConfigSet(x.abspath()) |
---|
| 87 | self.all_envs[name]=env |
---|
| 88 | for f in env[CFG_FILES]: |
---|
| 89 | newnode=self.root.find_resource(f) |
---|
| 90 | try: |
---|
| 91 | h=Utils.h_file(newnode.abspath()) |
---|
| 92 | except(IOError,AttributeError): |
---|
| 93 | Logs.error('cannot find %r'%f) |
---|
| 94 | h=Utils.SIG_NIL |
---|
| 95 | newnode.sig=h |
---|
| 96 | def init_dirs(self): |
---|
| 97 | if not(os.path.isabs(self.top_dir)and os.path.isabs(self.out_dir)): |
---|
| 98 | raise Errors.WafError('The project was not configured: run "waf configure" first!') |
---|
| 99 | self.path=self.srcnode=self.root.find_dir(self.top_dir) |
---|
| 100 | self.bldnode=self.root.make_node(self.variant_dir) |
---|
| 101 | self.bldnode.mkdir() |
---|
| 102 | def execute(self): |
---|
| 103 | self.restore() |
---|
| 104 | if not self.all_envs: |
---|
| 105 | self.load_envs() |
---|
| 106 | self.execute_build() |
---|
| 107 | def execute_build(self): |
---|
| 108 | Logs.info("Waf: Entering directory `%s'"%self.variant_dir) |
---|
| 109 | self.recurse([self.run_dir]) |
---|
| 110 | self.pre_build() |
---|
| 111 | self.timer=Utils.Timer() |
---|
| 112 | if self.progress_bar: |
---|
| 113 | sys.stderr.write(Logs.colors.cursor_off) |
---|
| 114 | try: |
---|
| 115 | self.compile() |
---|
| 116 | finally: |
---|
| 117 | if self.progress_bar==1: |
---|
| 118 | c=len(self.returned_tasks)or 1 |
---|
| 119 | self.to_log(self.progress_line(c,c,Logs.colors.BLUE,Logs.colors.NORMAL)) |
---|
| 120 | print('') |
---|
| 121 | sys.stdout.flush() |
---|
| 122 | sys.stderr.write(Logs.colors.cursor_on) |
---|
| 123 | Logs.info("Waf: Leaving directory `%s'"%self.variant_dir) |
---|
| 124 | self.post_build() |
---|
| 125 | def restore(self): |
---|
| 126 | try: |
---|
| 127 | env=ConfigSet.ConfigSet(os.path.join(self.cache_dir,'build.config.py')) |
---|
| 128 | except(IOError,OSError): |
---|
| 129 | pass |
---|
| 130 | else: |
---|
| 131 | if env['version']<Context.HEXVERSION: |
---|
| 132 | raise Errors.WafError('Version mismatch! reconfigure the project') |
---|
| 133 | for t in env['tools']: |
---|
| 134 | self.setup(**t) |
---|
| 135 | f=None |
---|
| 136 | try: |
---|
| 137 | dbfn=os.path.join(self.variant_dir,Context.DBFILE) |
---|
| 138 | try: |
---|
| 139 | f=open(dbfn,'rb') |
---|
| 140 | except(IOError,EOFError): |
---|
| 141 | Logs.debug('build: Could not load the build cache %s (missing)'%dbfn) |
---|
| 142 | else: |
---|
| 143 | try: |
---|
| 144 | waflib.Node.pickle_lock.acquire() |
---|
| 145 | waflib.Node.Nod3=self.node_class |
---|
| 146 | try: |
---|
| 147 | data=cPickle.load(f) |
---|
| 148 | except Exception ,e: |
---|
| 149 | Logs.debug('build: Could not pickle the build cache %s: %r'%(dbfn,e)) |
---|
| 150 | else: |
---|
| 151 | for x in SAVED_ATTRS: |
---|
| 152 | setattr(self,x,data[x]) |
---|
| 153 | finally: |
---|
| 154 | waflib.Node.pickle_lock.release() |
---|
| 155 | finally: |
---|
| 156 | if f: |
---|
| 157 | f.close() |
---|
| 158 | self.init_dirs() |
---|
| 159 | def store(self): |
---|
| 160 | data={} |
---|
| 161 | for x in SAVED_ATTRS: |
---|
| 162 | data[x]=getattr(self,x) |
---|
| 163 | db=os.path.join(self.variant_dir,Context.DBFILE) |
---|
| 164 | try: |
---|
| 165 | waflib.Node.pickle_lock.acquire() |
---|
| 166 | waflib.Node.Nod3=self.node_class |
---|
| 167 | f=None |
---|
| 168 | try: |
---|
| 169 | f=open(db+'.tmp','wb') |
---|
| 170 | cPickle.dump(data,f,-1) |
---|
| 171 | finally: |
---|
| 172 | if f: |
---|
| 173 | f.close() |
---|
| 174 | finally: |
---|
| 175 | waflib.Node.pickle_lock.release() |
---|
| 176 | try: |
---|
| 177 | st=os.stat(db) |
---|
| 178 | os.unlink(db) |
---|
| 179 | if not Utils.is_win32: |
---|
| 180 | os.chown(db+'.tmp',st.st_uid,st.st_gid) |
---|
| 181 | except(AttributeError,OSError): |
---|
| 182 | pass |
---|
| 183 | os.rename(db+'.tmp',db) |
---|
| 184 | def compile(self): |
---|
| 185 | Logs.debug('build: compile()') |
---|
| 186 | self.producer=Runner.Parallel(self,self.jobs) |
---|
| 187 | self.producer.biter=self.get_build_iterator() |
---|
| 188 | self.returned_tasks=[] |
---|
| 189 | try: |
---|
| 190 | self.producer.start() |
---|
| 191 | except KeyboardInterrupt: |
---|
| 192 | self.store() |
---|
| 193 | raise |
---|
| 194 | else: |
---|
| 195 | if self.producer.dirty: |
---|
| 196 | self.store() |
---|
| 197 | if self.producer.error: |
---|
| 198 | raise Errors.BuildError(self.producer.error) |
---|
| 199 | def setup(self,tool,tooldir=None,funs=None): |
---|
| 200 | if isinstance(tool,list): |
---|
| 201 | for i in tool:self.setup(i,tooldir) |
---|
| 202 | return |
---|
| 203 | module=Context.load_tool(tool,tooldir) |
---|
| 204 | if hasattr(module,"setup"):module.setup(self) |
---|
| 205 | def get_env(self): |
---|
| 206 | try: |
---|
| 207 | return self.all_envs[self.variant] |
---|
| 208 | except KeyError: |
---|
| 209 | return self.all_envs[''] |
---|
| 210 | def set_env(self,val): |
---|
| 211 | self.all_envs[self.variant]=val |
---|
| 212 | env=property(get_env,set_env) |
---|
| 213 | def add_manual_dependency(self,path,value): |
---|
| 214 | if path is None: |
---|
| 215 | raise ValueError('Invalid input') |
---|
| 216 | if isinstance(path,waflib.Node.Node): |
---|
| 217 | node=path |
---|
| 218 | elif os.path.isabs(path): |
---|
| 219 | node=self.root.find_resource(path) |
---|
| 220 | else: |
---|
| 221 | node=self.path.find_resource(path) |
---|
| 222 | if isinstance(value,list): |
---|
| 223 | self.deps_man[id(node)].extend(value) |
---|
| 224 | else: |
---|
| 225 | self.deps_man[id(node)].append(value) |
---|
| 226 | def launch_node(self): |
---|
| 227 | try: |
---|
| 228 | return self.p_ln |
---|
| 229 | except AttributeError: |
---|
| 230 | self.p_ln=self.root.find_dir(self.launch_dir) |
---|
| 231 | return self.p_ln |
---|
| 232 | def hash_env_vars(self,env,vars_lst): |
---|
| 233 | if not env.table: |
---|
| 234 | env=env.parent |
---|
| 235 | if not env: |
---|
| 236 | return Utils.SIG_NIL |
---|
| 237 | idx=str(id(env))+str(vars_lst) |
---|
| 238 | try: |
---|
| 239 | cache=self.cache_env |
---|
| 240 | except AttributeError: |
---|
| 241 | cache=self.cache_env={} |
---|
| 242 | else: |
---|
| 243 | try: |
---|
| 244 | return self.cache_env[idx] |
---|
| 245 | except KeyError: |
---|
| 246 | pass |
---|
| 247 | lst=[env[a]for a in vars_lst] |
---|
| 248 | ret=Utils.h_list(lst) |
---|
| 249 | Logs.debug('envhash: %s %r',Utils.to_hex(ret),lst) |
---|
| 250 | cache[idx]=ret |
---|
| 251 | return ret |
---|
| 252 | def get_tgen_by_name(self,name): |
---|
| 253 | cache=self.task_gen_cache_names |
---|
| 254 | if not cache: |
---|
| 255 | for g in self.groups: |
---|
| 256 | for tg in g: |
---|
| 257 | try: |
---|
| 258 | cache[tg.name]=tg |
---|
| 259 | except AttributeError: |
---|
| 260 | pass |
---|
| 261 | try: |
---|
| 262 | return cache[name] |
---|
| 263 | except KeyError: |
---|
| 264 | raise Errors.WafError('Could not find a task generator for the name %r'%name) |
---|
| 265 | def progress_line(self,state,total,col1,col2): |
---|
| 266 | n=len(str(total)) |
---|
| 267 | Utils.rot_idx+=1 |
---|
| 268 | ind=Utils.rot_chr[Utils.rot_idx%4] |
---|
| 269 | pc=(100.*state)/total |
---|
| 270 | eta=str(self.timer) |
---|
| 271 | fs="[%%%dd/%%%dd][%%s%%2d%%%%%%s][%s]["%(n,n,ind) |
---|
| 272 | left=fs%(state,total,col1,pc,col2) |
---|
| 273 | right='][%s%s%s]'%(col1,eta,col2) |
---|
| 274 | cols=Logs.get_term_cols()-len(left)-len(right)+2*len(col1)+2*len(col2) |
---|
| 275 | if cols<7:cols=7 |
---|
| 276 | ratio=((cols*state)//total)-1 |
---|
| 277 | bar=('='*ratio+'>').ljust(cols) |
---|
| 278 | msg=Utils.indicator%(left,bar,right) |
---|
| 279 | return msg |
---|
| 280 | def declare_chain(self,*k,**kw): |
---|
| 281 | return TaskGen.declare_chain(*k,**kw) |
---|
| 282 | def pre_build(self): |
---|
| 283 | for m in getattr(self,'pre_funs',[]): |
---|
| 284 | m(self) |
---|
| 285 | def post_build(self): |
---|
| 286 | for m in getattr(self,'post_funs',[]): |
---|
| 287 | m(self) |
---|
| 288 | def add_pre_fun(self,meth): |
---|
| 289 | try: |
---|
| 290 | self.pre_funs.append(meth) |
---|
| 291 | except AttributeError: |
---|
| 292 | self.pre_funs=[meth] |
---|
| 293 | def add_post_fun(self,meth): |
---|
| 294 | try: |
---|
| 295 | self.post_funs.append(meth) |
---|
| 296 | except AttributeError: |
---|
| 297 | self.post_funs=[meth] |
---|
| 298 | def get_group(self,x): |
---|
| 299 | if not self.groups: |
---|
| 300 | self.add_group() |
---|
| 301 | if x is None: |
---|
| 302 | return self.groups[self.current_group] |
---|
| 303 | if x in self.group_names: |
---|
| 304 | return self.group_names[x] |
---|
| 305 | return self.groups[x] |
---|
| 306 | def add_to_group(self,tgen,group=None): |
---|
| 307 | assert(isinstance(tgen,TaskGen.task_gen)or isinstance(tgen,Task.TaskBase)) |
---|
| 308 | tgen.bld=self |
---|
| 309 | self.get_group(group).append(tgen) |
---|
| 310 | def get_group_name(self,g): |
---|
| 311 | if not isinstance(g,list): |
---|
| 312 | g=self.groups[g] |
---|
| 313 | for x in self.group_names: |
---|
| 314 | if id(self.group_names[x])==id(g): |
---|
| 315 | return x |
---|
| 316 | return'' |
---|
| 317 | def get_group_idx(self,tg): |
---|
| 318 | se=id(tg) |
---|
| 319 | for i in range(len(self.groups)): |
---|
| 320 | for t in self.groups[i]: |
---|
| 321 | if id(t)==se: |
---|
| 322 | return i |
---|
| 323 | return None |
---|
| 324 | def add_group(self,name=None,move=True): |
---|
| 325 | if name and name in self.group_names: |
---|
| 326 | Logs.error('add_group: name %s already present'%name) |
---|
| 327 | g=[] |
---|
| 328 | self.group_names[name]=g |
---|
| 329 | self.groups.append(g) |
---|
| 330 | if move: |
---|
| 331 | self.current_group=len(self.groups)-1 |
---|
| 332 | def set_group(self,idx): |
---|
| 333 | if isinstance(idx,str): |
---|
| 334 | g=self.group_names[idx] |
---|
| 335 | for i in range(len(self.groups)): |
---|
| 336 | if id(g)==id(self.groups[i]): |
---|
| 337 | self.current_group=i |
---|
| 338 | else: |
---|
| 339 | self.current_group=idx |
---|
| 340 | def total(self): |
---|
| 341 | total=0 |
---|
| 342 | for group in self.groups: |
---|
| 343 | for tg in group: |
---|
| 344 | try: |
---|
| 345 | total+=len(tg.tasks) |
---|
| 346 | except AttributeError: |
---|
| 347 | total+=1 |
---|
| 348 | return total |
---|
| 349 | def get_targets(self): |
---|
| 350 | to_post=[] |
---|
| 351 | min_grp=0 |
---|
| 352 | for name in self.targets.split(','): |
---|
| 353 | tg=self.get_tgen_by_name(name) |
---|
| 354 | if not tg: |
---|
| 355 | raise Errors.WafError('target %r does not exist'%name) |
---|
| 356 | m=self.get_group_idx(tg) |
---|
| 357 | if m>min_grp: |
---|
| 358 | min_grp=m |
---|
| 359 | to_post=[tg] |
---|
| 360 | elif m==min_grp: |
---|
| 361 | to_post.append(tg) |
---|
| 362 | return(min_grp,to_post) |
---|
| 363 | def get_all_task_gen(self): |
---|
| 364 | lst=[] |
---|
| 365 | for g in self.groups: |
---|
| 366 | lst.extend(g) |
---|
| 367 | return lst |
---|
| 368 | def post_group(self): |
---|
| 369 | if self.targets=='*': |
---|
| 370 | for tg in self.groups[self.cur]: |
---|
| 371 | try: |
---|
| 372 | f=tg.post |
---|
| 373 | except AttributeError: |
---|
| 374 | pass |
---|
| 375 | else: |
---|
| 376 | f() |
---|
| 377 | elif self.targets: |
---|
| 378 | if self.cur<self._min_grp: |
---|
| 379 | for tg in self.groups[self.cur]: |
---|
| 380 | try: |
---|
| 381 | f=tg.post |
---|
| 382 | except AttributeError: |
---|
| 383 | pass |
---|
| 384 | else: |
---|
| 385 | f() |
---|
| 386 | else: |
---|
| 387 | for tg in self._exact_tg: |
---|
| 388 | tg.post() |
---|
| 389 | else: |
---|
| 390 | ln=self.launch_node() |
---|
| 391 | if ln.is_child_of(self.bldnode): |
---|
| 392 | Logs.warn('Building from the build directory, forcing --targets=*') |
---|
| 393 | ln=self.srcnode |
---|
| 394 | elif not ln.is_child_of(self.srcnode): |
---|
| 395 | Logs.warn('CWD %s is not under %s, forcing --targets=* (run distclean?)'%(ln.abspath(),self.srcnode.abspath())) |
---|
| 396 | ln=self.srcnode |
---|
| 397 | for tg in self.groups[self.cur]: |
---|
| 398 | try: |
---|
| 399 | f=tg.post |
---|
| 400 | except AttributeError: |
---|
| 401 | pass |
---|
| 402 | else: |
---|
| 403 | if tg.path.is_child_of(ln): |
---|
| 404 | f() |
---|
| 405 | def get_tasks_group(self,idx): |
---|
| 406 | tasks=[] |
---|
| 407 | for tg in self.groups[idx]: |
---|
| 408 | try: |
---|
| 409 | tasks.extend(tg.tasks) |
---|
| 410 | except AttributeError: |
---|
| 411 | tasks.append(tg) |
---|
| 412 | return tasks |
---|
| 413 | def get_build_iterator(self): |
---|
| 414 | self.cur=0 |
---|
| 415 | if self.targets and self.targets!='*': |
---|
| 416 | (self._min_grp,self._exact_tg)=self.get_targets() |
---|
| 417 | global lazy_post |
---|
| 418 | if self.post_mode!=POST_LAZY: |
---|
| 419 | while self.cur<len(self.groups): |
---|
| 420 | self.post_group() |
---|
| 421 | self.cur+=1 |
---|
| 422 | self.cur=0 |
---|
| 423 | while self.cur<len(self.groups): |
---|
| 424 | if self.post_mode!=POST_AT_ONCE: |
---|
| 425 | self.post_group() |
---|
| 426 | tasks=self.get_tasks_group(self.cur) |
---|
| 427 | Task.set_file_constraints(tasks) |
---|
| 428 | Task.set_precedence_constraints(tasks) |
---|
| 429 | self.cur_tasks=tasks |
---|
| 430 | self.cur+=1 |
---|
| 431 | if not tasks: |
---|
| 432 | continue |
---|
| 433 | yield tasks |
---|
| 434 | while 1: |
---|
| 435 | yield[] |
---|
| 436 | class inst(Task.Task): |
---|
| 437 | color='CYAN' |
---|
| 438 | def uid(self): |
---|
| 439 | lst=[self.dest,self.path]+self.source |
---|
| 440 | return Utils.h_list(repr(lst)) |
---|
| 441 | def post(self): |
---|
| 442 | buf=[] |
---|
| 443 | for x in self.source: |
---|
| 444 | if isinstance(x,waflib.Node.Node): |
---|
| 445 | y=x |
---|
| 446 | else: |
---|
| 447 | y=self.path.find_resource(x) |
---|
| 448 | if not y: |
---|
| 449 | if Logs.verbose: |
---|
| 450 | Logs.warn('Could not find %s immediately (may cause broken builds)'%x) |
---|
| 451 | idx=self.generator.bld.get_group_idx(self) |
---|
| 452 | for tg in self.generator.bld.groups[idx]: |
---|
| 453 | if not isinstance(tg,inst)and id(tg)!=id(self): |
---|
| 454 | tg.post() |
---|
| 455 | y=self.path.find_resource(x) |
---|
| 456 | if y: |
---|
| 457 | break |
---|
| 458 | else: |
---|
| 459 | raise Errors.WafError('Could not find %r in %r'%(x,self.path)) |
---|
| 460 | buf.append(y) |
---|
| 461 | self.inputs=buf |
---|
| 462 | def runnable_status(self): |
---|
| 463 | ret=super(inst,self).runnable_status() |
---|
| 464 | if ret==Task.SKIP_ME: |
---|
| 465 | return Task.RUN_ME |
---|
| 466 | return ret |
---|
| 467 | def __str__(self): |
---|
| 468 | return'' |
---|
| 469 | def run(self): |
---|
| 470 | return self.generator.exec_task() |
---|
| 471 | def get_install_path(self,destdir=True): |
---|
| 472 | dest=Utils.subst_vars(self.dest,self.env) |
---|
| 473 | dest=dest.replace('/',os.sep) |
---|
| 474 | if destdir and Options.options.destdir: |
---|
| 475 | dest=os.path.join(Options.options.destdir,os.path.splitdrive(dest)[1].lstrip(os.sep)) |
---|
| 476 | return dest |
---|
| 477 | def exec_install_files(self): |
---|
| 478 | destpath=self.get_install_path() |
---|
| 479 | if not destpath: |
---|
| 480 | raise Errors.WafError('unknown installation path %r'%self.generator) |
---|
| 481 | for x,y in zip(self.source,self.inputs): |
---|
| 482 | if self.relative_trick: |
---|
| 483 | destfile=os.path.join(destpath,y.path_from(self.path)) |
---|
| 484 | Utils.check_dir(os.path.dirname(destfile)) |
---|
| 485 | else: |
---|
| 486 | destfile=os.path.join(destpath,y.name) |
---|
| 487 | self.generator.bld.do_install(y.abspath(),destfile,self.chmod) |
---|
| 488 | def exec_install_as(self): |
---|
| 489 | destfile=self.get_install_path() |
---|
| 490 | self.generator.bld.do_install(self.inputs[0].abspath(),destfile,self.chmod) |
---|
| 491 | def exec_symlink_as(self): |
---|
| 492 | destfile=self.get_install_path() |
---|
| 493 | src=self.link |
---|
| 494 | if self.relative_trick: |
---|
| 495 | src=os.path.relpath(src,os.path.dirname(destfile)) |
---|
| 496 | self.generator.bld.do_link(src,destfile) |
---|
| 497 | class InstallContext(BuildContext): |
---|
| 498 | '''installs the targets on the system''' |
---|
| 499 | cmd='install' |
---|
| 500 | def __init__(self,**kw): |
---|
| 501 | super(InstallContext,self).__init__(**kw) |
---|
| 502 | self.uninstall=[] |
---|
| 503 | self.is_install=INSTALL |
---|
| 504 | def do_install(self,src,tgt,chmod=Utils.O644): |
---|
| 505 | d,_=os.path.split(tgt) |
---|
| 506 | if not d: |
---|
| 507 | raise Errors.WafError('Invalid installation given %r->%r'%(src,tgt)) |
---|
| 508 | Utils.check_dir(d) |
---|
| 509 | srclbl=src.replace(self.srcnode.abspath()+os.sep,'') |
---|
| 510 | if not Options.options.force: |
---|
| 511 | try: |
---|
| 512 | st1=os.stat(tgt) |
---|
| 513 | st2=os.stat(src) |
---|
| 514 | except OSError: |
---|
| 515 | pass |
---|
| 516 | else: |
---|
| 517 | if st1.st_mtime+2>=st2.st_mtime and st1.st_size==st2.st_size: |
---|
| 518 | if not self.progress_bar: |
---|
| 519 | Logs.info('- install %s (from %s)'%(tgt,srclbl)) |
---|
| 520 | return False |
---|
| 521 | if not self.progress_bar: |
---|
| 522 | Logs.info('+ install %s (from %s)'%(tgt,srclbl)) |
---|
| 523 | try: |
---|
| 524 | os.remove(tgt) |
---|
| 525 | except OSError: |
---|
| 526 | pass |
---|
| 527 | try: |
---|
| 528 | shutil.copy2(src,tgt) |
---|
| 529 | os.chmod(tgt,chmod) |
---|
| 530 | except IOError: |
---|
| 531 | try: |
---|
| 532 | os.stat(src) |
---|
| 533 | except(OSError,IOError): |
---|
| 534 | Logs.error('File %r does not exist'%src) |
---|
| 535 | raise Errors.WafError('Could not install the file %r'%tgt) |
---|
| 536 | def do_link(self,src,tgt): |
---|
| 537 | d,_=os.path.split(tgt) |
---|
| 538 | Utils.check_dir(d) |
---|
| 539 | link=False |
---|
| 540 | if not os.path.islink(tgt): |
---|
| 541 | link=True |
---|
| 542 | elif os.readlink(tgt)!=src: |
---|
| 543 | link=True |
---|
| 544 | if link: |
---|
| 545 | try:os.remove(tgt) |
---|
| 546 | except OSError:pass |
---|
| 547 | if not self.progress_bar: |
---|
| 548 | Logs.info('+ symlink %s (to %s)'%(tgt,src)) |
---|
| 549 | os.symlink(src,tgt) |
---|
| 550 | else: |
---|
| 551 | if not self.progress_bar: |
---|
| 552 | Logs.info('- symlink %s (to %s)'%(tgt,src)) |
---|
| 553 | def run_task_now(self,tsk,postpone): |
---|
| 554 | tsk.post() |
---|
| 555 | if not postpone: |
---|
| 556 | if tsk.runnable_status()==Task.ASK_LATER: |
---|
| 557 | raise self.WafError('cannot post the task %r'%tsk) |
---|
| 558 | tsk.run() |
---|
| 559 | def install_files(self,dest,files,env=None,chmod=Utils.O644,relative_trick=False,cwd=None,add=True,postpone=True): |
---|
| 560 | tsk=inst(env=env or self.env) |
---|
| 561 | tsk.bld=self |
---|
| 562 | tsk.path=cwd or self.path |
---|
| 563 | tsk.chmod=chmod |
---|
| 564 | if isinstance(files,waflib.Node.Node): |
---|
| 565 | tsk.source=[files] |
---|
| 566 | else: |
---|
| 567 | tsk.source=Utils.to_list(files) |
---|
| 568 | tsk.dest=dest |
---|
| 569 | tsk.exec_task=tsk.exec_install_files |
---|
| 570 | tsk.relative_trick=relative_trick |
---|
| 571 | if add:self.add_to_group(tsk) |
---|
| 572 | self.run_task_now(tsk,postpone) |
---|
| 573 | return tsk |
---|
| 574 | def install_as(self,dest,srcfile,env=None,chmod=Utils.O644,cwd=None,add=True,postpone=True): |
---|
| 575 | tsk=inst(env=env or self.env) |
---|
| 576 | tsk.bld=self |
---|
| 577 | tsk.path=cwd or self.path |
---|
| 578 | tsk.chmod=chmod |
---|
| 579 | tsk.source=[srcfile] |
---|
| 580 | tsk.dest=dest |
---|
| 581 | tsk.exec_task=tsk.exec_install_as |
---|
| 582 | if add:self.add_to_group(tsk) |
---|
| 583 | self.run_task_now(tsk,postpone) |
---|
| 584 | return tsk |
---|
| 585 | def symlink_as(self,dest,src,env=None,cwd=None,add=True,postpone=True,relative_trick=False): |
---|
| 586 | if Utils.is_win32: |
---|
| 587 | return |
---|
| 588 | tsk=inst(env=env or self.env) |
---|
| 589 | tsk.bld=self |
---|
| 590 | tsk.dest=dest |
---|
| 591 | tsk.path=cwd or self.path |
---|
| 592 | tsk.source=[] |
---|
| 593 | tsk.link=src |
---|
| 594 | tsk.relative_trick=relative_trick |
---|
| 595 | tsk.exec_task=tsk.exec_symlink_as |
---|
| 596 | if add:self.add_to_group(tsk) |
---|
| 597 | self.run_task_now(tsk,postpone) |
---|
| 598 | return tsk |
---|
| 599 | class UninstallContext(InstallContext): |
---|
| 600 | '''removes the targets installed''' |
---|
| 601 | cmd='uninstall' |
---|
| 602 | def __init__(self,**kw): |
---|
| 603 | super(UninstallContext,self).__init__(**kw) |
---|
| 604 | self.is_install=UNINSTALL |
---|
| 605 | def do_install(self,src,tgt,chmod=Utils.O644): |
---|
| 606 | if not self.progress_bar: |
---|
| 607 | Logs.info('- remove %s'%tgt) |
---|
| 608 | self.uninstall.append(tgt) |
---|
| 609 | try: |
---|
| 610 | os.remove(tgt) |
---|
| 611 | except OSError ,e: |
---|
| 612 | if e.errno!=errno.ENOENT: |
---|
| 613 | if not getattr(self,'uninstall_error',None): |
---|
| 614 | self.uninstall_error=True |
---|
| 615 | Logs.warn('build: some files could not be uninstalled (retry with -vv to list them)') |
---|
| 616 | if Logs.verbose>1: |
---|
| 617 | Logs.warn('Could not remove %s (error code %r)'%(e.filename,e.errno)) |
---|
| 618 | while tgt: |
---|
| 619 | tgt=os.path.dirname(tgt) |
---|
| 620 | try: |
---|
| 621 | os.rmdir(tgt) |
---|
| 622 | except OSError: |
---|
| 623 | break |
---|
| 624 | def do_link(self,src,tgt): |
---|
| 625 | try: |
---|
| 626 | if not self.progress_bar: |
---|
| 627 | Logs.info('- unlink %s'%tgt) |
---|
| 628 | os.remove(tgt) |
---|
| 629 | except OSError: |
---|
| 630 | pass |
---|
| 631 | while tgt: |
---|
| 632 | tgt=os.path.dirname(tgt) |
---|
| 633 | try: |
---|
| 634 | os.rmdir(tgt) |
---|
| 635 | except OSError: |
---|
| 636 | break |
---|
| 637 | def execute(self): |
---|
| 638 | try: |
---|
| 639 | def runnable_status(self): |
---|
| 640 | return Task.SKIP_ME |
---|
| 641 | setattr(Task.Task,'runnable_status_back',Task.Task.runnable_status) |
---|
| 642 | setattr(Task.Task,'runnable_status',runnable_status) |
---|
| 643 | super(UninstallContext,self).execute() |
---|
| 644 | finally: |
---|
| 645 | setattr(Task.Task,'runnable_status',Task.Task.runnable_status_back) |
---|
| 646 | class CleanContext(BuildContext): |
---|
| 647 | '''cleans the project''' |
---|
| 648 | cmd='clean' |
---|
| 649 | def execute(self): |
---|
| 650 | self.restore() |
---|
| 651 | if not self.all_envs: |
---|
| 652 | self.load_envs() |
---|
| 653 | self.recurse([self.run_dir]) |
---|
| 654 | try: |
---|
| 655 | self.clean() |
---|
| 656 | finally: |
---|
| 657 | self.store() |
---|
| 658 | def clean(self): |
---|
| 659 | Logs.debug('build: clean called') |
---|
| 660 | if self.bldnode!=self.srcnode: |
---|
| 661 | lst=[] |
---|
| 662 | for e in self.all_envs.values(): |
---|
| 663 | lst.extend(self.root.find_or_declare(f)for f in e[CFG_FILES]) |
---|
| 664 | for n in self.bldnode.ant_glob('**/*',excl='.lock* *conf_check_*/** config.log c4che/*',quiet=True): |
---|
| 665 | if n in lst: |
---|
| 666 | continue |
---|
| 667 | n.delete() |
---|
| 668 | self.root.children={} |
---|
| 669 | for v in'node_deps task_sigs raw_deps'.split(): |
---|
| 670 | setattr(self,v,{}) |
---|
| 671 | class ListContext(BuildContext): |
---|
| 672 | '''lists the targets to execute''' |
---|
| 673 | cmd='list' |
---|
| 674 | def execute(self): |
---|
| 675 | self.restore() |
---|
| 676 | if not self.all_envs: |
---|
| 677 | self.load_envs() |
---|
| 678 | self.recurse([self.run_dir]) |
---|
| 679 | self.pre_build() |
---|
| 680 | self.timer=Utils.Timer() |
---|
| 681 | for g in self.groups: |
---|
| 682 | for tg in g: |
---|
| 683 | try: |
---|
| 684 | f=tg.post |
---|
| 685 | except AttributeError: |
---|
| 686 | pass |
---|
| 687 | else: |
---|
| 688 | f() |
---|
| 689 | try: |
---|
| 690 | self.get_tgen_by_name('') |
---|
| 691 | except Exception: |
---|
| 692 | pass |
---|
| 693 | lst=list(self.task_gen_cache_names.keys()) |
---|
| 694 | lst.sort() |
---|
| 695 | for k in lst: |
---|
| 696 | Logs.pprint('GREEN',k) |
---|
| 697 | class StepContext(BuildContext): |
---|
| 698 | '''executes tasks in a step-by-step fashion, for debugging''' |
---|
| 699 | cmd='step' |
---|
| 700 | def __init__(self,**kw): |
---|
| 701 | super(StepContext,self).__init__(**kw) |
---|
| 702 | self.files=Options.options.files |
---|
| 703 | def compile(self): |
---|
| 704 | if not self.files: |
---|
| 705 | Logs.warn('Add a pattern for the debug build, for example "waf step --files=main.c,app"') |
---|
| 706 | BuildContext.compile(self) |
---|
| 707 | return |
---|
| 708 | targets=None |
---|
| 709 | if self.targets and self.targets!='*': |
---|
| 710 | targets=self.targets.split(',') |
---|
| 711 | for g in self.groups: |
---|
| 712 | for tg in g: |
---|
| 713 | if targets and tg.name not in targets: |
---|
| 714 | continue |
---|
| 715 | try: |
---|
| 716 | f=tg.post |
---|
| 717 | except AttributeError: |
---|
| 718 | pass |
---|
| 719 | else: |
---|
| 720 | f() |
---|
| 721 | for pat in self.files.split(','): |
---|
| 722 | matcher=self.get_matcher(pat) |
---|
| 723 | for tg in g: |
---|
| 724 | if isinstance(tg,Task.TaskBase): |
---|
| 725 | lst=[tg] |
---|
| 726 | else: |
---|
| 727 | lst=tg.tasks |
---|
| 728 | for tsk in lst: |
---|
| 729 | do_exec=False |
---|
| 730 | for node in getattr(tsk,'inputs',[]): |
---|
| 731 | if matcher(node,output=False): |
---|
| 732 | do_exec=True |
---|
| 733 | break |
---|
| 734 | for node in getattr(tsk,'outputs',[]): |
---|
| 735 | if matcher(node,output=True): |
---|
| 736 | do_exec=True |
---|
| 737 | break |
---|
| 738 | if do_exec: |
---|
| 739 | ret=tsk.run() |
---|
| 740 | Logs.info('%s -> exit %r'%(str(tsk),ret)) |
---|
| 741 | def get_matcher(self,pat): |
---|
| 742 | inn=True |
---|
| 743 | out=True |
---|
| 744 | if pat.startswith('in:'): |
---|
| 745 | out=False |
---|
| 746 | pat=pat.replace('in:','') |
---|
| 747 | elif pat.startswith('out:'): |
---|
| 748 | inn=False |
---|
| 749 | pat=pat.replace('out:','') |
---|
| 750 | anode=self.root.find_node(pat) |
---|
| 751 | pattern=None |
---|
| 752 | if not anode: |
---|
| 753 | if not pat.startswith('^'): |
---|
| 754 | pat='^.+?%s'%pat |
---|
| 755 | if not pat.endswith('$'): |
---|
| 756 | pat='%s$'%pat |
---|
| 757 | pattern=re.compile(pat) |
---|
| 758 | def match(node,output): |
---|
| 759 | if output==True and not out: |
---|
| 760 | return False |
---|
| 761 | if output==False and not inn: |
---|
| 762 | return False |
---|
| 763 | if anode: |
---|
| 764 | return anode==node |
---|
| 765 | else: |
---|
| 766 | return pattern.match(node.abspath()) |
---|
| 767 | return match |
---|
| 768 | BuildContext.store=Utils.nogc(BuildContext.store) |
---|
| 769 | BuildContext.restore=Utils.nogc(BuildContext.restore) |
---|