jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
5.3KB

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