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 18 19sphinx_cmd = [sphinx] + extra_args 20 21# find all the files sphinx will process so we can write them as dependencies 22srcfiles = [] 23for root, dirs, files in os.walk(src): 24 srcfiles.extend([join(root, f) for f in files]) 25 26# run sphinx, putting the html output in a "html" directory 27with open(join(dst, 'sphinx_html.out'), 'w') as out: 28 process = run(sphinx_cmd + ['-b', 'html', src, join(dst, 'html')], 29 stdout=out) 30 31# create a gcc format .d file giving all the dependencies of this doc build 32with open(join(dst, '.html.d'), 'w') as d: 33 d.write('html: ' + ' '.join(srcfiles) + '\n') 34 35# copy custom CSS file 36css = 'custom.css' 37src_css = join(src, css) 38dst_css = join(dst, 'html', '_static', 'css', css) 39if not os.path.exists(dst_css) or not filecmp.cmp(src_css, dst_css): 40 os.makedirs(os.path.dirname(dst_css), exist_ok=True) 41 shutil.copyfile(src_css, dst_css) 42 43sys.exit(process.returncode) 44