blob: 8585352a4990b5ebe415ae16e993a227e262a2cd [file] [log] [blame]
Beichuan Zhang55b8ed42014-04-26 22:25:44 -07001# inspired by code by Hans-Martin von Gaudecker, 2012
Alexander Afanasyev49272f72014-04-06 21:49:46 -07002
3import os
4from waflib import Node, Task, TaskGen, Errors, Logs, Build, Utils
5
6class sphinx_build(Task.Task):
7 color = 'BLUE'
Beichuan Zhang55b8ed42014-04-26 22:25:44 -07008 run_str = '${SPHINX_BUILD} -D ${VERSION} -D ${RELEASE} -q -b ${BUILDERNAME} -d ${DOCTREEDIR} ${SRCDIR} ${OUTDIR}'
Alexander Afanasyev49272f72014-04-06 21:49:46 -07009
10 def __str__(self):
11 env = self.env
Alexander Afanasyev58ea4582014-05-30 08:38:56 +030012 src_str = ' '.join([a.path_from(a.ctx.launch_node()) for a in self.inputs])
13 tgt_str = ' '.join([a.path_from(a.ctx.launch_node()) for a in self.outputs])
Alexander Afanasyev49272f72014-04-06 21:49:46 -070014 if self.outputs: sep = ' -> '
15 else: sep = ''
16 return'%s [%s]: %s%s%s\n'%(self.__class__.__name__.replace('_task',''),
17 self.env['BUILDERNAME'], src_str, sep, tgt_str)
18
19@TaskGen.extension('.py', '.rst')
20def sig_hook(self, node):
21 node.sig=Utils.h_file(node.abspath())
22
23@TaskGen.feature("sphinx")
24@TaskGen.before_method("process_source")
25def apply_sphinx(self):
26 """Set up the task generator with a Sphinx instance and create a task."""
27
28 inputs = []
29 for i in Utils.to_list(self.source):
30 if not isinstance(i, Node.Node):
31 node = self.path.find_node(node)
32 else:
33 node = i
34 if not node:
35 raise ValueError('[%s] file not found' % i)
36 inputs.append(node)
37
38 task = self.create_task('sphinx_build', inputs)
39
40 conf = self.path.find_node(self.config)
41 task.inputs.append(conf)
42
43 confdir = conf.parent.abspath()
Davide Pesavento08b91c82019-04-13 19:42:10 -040044 buildername = getattr(self, 'builder', 'html')
45 srcdir = getattr(self, 'srcdir', confdir)
46 outdir = self.path.find_or_declare(getattr(self, 'outdir', buildername)).get_bld()
47 doctreedir = getattr(self, 'doctreedir', os.path.join(outdir.abspath(), '.doctrees'))
Alexander Afanasyev49272f72014-04-06 21:49:46 -070048
49 task.env['BUILDERNAME'] = buildername
50 task.env['SRCDIR'] = srcdir
51 task.env['DOCTREEDIR'] = doctreedir
52 task.env['OUTDIR'] = outdir.abspath()
Davide Pesavento08b91c82019-04-13 19:42:10 -040053 task.env['VERSION'] = 'version=%s' % self.version
54 task.env['RELEASE'] = 'release=%s' % getattr(self, 'release', self.version)
Alexander Afanasyev49272f72014-04-06 21:49:46 -070055
56 import imp
57 confData = imp.load_source('sphinx_conf', conf.abspath())
58
Davide Pesavento08b91c82019-04-13 19:42:10 -040059 if buildername == 'man':
Alexander Afanasyev49272f72014-04-06 21:49:46 -070060 for i in confData.man_pages:
61 target = outdir.find_or_declare('%s.%d' % (i[1], i[4]))
62 task.outputs.append(target)
63
64 if self.install_path:
Davide Pesavento08b91c82019-04-13 19:42:10 -040065 self.bld.install_files('%s/man%d/' % (self.install_path, i[4]), target)
Alexander Afanasyev49272f72014-04-06 21:49:46 -070066 else:
67 task.outputs.append(outdir)
68
69def configure(conf):
70 conf.find_program('sphinx-build', var='SPHINX_BUILD', mandatory=False)
71
72# sphinx docs
73from waflib.Build import BuildContext
74class sphinx(BuildContext):
75 cmd = "sphinx"
76 fun = "sphinx"