thirdparty:waf: New files for waf 1.9.10
[Samba.git] / third_party / waf / waflib / Tools / cs.py
blob0ac0ac317328b5016eaa95a578d4d007d1c73a6a
1 #! /usr/bin/env python
2 # encoding: utf-8
3 # WARNING! Do not edit! https://waf.io/book/index.html#_obtaining_the_waf_file
5 #!/usr/bin/env python
6 # encoding: utf-8
7 # Thomas Nagy, 2006-2016 (ita)
9 """
10 C# support. A simple example::
12 def configure(conf):
13 conf.load('cs')
14 def build(bld):
15 bld(features='cs', source='main.cs', gen='foo')
17 Note that the configuration may compile C# snippets::
19 FRAG = '''
20 namespace Moo {
21 public class Test { public static int Main(string[] args) { return 0; } }
22 }'''
23 def configure(conf):
24 conf.check(features='cs', fragment=FRAG, compile_filename='test.cs', gen='test.exe',
25 bintype='exe', csflags=['-pkg:gtk-sharp-2.0'], msg='Checking for Gtksharp support')
26 """
28 from waflib import Utils, Task, Options, Errors
29 from waflib.TaskGen import before_method, after_method, feature
30 from waflib.Tools import ccroot
31 from waflib.Configure import conf
33 ccroot.USELIB_VARS['cs'] = set(['CSFLAGS', 'ASSEMBLIES', 'RESOURCES'])
34 ccroot.lib_patterns['csshlib'] = ['%s']
36 @feature('cs')
37 @before_method('process_source')
38 def apply_cs(self):
39 """
40 Create a C# task bound to the attribute *cs_task*. There can be only one C# task by task generator.
41 """
42 cs_nodes = []
43 no_nodes = []
44 for x in self.to_nodes(self.source):
45 if x.name.endswith('.cs'):
46 cs_nodes.append(x)
47 else:
48 no_nodes.append(x)
49 self.source = no_nodes
51 bintype = getattr(self, 'bintype', self.gen.endswith('.dll') and 'library' or 'exe')
52 self.cs_task = tsk = self.create_task('mcs', cs_nodes, self.path.find_or_declare(self.gen))
53 tsk.env.CSTYPE = '/target:%s' % bintype
54 tsk.env.OUT = '/out:%s' % tsk.outputs[0].abspath()
55 self.env.append_value('CSFLAGS', '/platform:%s' % getattr(self, 'platform', 'anycpu'))
57 inst_to = getattr(self, 'install_path', bintype=='exe' and '${BINDIR}' or '${LIBDIR}')
58 if inst_to:
59 # note: we are making a copy, so the files added to cs_task.outputs won't be installed automatically
60 mod = getattr(self, 'chmod', bintype=='exe' and Utils.O755 or Utils.O644)
61 self.install_task = self.add_install_files(install_to=inst_to, install_from=self.cs_task.outputs[:], chmod=mod)
63 @feature('cs')
64 @after_method('apply_cs')
65 def use_cs(self):
66 """
67 C# applications honor the **use** keyword::
69 def build(bld):
70 bld(features='cs', source='My.cs', bintype='library', gen='my.dll', name='mylib')
71 bld(features='cs', source='Hi.cs', includes='.', bintype='exe', gen='hi.exe', use='mylib', name='hi')
72 """
73 names = self.to_list(getattr(self, 'use', []))
74 get = self.bld.get_tgen_by_name
75 for x in names:
76 try:
77 y = get(x)
78 except Errors.WafError:
79 self.env.append_value('CSFLAGS', '/reference:%s' % x)
80 continue
81 y.post()
83 tsk = getattr(y, 'cs_task', None) or getattr(y, 'link_task', None)
84 if not tsk:
85 self.bld.fatal('cs task has no link task for use %r' % self)
86 self.cs_task.dep_nodes.extend(tsk.outputs) # dependency
87 self.cs_task.set_run_after(tsk) # order (redundant, the order is inferred from the nodes inputs/outputs)
88 self.env.append_value('CSFLAGS', '/reference:%s' % tsk.outputs[0].abspath())
90 @feature('cs')
91 @after_method('apply_cs', 'use_cs')
92 def debug_cs(self):
93 """
94 The C# targets may create .mdb or .pdb files::
96 def build(bld):
97 bld(features='cs', source='My.cs', bintype='library', gen='my.dll', csdebug='full')
98 # csdebug is a value in (True, 'full', 'pdbonly')
99 """
100 csdebug = getattr(self, 'csdebug', self.env.CSDEBUG)
101 if not csdebug:
102 return
104 node = self.cs_task.outputs[0]
105 if self.env.CS_NAME == 'mono':
106 out = node.parent.find_or_declare(node.name + '.mdb')
107 else:
108 out = node.change_ext('.pdb')
109 self.cs_task.outputs.append(out)
110 try:
111 self.install_task.source.append(out)
112 except AttributeError:
113 pass
115 if csdebug == 'pdbonly':
116 val = ['/debug+', '/debug:pdbonly']
117 elif csdebug == 'full':
118 val = ['/debug+', '/debug:full']
119 else:
120 val = ['/debug-']
121 self.env.append_value('CSFLAGS', val)
124 class mcs(Task.Task):
126 Compile C# files
128 color = 'YELLOW'
129 run_str = '${MCS} ${CSTYPE} ${CSFLAGS} ${ASS_ST:ASSEMBLIES} ${RES_ST:RESOURCES} ${OUT} ${SRC}'
131 def exec_command(self, cmd, **kw):
132 if '/noconfig' in cmd:
133 raise ValueError('/noconfig is not allowed when using response files, check your flags!')
134 return super(self.__class__, self).exec_command(cmd, **kw)
136 def configure(conf):
138 Find a C# compiler, set the variable MCS for the compiler and CS_NAME (mono or csc)
140 csc = getattr(Options.options, 'cscbinary', None)
141 if csc:
142 conf.env.MCS = csc
143 conf.find_program(['csc', 'mcs', 'gmcs'], var='MCS')
144 conf.env.ASS_ST = '/r:%s'
145 conf.env.RES_ST = '/resource:%s'
147 conf.env.CS_NAME = 'csc'
148 if str(conf.env.MCS).lower().find('mcs') > -1:
149 conf.env.CS_NAME = 'mono'
151 def options(opt):
153 Add a command-line option for the configuration::
155 $ waf configure --with-csc-binary=/foo/bar/mcs
157 opt.add_option('--with-csc-binary', type='string', dest='cscbinary')
159 class fake_csshlib(Task.Task):
161 Task used for reading a foreign .net assembly and adding the dependency on it
163 color = 'YELLOW'
164 inst_to = None
166 def runnable_status(self):
167 return Task.SKIP_ME
169 @conf
170 def read_csshlib(self, name, paths=[]):
172 Read a foreign .net assembly for the *use* system::
174 def build(bld):
175 bld.read_csshlib('ManagedLibrary.dll', paths=[bld.env.mylibrarypath])
176 bld(features='cs', source='Hi.cs', bintype='exe', gen='hi.exe', use='ManagedLibrary.dll')
178 :param name: Name of the library
179 :type name: string
180 :param paths: Folders in which the library may be found
181 :type paths: list of string
182 :return: A task generator having the feature *fake_lib* which will call :py:func:`waflib.Tools.ccroot.process_lib`
183 :rtype: :py:class:`waflib.TaskGen.task_gen`
185 return self(name=name, features='fake_lib', lib_paths=paths, lib_type='csshlib')