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# create destination path if not already present 29os.makedirs(dst, exist_ok=True) 30 31# run sphinx, putting the html output in a "html" directory 32with open(join(dst, 'sphinx_html.out'), 'w') as out: 33 # don't append html dir if dst is already nested in a html dir 34 last_two_dirs = os.path.join(*os.path.normpath(dst).split(os.path.sep)[-2:]) 35 html_dst = dst if 'html' in last_two_dirs else join(dst, 'html') 36 process = run(sphinx_cmd + ['-b', 'html', src, html_dst], stdout=out) 37 38# create a gcc format .d file giving all the dependencies of this doc build 39with open(join(dst, '.html.d'), 'w') as d: 40 d.write('html: ' + ' '.join(srcfiles) + '\n') 41 42# copy custom CSS file 43css = 'custom.css' 44src_css = join(src, css) 45dst_css = join(html_dst, '_static', 'css', css) 46if not os.path.exists(dst_css) or not filecmp.cmp(src_css, dst_css): 47 os.makedirs(os.path.dirname(dst_css), exist_ok=True) 48 shutil.copyfile(src_css, dst_css) 49 50sys.exit(process.returncode) 51