ctdb-daemon: Use ctdb_parse_node_address() in ctdbd
[samba4-gss.git] / third_party / waf / waflib / extras / haxe.py
blob4ff3745794d6d3e34ad22549e7df3ede855b0d6b
1 import re
3 from waflib import Utils, Task, Errors, Logs
4 from waflib.Configure import conf
5 from waflib.TaskGen import extension, taskgen_method
7 HAXE_COMPILERS = {
8 'JS': {'tgt': '--js', 'ext_out': ['.js']},
9 'LUA': {'tgt': '--lua', 'ext_out': ['.lua']},
10 'SWF': {'tgt': '--swf', 'ext_out': ['.swf']},
11 'NEKO': {'tgt': '--neko', 'ext_out': ['.n']},
12 'PHP': {'tgt': '--php', 'ext_out': ['.php']},
13 'CPP': {'tgt': '--cpp', 'ext_out': ['.h', '.cpp']},
14 'CPPIA': {'tgt': '--cppia', 'ext_out': ['.cppia']},
15 'CS': {'tgt': '--cs', 'ext_out': ['.cs']},
16 'JAVA': {'tgt': '--java', 'ext_out': ['.java']},
17 'JVM': {'tgt': '--jvm', 'ext_out': ['.jar']},
18 'PYTHON': {'tgt': '--python', 'ext_out': ['.py']},
19 'HL': {'tgt': '--hl', 'ext_out': ['.hl']},
20 'HLC': {'tgt': '--hl', 'ext_out': ['.h', '.c']},
23 @conf
24 def check_haxe_pkg(self, **kw):
25 self.find_program('haxelib')
26 libs = kw.get('libs')
27 if not libs or not (type(libs) == str or (type(libs) == list and all(isinstance(s, str) for s in libs))):
28 self.fatal('Specify correct libs value in ensure call')
29 return
30 fetch = kw.get('fetch')
31 if not fetch is None and not type(fetch) == bool:
32 self.fatal('Specify correct fetch value in ensure call')
34 libs = [libs] if type(libs) == str else libs
35 halt = False
36 for lib in libs:
37 try:
38 self.start_msg('Checking for library %s' % lib)
39 output = self.cmd_and_log(self.env.HAXELIB + ['list', lib])
40 except Errors.WafError:
41 self.end_msg(False)
42 self.fatal('Can\'t run haxelib list, ensuring halted')
43 return
45 if lib in output:
46 self.end_msg(lib in output)
47 else:
48 if not fetch:
49 self.end_msg(False)
50 halt = True
51 continue
52 try:
53 status = self.exec_command(self.env.HAXELIB + ['install', lib])
54 if status:
55 self.end_msg(False)
56 self.fatal('Can\'t get %s with haxelib, ensuring halted' % lib)
57 return
58 else:
59 self.end_msg('downloaded', color='YELLOW')
60 except Errors.WafError:
61 self.end_msg(False)
62 self.fatal('Can\'t run haxelib install, ensuring halted')
63 return
64 postfix = kw.get('uselib_store') or lib.upper()
65 self.env.append_unique('LIB_' + postfix, lib)
67 if halt:
68 self.fatal('Can\'t find libraries in haxelib list, ensuring halted')
69 return
71 class haxe(Task.Task):
72 vars = ['HAXE_VERSION', 'HAXE_FLAGS']
73 ext_in = ['.hx']
75 def run(self):
76 cmd = self.env.HAXE + self.env.HAXE_FLAGS_DEFAULT + self.env.HAXE_FLAGS
77 return self.exec_command(cmd)
79 for COMP in HAXE_COMPILERS:
80 # create runners for each compile target
81 type("haxe_" + COMP, (haxe,), {'ext_out': HAXE_COMPILERS[COMP]['ext_out']})
83 @taskgen_method
84 def init_haxe(self):
85 errmsg = '%s not found, specify correct value'
86 try:
87 compiler = HAXE_COMPILERS[self.compiler]
88 comp_tgt = compiler['tgt']
89 comp_mod = '/main.c' if self.compiler == 'HLC' else ''
90 except (AttributeError, KeyError):
91 self.bld.fatal(errmsg % 'COMPILER' + ': ' + ', '.join(HAXE_COMPILERS.keys()))
92 return
94 self.env.append_value(
95 'HAXE_FLAGS',
96 [comp_tgt, self.path.get_bld().make_node(self.target + comp_mod).abspath()])
97 if hasattr(self, 'use'):
98 if not (type(self.use) == str or type(self.use) == list):
99 self.bld.fatal(errmsg % 'USE')
100 return
101 self.use = [self.use] if type(self.use) == str else self.use
103 for dep in self.use:
104 if self.env['LIB_' + dep]:
105 for lib in self.env['LIB_' + dep]:
106 self.env.append_value('HAXE_FLAGS', ['-lib', lib])
108 if hasattr(self, 'res'):
109 if not type(self.res) == str:
110 self.bld.fatal(errmsg % 'RES')
111 return
112 self.env.append_value('HAXE_FLAGS', ['-D', 'resourcesPath=%s' % self.res])
114 @extension('.hx')
115 def haxe_hook(self, node):
116 if len(self.source) > 1:
117 self.bld.fatal('Use separate task generators for multiple files')
118 return
120 src = node
121 tgt = self.path.get_bld().find_or_declare(self.target)
123 self.init_haxe()
124 self.create_task('haxe_' + self.compiler, src, tgt)
126 @conf
127 def check_haxe(self, mini=None, maxi=None):
128 self.start_msg('Checking for haxe version')
129 try:
130 curr = re.search(
131 r'(\d+.?)+',
132 self.cmd_and_log(self.env.HAXE + ['-version'])).group()
133 except Errors.WafError:
134 self.end_msg(False)
135 self.fatal('Can\'t get haxe version')
136 return
138 if mini and Utils.num2ver(curr) < Utils.num2ver(mini):
139 self.end_msg('wrong', color='RED')
140 self.fatal('%s is too old, need >= %s' % (curr, mini))
141 return
142 if maxi and Utils.num2ver(curr) > Utils.num2ver(maxi):
143 self.end_msg('wrong', color='RED')
144 self.fatal('%s is too new, need <= %s' % (curr, maxi))
145 return
146 self.end_msg(curr, color='GREEN')
147 self.env.HAXE_VERSION = curr
149 def configure(self):
150 self.env.append_value(
151 'HAXE_FLAGS_DEFAULT',
152 ['-D', 'no-compilation', '-cp', self.path.abspath()])
153 Logs.warn('Default flags: %s' % ' '.join(self.env.HAXE_FLAGS_DEFAULT))
154 self.find_program('haxe')