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.

157 lines
5.2KB

  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. # Anton Feldmann, 2012
  4. # "Base for cabal"
  5. import re
  6. import time
  7. from waflib import TaskGen, Task, Utils
  8. from waflib.Configure import conf
  9. from waflib.Task import always_run
  10. from waflib.TaskGen import extension, feature, after, before, before_method
  11. from waflib.Utils import threading
  12. from shutil import rmtree
  13. lock = threading.Lock()
  14. registering = False
  15. def configure(self):
  16. self.find_program('cabal', var='CABAL')
  17. self.find_program('ghc-pkg', var='GHCPKG')
  18. pkgconfd = self.bldnode.abspath() + '/package.conf.d'
  19. self.env.PREFIX = self.bldnode.abspath() + '/dist'
  20. self.env.PKGCONFD = pkgconfd
  21. if self.root.find_node(pkgconfd + '/package.cache'):
  22. self.msg('Using existing package database', pkgconfd, color='CYAN')
  23. else:
  24. pkgdir = self.root.find_dir(pkgconfd)
  25. if pkgdir:
  26. self.msg('Deleting corrupt package database', pkgdir.abspath(), color ='RED')
  27. rmtree(pkgdir.abspath())
  28. pkgdir = None
  29. self.cmd_and_log(self.env.GHCPKG + ['init', pkgconfd])
  30. self.msg('Created package database', pkgconfd, color = 'YELLOW' if pkgdir else 'GREEN')
  31. @extension('.cabal')
  32. def process_cabal(self, node):
  33. out_dir_node = self.bld.root.find_dir(self.bld.out_dir)
  34. package_node = node.change_ext('.package')
  35. package_node = out_dir_node.find_or_declare(package_node.name)
  36. build_node = node.parent.get_bld()
  37. build_path = build_node.abspath()
  38. config_node = build_node.find_or_declare('setup-config')
  39. inplace_node = build_node.find_or_declare('package.conf.inplace')
  40. config_task = self.create_task('cabal_configure', node)
  41. config_task.cwd = node.parent.abspath()
  42. config_task.depends_on = getattr(self, 'depends_on', '')
  43. config_task.build_path = build_path
  44. config_task.set_outputs(config_node)
  45. build_task = self.create_task('cabal_build', config_node)
  46. build_task.cwd = node.parent.abspath()
  47. build_task.build_path = build_path
  48. build_task.set_outputs(inplace_node)
  49. copy_task = self.create_task('cabal_copy', inplace_node)
  50. copy_task.cwd = node.parent.abspath()
  51. copy_task.depends_on = getattr(self, 'depends_on', '')
  52. copy_task.build_path = build_path
  53. last_task = copy_task
  54. task_list = [config_task, build_task, copy_task]
  55. if (getattr(self, 'register', False)):
  56. register_task = self.create_task('cabal_register', inplace_node)
  57. register_task.cwd = node.parent.abspath()
  58. register_task.set_run_after(copy_task)
  59. register_task.build_path = build_path
  60. pkgreg_task = self.create_task('ghcpkg_register', inplace_node)
  61. pkgreg_task.cwd = node.parent.abspath()
  62. pkgreg_task.set_run_after(register_task)
  63. pkgreg_task.build_path = build_path
  64. last_task = pkgreg_task
  65. task_list += [register_task, pkgreg_task]
  66. touch_task = self.create_task('cabal_touch', inplace_node)
  67. touch_task.set_run_after(last_task)
  68. touch_task.set_outputs(package_node)
  69. touch_task.build_path = build_path
  70. task_list += [touch_task]
  71. return task_list
  72. def get_all_src_deps(node):
  73. hs_deps = node.ant_glob('**/*.hs')
  74. hsc_deps = node.ant_glob('**/*.hsc')
  75. lhs_deps = node.ant_glob('**/*.lhs')
  76. c_deps = node.ant_glob('**/*.c')
  77. cpp_deps = node.ant_glob('**/*.cpp')
  78. proto_deps = node.ant_glob('**/*.proto')
  79. return sum([hs_deps, hsc_deps, lhs_deps, c_deps, cpp_deps, proto_deps], [])
  80. class Cabal(Task.Task):
  81. def scan(self):
  82. return (get_all_src_deps(self.generator.path), ())
  83. class cabal_configure(Cabal):
  84. run_str = '${CABAL} configure -v0 --prefix=${PREFIX} --global --user --package-db=${PKGCONFD} --builddir=${tsk.build_path}'
  85. shell = True
  86. def scan(self):
  87. out_node = self.generator.bld.root.find_dir(self.generator.bld.out_dir)
  88. deps = [out_node.find_or_declare(dep).change_ext('.package') for dep in Utils.to_list(self.depends_on)]
  89. return (deps, ())
  90. class cabal_build(Cabal):
  91. run_str = '${CABAL} build -v1 --builddir=${tsk.build_path}/'
  92. shell = True
  93. class cabal_copy(Cabal):
  94. run_str = '${CABAL} copy -v0 --builddir=${tsk.build_path}'
  95. shell = True
  96. class cabal_register(Cabal):
  97. run_str = '${CABAL} register -v0 --gen-pkg-config=${tsk.build_path}/pkg.config --builddir=${tsk.build_path}'
  98. shell = True
  99. class ghcpkg_register(Cabal):
  100. run_str = '${GHCPKG} update -v0 --global --user --package-conf=${PKGCONFD} ${tsk.build_path}/pkg.config'
  101. shell = True
  102. def runnable_status(self):
  103. global lock, registering
  104. val = False
  105. lock.acquire()
  106. val = registering
  107. lock.release()
  108. if val:
  109. return Task.ASK_LATER
  110. ret = Task.Task.runnable_status(self)
  111. if ret == Task.RUN_ME:
  112. lock.acquire()
  113. registering = True
  114. lock.release()
  115. return ret
  116. def post_run(self):
  117. global lock, registering
  118. lock.acquire()
  119. registering = False
  120. lock.release()
  121. return Task.Task.post_run(self)
  122. class cabal_touch(Cabal):
  123. run_str = 'touch ${TGT}'