bjam.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #! /usr/bin/env python
  2. # per rosengren 2011
  3. from os import sep, readlink
  4. from waflib import Logs
  5. from waflib.TaskGen import feature, after_method
  6. from waflib.Task import Task, always_run
  7. def options(opt):
  8. grp = opt.add_option_group('Bjam Options')
  9. grp.add_option('--bjam_src', default=None, help='You can find it in <boost root>/tools/jam/src')
  10. grp.add_option('--bjam_uname', default='linuxx86_64', help='bjam is built in <src>/bin.<uname>/bjam')
  11. grp.add_option('--bjam_config', default=None)
  12. grp.add_option('--bjam_toolset', default=None)
  13. def configure(cnf):
  14. if not cnf.env.BJAM_SRC:
  15. cnf.env.BJAM_SRC = cnf.options.bjam_src
  16. if not cnf.env.BJAM_UNAME:
  17. cnf.env.BJAM_UNAME = cnf.options.bjam_uname
  18. try:
  19. cnf.find_program('bjam', path_list=[
  20. cnf.env.BJAM_SRC + sep + 'bin.' + cnf.env.BJAM_UNAME
  21. ])
  22. except Exception:
  23. cnf.env.BJAM = None
  24. if not cnf.env.BJAM_CONFIG:
  25. cnf.env.BJAM_CONFIG = cnf.options.bjam_config
  26. if not cnf.env.BJAM_TOOLSET:
  27. cnf.env.BJAM_TOOLSET = cnf.options.bjam_toolset
  28. @feature('bjam')
  29. @after_method('process_rule')
  30. def process_bjam(self):
  31. if not self.bld.env.BJAM:
  32. self.create_task('bjam_creator')
  33. self.create_task('bjam_build')
  34. self.create_task('bjam_installer')
  35. if getattr(self, 'always', False):
  36. always_run(bjam_creator)
  37. always_run(bjam_build)
  38. always_run(bjam_installer)
  39. class bjam_creator(Task):
  40. ext_out = 'bjam_exe'
  41. vars=['BJAM_SRC', 'BJAM_UNAME']
  42. def run(self):
  43. env = self.env
  44. gen = self.generator
  45. bjam = gen.bld.root.find_dir(env.BJAM_SRC)
  46. if not bjam:
  47. Logs.error('Can not find bjam source')
  48. return -1
  49. bjam_exe_relpath = 'bin.' + env.BJAM_UNAME + '/bjam'
  50. bjam_exe = bjam.find_resource(bjam_exe_relpath)
  51. if bjam_exe:
  52. env.BJAM = bjam_exe.srcpath()
  53. return 0
  54. bjam_cmd = ['./build.sh']
  55. Logs.debug('runner: ' + bjam.srcpath() + '> ' + str(bjam_cmd))
  56. result = self.exec_command(bjam_cmd, cwd=bjam.srcpath())
  57. if not result == 0:
  58. Logs.error('bjam failed')
  59. return -1
  60. bjam_exe = bjam.find_resource(bjam_exe_relpath)
  61. if bjam_exe:
  62. env.BJAM = bjam_exe.srcpath()
  63. return 0
  64. Logs.error('bjam failed')
  65. return -1
  66. class bjam_build(Task):
  67. ext_in = 'bjam_exe'
  68. ext_out = 'install'
  69. vars = ['BJAM_TOOLSET']
  70. def run(self):
  71. env = self.env
  72. gen = self.generator
  73. path = gen.path
  74. bld = gen.bld
  75. if hasattr(gen, 'root'):
  76. build_root = path.find_node(gen.root)
  77. else:
  78. build_root = path
  79. jam = bld.srcnode.find_resource(env.BJAM_CONFIG)
  80. if jam:
  81. Logs.debug('bjam: Using jam configuration from ' + jam.srcpath())
  82. jam_rel = jam.relpath_gen(build_root)
  83. else:
  84. Logs.warn('No build configuration in build_config/user-config.jam. Using default')
  85. jam_rel = None
  86. bjam_exe = bld.srcnode.find_node(env.BJAM)
  87. if not bjam_exe:
  88. Logs.error('env.BJAM is not set')
  89. return -1
  90. bjam_exe_rel = bjam_exe.relpath_gen(build_root)
  91. cmd = ([bjam_exe_rel] +
  92. (['--user-config=' + jam_rel] if jam_rel else []) +
  93. ['--stagedir=' + path.get_bld().path_from(build_root)] +
  94. ['--debug-configuration'] +
  95. ['--with-' + lib for lib in self.generator.target] +
  96. (['toolset=' + env.BJAM_TOOLSET] if env.BJAM_TOOLSET else []) +
  97. ['link=' + 'shared'] +
  98. ['variant=' + 'release']
  99. )
  100. Logs.debug('runner: ' + build_root.srcpath() + '> ' + str(cmd))
  101. ret = self.exec_command(cmd, cwd=build_root.srcpath())
  102. if ret != 0:
  103. return ret
  104. self.set_outputs(path.get_bld().ant_glob('lib/*') + path.get_bld().ant_glob('bin/*'))
  105. return 0
  106. class bjam_installer(Task):
  107. ext_in = 'install'
  108. def run(self):
  109. gen = self.generator
  110. path = gen.path
  111. for idir, pat in (('${LIBDIR}', 'lib/*'), ('${BINDIR}', 'bin/*')):
  112. files = []
  113. for n in path.get_bld().ant_glob(pat):
  114. try:
  115. t = readlink(n.srcpath())
  116. gen.bld.symlink_as(sep.join([idir, n.name]), t, postpone=False)
  117. except OSError:
  118. files.append(n)
  119. gen.bld.install_files(idir, files, postpone=False)
  120. return 0