xref: /dpdk/buildtools/call-sphinx-build.py (revision 3cc6ecfdfe85d2577fef30e1791bb7534e3d60b3)
1#! /usr/bin/env python3
2# SPDX-License-Identifier: BSD-3-Clause
3# Copyright(c) 2019 Intel Corporation
4#
5
6import sys
7import os
8from os.path import join
9from subprocess import run, PIPE, STDOUT
10from distutils.version import StrictVersion
11
12(sphinx, version, src, dst) = sys.argv[1:]  # assign parameters to variables
13
14# set the version in environment for sphinx to pick up
15os.environ['DPDK_VERSION'] = version
16
17# for sphinx version >= 1.7 add parallelism using "-j auto"
18ver = run([sphinx, '--version'], stdout=PIPE,
19          stderr=STDOUT).stdout.decode().split()[-1]
20sphinx_cmd = [sphinx]
21if StrictVersion(ver) >= StrictVersion('1.7'):
22    sphinx_cmd += ['-j', 'auto']
23
24# find all the files sphinx will process so we can write them as dependencies
25srcfiles = []
26for root, dirs, files in os.walk(src):
27    srcfiles.extend([join(root, f) for f in files])
28
29# run sphinx, putting the html output in a "html" directory
30process = run(sphinx_cmd + ['-b', 'html', src, join(dst, 'html')], check=True)
31print(str(process.args) + ' Done OK')
32
33# create a gcc format .d file giving all the dependencies of this doc build
34with open(join(dst, '.html.d'), 'w') as d:
35    d.write('html: ' + ' '.join(srcfiles) + '\n')
36