akmhoque | fa8ee9b | 2014-03-14 09:06:24 -0500 | [diff] [blame^] | 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 | from waflib import Utils,Task,Options,Logs,Errors |
| 6 | from waflib.TaskGen import before_method,after_method,feature |
| 7 | from waflib.Tools import ccroot |
| 8 | from waflib.Configure import conf |
| 9 | import os,tempfile |
| 10 | ccroot.USELIB_VARS['cs']=set(['CSFLAGS','ASSEMBLIES','RESOURCES']) |
| 11 | ccroot.lib_patterns['csshlib']=['%s'] |
| 12 | @feature('cs') |
| 13 | @before_method('process_source') |
| 14 | def apply_cs(self): |
| 15 | cs_nodes=[] |
| 16 | no_nodes=[] |
| 17 | for x in self.to_nodes(self.source): |
| 18 | if x.name.endswith('.cs'): |
| 19 | cs_nodes.append(x) |
| 20 | else: |
| 21 | no_nodes.append(x) |
| 22 | self.source=no_nodes |
| 23 | bintype=getattr(self,'bintype',self.gen.endswith('.dll')and'library'or'exe') |
| 24 | self.cs_task=tsk=self.create_task('mcs',cs_nodes,self.path.find_or_declare(self.gen)) |
| 25 | tsk.env.CSTYPE='/target:%s'%bintype |
| 26 | tsk.env.OUT='/out:%s'%tsk.outputs[0].abspath() |
| 27 | self.env.append_value('CSFLAGS','/platform:%s'%getattr(self,'platform','anycpu')) |
| 28 | inst_to=getattr(self,'install_path',bintype=='exe'and'${BINDIR}'or'${LIBDIR}') |
| 29 | if inst_to: |
| 30 | mod=getattr(self,'chmod',bintype=='exe'and Utils.O755 or Utils.O644) |
| 31 | self.install_task=self.bld.install_files(inst_to,self.cs_task.outputs[:],env=self.env,chmod=mod) |
| 32 | @feature('cs') |
| 33 | @after_method('apply_cs') |
| 34 | def use_cs(self): |
| 35 | names=self.to_list(getattr(self,'use',[])) |
| 36 | get=self.bld.get_tgen_by_name |
| 37 | for x in names: |
| 38 | try: |
| 39 | y=get(x) |
| 40 | except Errors.WafError: |
| 41 | self.env.append_value('CSFLAGS','/reference:%s'%x) |
| 42 | continue |
| 43 | y.post() |
| 44 | tsk=getattr(y,'cs_task',None)or getattr(y,'link_task',None) |
| 45 | if not tsk: |
| 46 | self.bld.fatal('cs task has no link task for use %r'%self) |
| 47 | self.cs_task.dep_nodes.extend(tsk.outputs) |
| 48 | self.cs_task.set_run_after(tsk) |
| 49 | self.env.append_value('CSFLAGS','/reference:%s'%tsk.outputs[0].abspath()) |
| 50 | @feature('cs') |
| 51 | @after_method('apply_cs','use_cs') |
| 52 | def debug_cs(self): |
| 53 | csdebug=getattr(self,'csdebug',self.env.CSDEBUG) |
| 54 | if not csdebug: |
| 55 | return |
| 56 | node=self.cs_task.outputs[0] |
| 57 | if self.env.CS_NAME=='mono': |
| 58 | out=node.parent.find_or_declare(node.name+'.mdb') |
| 59 | else: |
| 60 | out=node.change_ext('.pdb') |
| 61 | self.cs_task.outputs.append(out) |
| 62 | try: |
| 63 | self.install_task.source.append(out) |
| 64 | except AttributeError: |
| 65 | pass |
| 66 | if csdebug=='pdbonly': |
| 67 | val=['/debug+','/debug:pdbonly'] |
| 68 | elif csdebug=='full': |
| 69 | val=['/debug+','/debug:full'] |
| 70 | else: |
| 71 | val=['/debug-'] |
| 72 | self.env.append_value('CSFLAGS',val) |
| 73 | class mcs(Task.Task): |
| 74 | color='YELLOW' |
| 75 | run_str='${MCS} ${CSTYPE} ${CSFLAGS} ${ASS_ST:ASSEMBLIES} ${RES_ST:RESOURCES} ${OUT} ${SRC}' |
| 76 | def exec_command(self,cmd,**kw): |
| 77 | bld=self.generator.bld |
| 78 | try: |
| 79 | if not kw.get('cwd',None): |
| 80 | kw['cwd']=bld.cwd |
| 81 | except AttributeError: |
| 82 | bld.cwd=kw['cwd']=bld.variant_dir |
| 83 | try: |
| 84 | tmp=None |
| 85 | if isinstance(cmd,list)and len(' '.join(cmd))>=8192: |
| 86 | program=cmd[0] |
| 87 | cmd=[self.quote_response_command(x)for x in cmd] |
| 88 | (fd,tmp)=tempfile.mkstemp() |
| 89 | os.write(fd,'\r\n'.join(i.replace('\\','\\\\')for i in cmd[1:])) |
| 90 | os.close(fd) |
| 91 | cmd=[program,'@'+tmp] |
| 92 | ret=self.generator.bld.exec_command(cmd,**kw) |
| 93 | finally: |
| 94 | if tmp: |
| 95 | try: |
| 96 | os.remove(tmp) |
| 97 | except OSError: |
| 98 | pass |
| 99 | return ret |
| 100 | def quote_response_command(self,flag): |
| 101 | if flag.lower()=='/noconfig': |
| 102 | return'' |
| 103 | if flag.find(' ')>-1: |
| 104 | for x in('/r:','/reference:','/resource:','/lib:','/out:'): |
| 105 | if flag.startswith(x): |
| 106 | flag='%s"%s"'%(x,flag[len(x):]) |
| 107 | break |
| 108 | else: |
| 109 | flag='"%s"'%flag |
| 110 | return flag |
| 111 | def configure(conf): |
| 112 | csc=getattr(Options.options,'cscbinary',None) |
| 113 | if csc: |
| 114 | conf.env.MCS=csc |
| 115 | conf.find_program(['csc','mcs','gmcs'],var='MCS') |
| 116 | conf.env.ASS_ST='/r:%s' |
| 117 | conf.env.RES_ST='/resource:%s' |
| 118 | conf.env.CS_NAME='csc' |
| 119 | if str(conf.env.MCS).lower().find('mcs')>-1: |
| 120 | conf.env.CS_NAME='mono' |
| 121 | def options(opt): |
| 122 | opt.add_option('--with-csc-binary',type='string',dest='cscbinary') |
| 123 | class fake_csshlib(Task.Task): |
| 124 | color='YELLOW' |
| 125 | inst_to=None |
| 126 | def runnable_status(self): |
| 127 | for x in self.outputs: |
| 128 | x.sig=Utils.h_file(x.abspath()) |
| 129 | return Task.SKIP_ME |
| 130 | @conf |
| 131 | def read_csshlib(self,name,paths=[]): |
| 132 | return self(name=name,features='fake_lib',lib_paths=paths,lib_type='csshlib') |