compiler_d.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. # Carlos Rafael Giani, 2007 (dv)
  4. # Thomas Nagy, 2016-2018 (ita)
  5. """
  6. Try to detect a D compiler from the list of supported compilers::
  7. def options(opt):
  8. opt.load('compiler_d')
  9. def configure(cnf):
  10. cnf.load('compiler_d')
  11. def build(bld):
  12. bld.program(source='main.d', target='app')
  13. Only three D compilers are really present at the moment:
  14. * gdc
  15. * dmd, the ldc compiler having a very similar command-line interface
  16. * ldc2
  17. """
  18. import re
  19. from waflib import Utils, Logs
  20. d_compiler = {
  21. 'default' : ['gdc', 'dmd', 'ldc2']
  22. }
  23. """
  24. Dict mapping the platform names to lists of names of D compilers to try, in order of preference::
  25. from waflib.Tools.compiler_d import d_compiler
  26. d_compiler['default'] = ['gdc', 'dmd', 'ldc2']
  27. """
  28. def default_compilers():
  29. build_platform = Utils.unversioned_sys_platform()
  30. possible_compiler_list = d_compiler.get(build_platform, d_compiler['default'])
  31. return ' '.join(possible_compiler_list)
  32. def configure(conf):
  33. """
  34. Detects a suitable D compiler
  35. :raises: :py:class:`waflib.Errors.ConfigurationError` when no suitable compiler is found
  36. """
  37. try:
  38. test_for_compiler = conf.options.check_d_compiler or default_compilers()
  39. except AttributeError:
  40. conf.fatal("Add options(opt): opt.load('compiler_d')")
  41. for compiler in re.split('[ ,]+', test_for_compiler):
  42. conf.env.stash()
  43. conf.start_msg('Checking for %r (D compiler)' % compiler)
  44. try:
  45. conf.load(compiler)
  46. except conf.errors.ConfigurationError as e:
  47. conf.env.revert()
  48. conf.end_msg(False)
  49. Logs.debug('compiler_d: %r', e)
  50. else:
  51. if conf.env.D:
  52. conf.end_msg(conf.env.get_flat('D'))
  53. conf.env.COMPILER_D = compiler
  54. conf.env.commit()
  55. break
  56. conf.env.revert()
  57. conf.end_msg(False)
  58. else:
  59. conf.fatal('could not configure a D compiler!')
  60. def options(opt):
  61. """
  62. This is how to provide compiler preferences on the command-line::
  63. $ waf configure --check-d-compiler=dmd
  64. """
  65. test_for_compiler = default_compilers()
  66. d_compiler_opts = opt.add_option_group('Configuration options')
  67. d_compiler_opts.add_option('--check-d-compiler', default=None,
  68. help='list of D compilers to try [%s]' % test_for_compiler, dest='check_d_compiler')
  69. for x in test_for_compiler.split():
  70. opt.load('%s' % x)