blob: b44a54f4ed5ffbaf650ecc2ce75d5457f9160e2d [file] [log] [blame]
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -08001#!/usr/bin/env python
2# encoding: utf-8
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -08003
Alexander Afanasyev1160baa2014-04-10 18:50:29 -07004# inspired by code by Hans-Martin von Gaudecker, 2012
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -08005
6import os
Alexander Afanasyev1160baa2014-04-10 18:50:29 -07007from waflib import Node, Task, TaskGen, Errors, Logs, Build, Utils
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -08008
Alexander Afanasyev1160baa2014-04-10 18:50:29 -07009class sphinx_build(Task.Task):
10 color = 'BLUE'
Alexander Afanasyeva06fdda2014-04-29 19:15:00 -070011 run_str = '${SPHINX_BUILD} -D ${VERSION} -D ${RELEASE} -q -b ${BUILDERNAME} -d ${DOCTREEDIR} ${SRCDIR} ${OUTDIR}'
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080012
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070013 def __str__(self):
14 env = self.env
Alexander Afanasyev8b1674a2014-05-15 00:58:43 -070015 src_str = ' '.join([a.path_from(a.ctx.launch_node()) for a in self.inputs])
16 tgt_str = ' '.join([a.path_from(a.ctx.launch_node()) for a in self.outputs])
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070017 if self.outputs: sep = ' -> '
18 else: sep = ''
19 return'%s [%s]: %s%s%s\n'%(self.__class__.__name__.replace('_task',''),
20 self.env['BUILDERNAME'], src_str, sep, tgt_str)
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080021
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070022@TaskGen.extension('.py', '.rst')
23def sig_hook(self, node):
24 node.sig=Utils.h_file(node.abspath())
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080025
26@TaskGen.feature("sphinx")
27@TaskGen.before_method("process_source")
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070028def apply_sphinx(self):
29 """Set up the task generator with a Sphinx instance and create a task."""
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080030
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070031 inputs = []
32 for i in Utils.to_list(self.source):
33 if not isinstance(i, Node.Node):
34 node = self.path.find_node(node)
35 else:
36 node = i
37 if not node:
38 raise ValueError('[%s] file not found' % i)
39 inputs.append(node)
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080040
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070041 task = self.create_task('sphinx_build', inputs)
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070042
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070043 conf = self.path.find_node(self.config)
44 task.inputs.append(conf)
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080045
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070046 confdir = conf.parent.abspath()
Davide Pesaventob310efb2019-04-11 22:10:24 -040047 buildername = getattr(self, 'builder', 'html')
48 srcdir = getattr(self, 'srcdir', confdir)
49 outdir = self.path.find_or_declare(getattr(self, 'outdir', buildername)).get_bld()
50 doctreedir = getattr(self, 'doctreedir', os.path.join(outdir.abspath(), '.doctrees'))
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080051
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070052 task.env['BUILDERNAME'] = buildername
53 task.env['SRCDIR'] = srcdir
54 task.env['DOCTREEDIR'] = doctreedir
55 task.env['OUTDIR'] = outdir.abspath()
Davide Pesaventob310efb2019-04-11 22:10:24 -040056 task.env['VERSION'] = 'version=%s' % self.version
57 task.env['RELEASE'] = 'release=%s' % getattr(self, 'release', self.version)
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080058
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070059 import imp
60 confData = imp.load_source('sphinx_conf', conf.abspath())
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080061
Davide Pesaventob310efb2019-04-11 22:10:24 -040062 if buildername == 'man':
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070063 for i in confData.man_pages:
64 target = outdir.find_or_declare('%s.%d' % (i[1], i[4]))
65 task.outputs.append(target)
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080066
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070067 if self.install_path:
Davide Pesaventob310efb2019-04-11 22:10:24 -040068 self.bld.install_files('%s/man%d/' % (self.install_path, i[4]), target)
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070069 else:
70 task.outputs.append(outdir)
71
72def configure(conf):
73 conf.find_program('sphinx-build', var='SPHINX_BUILD', mandatory=False)
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070074
75# sphinx docs
76from waflib.Build import BuildContext
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070077class sphinx(BuildContext):
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070078 cmd = "sphinx"
79 fun = "sphinx"