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.

121 lines
4.4KB

  1. """Support for Sphinx documentation
  2. This is a wrapper for sphinx-build program. Please note that sphinx-build supports only
  3. one output format at a time, but the tool can create multiple tasks to handle more.
  4. The output formats can be passed via the sphinx_output_format, which is an array of
  5. strings. For backwards compatibility if only one output is needed, it can be passed
  6. as a single string.
  7. The default output format is html.
  8. Specific formats can be installed in different directories by specifying the
  9. install_path_<FORMAT> attribute. If not defined, the standard install_path
  10. will be used instead.
  11. Example wscript:
  12. def configure(cnf):
  13. conf.load('sphinx')
  14. def build(bld):
  15. bld(
  16. features='sphinx',
  17. sphinx_source='sources', # path to source directory
  18. sphinx_options='-a -v', # sphinx-build program additional options
  19. sphinx_output_format=['html', 'man'], # output format of sphinx documentation
  20. install_path_man='${DOCDIR}/man' # put man pages in a specific directory
  21. )
  22. """
  23. from waflib.Node import Node
  24. from waflib import Utils
  25. from waflib import Task
  26. from waflib.TaskGen import feature, after_method
  27. def configure(cnf):
  28. """Check if sphinx-build program is available and loads gnu_dirs tool."""
  29. cnf.find_program('sphinx-build', var='SPHINX_BUILD', mandatory=False)
  30. cnf.load('gnu_dirs')
  31. @feature('sphinx')
  32. def build_sphinx(self):
  33. """Builds sphinx sources.
  34. """
  35. if not self.env.SPHINX_BUILD:
  36. self.bld.fatal('Program SPHINX_BUILD not defined.')
  37. if not getattr(self, 'sphinx_source', None):
  38. self.bld.fatal('Attribute sphinx_source not defined.')
  39. if not isinstance(self.sphinx_source, Node):
  40. self.sphinx_source = self.path.find_node(self.sphinx_source)
  41. if not self.sphinx_source:
  42. self.bld.fatal('Can\'t find sphinx_source: %r' % self.sphinx_source)
  43. # In the taskgen we have the complete list of formats
  44. Utils.def_attrs(self, sphinx_output_format='html')
  45. self.sphinx_output_format = Utils.to_list(self.sphinx_output_format)
  46. self.env.SPHINX_OPTIONS = getattr(self, 'sphinx_options', [])
  47. for source_file in self.sphinx_source.ant_glob('**/*'):
  48. self.bld.add_manual_dependency(self.sphinx_source, source_file)
  49. for cfmt in self.sphinx_output_format:
  50. sphinx_build_task = self.create_task('SphinxBuildingTask')
  51. sphinx_build_task.set_inputs(self.sphinx_source)
  52. # In task we keep the specific format this task is generating
  53. sphinx_build_task.env.SPHINX_OUTPUT_FORMAT = cfmt
  54. # the sphinx-build results are in <build + output_format> directory
  55. sphinx_build_task.sphinx_output_directory = self.path.get_bld().make_node(cfmt)
  56. sphinx_build_task.set_outputs(sphinx_build_task.sphinx_output_directory)
  57. sphinx_build_task.sphinx_output_directory.mkdir()
  58. Utils.def_attrs(sphinx_build_task, install_path=getattr(self, 'install_path_' + cfmt, getattr(self, 'install_path', get_install_path(sphinx_build_task))))
  59. def get_install_path(object):
  60. if object.env.SPHINX_OUTPUT_FORMAT == 'man':
  61. return object.env.MANDIR
  62. elif object.env.SPHINX_OUTPUT_FORMAT == 'info':
  63. return object.env.INFODIR
  64. else:
  65. return object.env.DOCDIR
  66. class SphinxBuildingTask(Task.Task):
  67. color = 'BOLD'
  68. run_str = '${SPHINX_BUILD} -M ${SPHINX_OUTPUT_FORMAT} ${SRC} ${TGT} -d ${TGT[0].bld_dir()}/doctrees-${SPHINX_OUTPUT_FORMAT} ${SPHINX_OPTIONS}'
  69. def keyword(self):
  70. return 'Compiling (%s)' % self.env.SPHINX_OUTPUT_FORMAT
  71. def runnable_status(self):
  72. for x in self.run_after:
  73. if not x.hasrun:
  74. return Task.ASK_LATER
  75. self.signature()
  76. ret = Task.Task.runnable_status(self)
  77. if ret == Task.SKIP_ME:
  78. # in case the files were removed
  79. self.add_install()
  80. return ret
  81. def post_run(self):
  82. self.add_install()
  83. return Task.Task.post_run(self)
  84. def add_install(self):
  85. nodes = self.sphinx_output_directory.ant_glob('**/*', quiet=True)
  86. self.outputs += nodes
  87. self.generator.add_install_files(install_to=self.install_path,
  88. install_from=nodes,
  89. postpone=False,
  90. cwd=self.sphinx_output_directory.make_node(self.env.SPHINX_OUTPUT_FORMAT),
  91. relative_trick=True)