valadoc.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #! /usr/bin/env python
  2. # encoding: UTF-8
  3. # Nicolas Joseph 2009
  4. """
  5. ported from waf 1.5:
  6. TODO: tabs vs spaces
  7. """
  8. from waflib import Task, Utils, Errors, Logs
  9. from waflib.TaskGen import feature
  10. VALADOC_STR = '${VALADOC}'
  11. class valadoc(Task.Task):
  12. vars = ['VALADOC', 'VALADOCFLAGS']
  13. color = 'BLUE'
  14. after = ['cprogram', 'cstlib', 'cshlib', 'cxxprogram', 'cxxstlib', 'cxxshlib']
  15. quiet = True # no outputs .. this is weird
  16. def __init__(self, *k, **kw):
  17. Task.Task.__init__(self, *k, **kw)
  18. self.output_dir = ''
  19. self.doclet = ''
  20. self.package_name = ''
  21. self.package_version = ''
  22. self.files = []
  23. self.vapi_dirs = []
  24. self.protected = True
  25. self.private = False
  26. self.inherit = False
  27. self.deps = False
  28. self.vala_defines = []
  29. self.vala_target_glib = None
  30. self.enable_non_null_experimental = False
  31. self.force = False
  32. def run(self):
  33. if not self.env['VALADOCFLAGS']:
  34. self.env['VALADOCFLAGS'] = ''
  35. cmd = [Utils.subst_vars(VALADOC_STR, self.env)]
  36. cmd.append ('-o %s' % self.output_dir)
  37. if getattr(self, 'doclet', None):
  38. cmd.append ('--doclet %s' % self.doclet)
  39. cmd.append ('--package-name %s' % self.package_name)
  40. if getattr(self, 'package_version', None):
  41. cmd.append ('--package-version %s' % self.package_version)
  42. if getattr(self, 'packages', None):
  43. for package in self.packages:
  44. cmd.append ('--pkg %s' % package)
  45. if getattr(self, 'vapi_dirs', None):
  46. for vapi_dir in self.vapi_dirs:
  47. cmd.append ('--vapidir %s' % vapi_dir)
  48. if not getattr(self, 'protected', None):
  49. cmd.append ('--no-protected')
  50. if getattr(self, 'private', None):
  51. cmd.append ('--private')
  52. if getattr(self, 'inherit', None):
  53. cmd.append ('--inherit')
  54. if getattr(self, 'deps', None):
  55. cmd.append ('--deps')
  56. if getattr(self, 'vala_defines', None):
  57. for define in self.vala_defines:
  58. cmd.append ('--define %s' % define)
  59. if getattr(self, 'vala_target_glib', None):
  60. cmd.append ('--target-glib=%s' % self.vala_target_glib)
  61. if getattr(self, 'enable_non_null_experimental', None):
  62. cmd.append ('--enable-non-null-experimental')
  63. if getattr(self, 'force', None):
  64. cmd.append ('--force')
  65. cmd.append (' '.join ([x.abspath() for x in self.files]))
  66. return self.generator.bld.exec_command(' '.join(cmd))
  67. @feature('valadoc')
  68. def process_valadoc(self):
  69. """
  70. Generate API documentation from Vala source code with valadoc
  71. doc = bld(
  72. features = 'valadoc',
  73. output_dir = '../doc/html',
  74. package_name = 'vala-gtk-example',
  75. package_version = '1.0.0',
  76. packages = 'gtk+-2.0',
  77. vapi_dirs = '../vapi',
  78. force = True
  79. )
  80. path = bld.path.find_dir ('../src')
  81. doc.files = path.ant_glob (incl='**/*.vala')
  82. """
  83. task = self.create_task('valadoc')
  84. if getattr(self, 'output_dir', None):
  85. task.output_dir = self.path.find_or_declare(self.output_dir).abspath()
  86. else:
  87. Errors.WafError('no output directory')
  88. if getattr(self, 'doclet', None):
  89. task.doclet = self.doclet
  90. else:
  91. Errors.WafError('no doclet directory')
  92. if getattr(self, 'package_name', None):
  93. task.package_name = self.package_name
  94. else:
  95. Errors.WafError('no package name')
  96. if getattr(self, 'package_version', None):
  97. task.package_version = self.package_version
  98. if getattr(self, 'packages', None):
  99. task.packages = Utils.to_list(self.packages)
  100. if getattr(self, 'vapi_dirs', None):
  101. vapi_dirs = Utils.to_list(self.vapi_dirs)
  102. for vapi_dir in vapi_dirs:
  103. try:
  104. task.vapi_dirs.append(self.path.find_dir(vapi_dir).abspath())
  105. except AttributeError:
  106. Logs.warn('Unable to locate Vala API directory: %r', vapi_dir)
  107. if getattr(self, 'files', None):
  108. task.files = self.files
  109. else:
  110. Errors.WafError('no input file')
  111. if getattr(self, 'protected', None):
  112. task.protected = self.protected
  113. if getattr(self, 'private', None):
  114. task.private = self.private
  115. if getattr(self, 'inherit', None):
  116. task.inherit = self.inherit
  117. if getattr(self, 'deps', None):
  118. task.deps = self.deps
  119. if getattr(self, 'vala_defines', None):
  120. task.vala_defines = Utils.to_list(self.vala_defines)
  121. if getattr(self, 'vala_target_glib', None):
  122. task.vala_target_glib = self.vala_target_glib
  123. if getattr(self, 'enable_non_null_experimental', None):
  124. task.enable_non_null_experimental = self.enable_non_null_experimental
  125. if getattr(self, 'force', None):
  126. task.force = self.force
  127. def configure(conf):
  128. conf.find_program('valadoc', errmsg='You must install valadoc <http://live.gnome.org/Valadoc> for generate the API documentation')