xref: /dpdk/buildtools/call-sphinx-build.py (revision 21a66096bb44a4468353782c36fc85913520dc6c)
1#! /usr/bin/env python3
2# SPDX-License-Identifier: BSD-3-Clause
3# Copyright(c) 2019 Intel Corporation
4#
5
6import filecmp
7import shutil
8import sys
9import os
10from os.path import join
11from subprocess import run
12
13# assign parameters to variables
14(sphinx, version, src, dst, *extra_args) = sys.argv[1:]
15
16# set the version in environment for sphinx to pick up
17os.environ['DPDK_VERSION'] = version
18if 'dts' in src:
19    os.environ['DTS_DOC_BUILD'] = "y"
20
21sphinx_cmd = [sphinx] + extra_args
22
23# find all the files sphinx will process so we can write them as dependencies
24srcfiles = []
25for root, dirs, files in os.walk(src):
26    srcfiles.extend([join(root, f) for f in files])
27
28# run sphinx, putting the html output in a "html" directory
29with open(join(dst, 'sphinx_html.out'), 'w') as out:
30    process = run(sphinx_cmd + ['-b', 'html', src, join(dst, 'html')],
31                  stdout=out)
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
37# copy custom CSS file
38css = 'custom.css'
39src_css = join(src, css)
40dst_css = join(dst, 'html', '_static', 'css', css)
41if not os.path.exists(dst_css) or not filecmp.cmp(src_css, dst_css):
42    os.makedirs(os.path.dirname(dst_css), exist_ok=True)
43    shutil.copyfile(src_css, dst_css)
44
45sys.exit(process.returncode)
46