1f5ab2074SBruce Richardson#! /usr/bin/env python3 2f5ab2074SBruce Richardson# SPDX-License-Identifier: BSD-3-Clause 3f5ab2074SBruce Richardson# Copyright(c) 2019 Intel Corporation 4f5ab2074SBruce Richardson# 5f5ab2074SBruce Richardson 6c946829eSThomas Monjalonimport filecmp 7c946829eSThomas Monjalonimport shutil 8f5ab2074SBruce Richardsonimport sys 9f5ab2074SBruce Richardsonimport os 10f5ab2074SBruce Richardsonfrom os.path import join 112af80739SChristian Ehrhardtfrom subprocess import run 12f5ab2074SBruce Richardson 136572fc92SBruce Richardson# assign parameters to variables 146572fc92SBruce Richardson(sphinx, version, src, dst, *extra_args) = sys.argv[1:] 15a4362f15SBruce Richardson 16a4362f15SBruce Richardson# set the version in environment for sphinx to pick up 17a4362f15SBruce Richardsonos.environ['DPDK_VERSION'] = version 187f932642SJuraj Linkešif 'dts' in src: 197f932642SJuraj Linkeš os.environ['DTS_DOC_BUILD'] = "y" 20f5ab2074SBruce Richardson 216572fc92SBruce Richardsonsphinx_cmd = [sphinx] + extra_args 22f5ab2074SBruce Richardson 23f5ab2074SBruce Richardson# find all the files sphinx will process so we can write them as dependencies 24f5ab2074SBruce Richardsonsrcfiles = [] 25f5ab2074SBruce Richardsonfor root, dirs, files in os.walk(src): 26f5ab2074SBruce Richardson srcfiles.extend([join(root, f) for f in files]) 27f5ab2074SBruce Richardson 28dfef8292SPaul Szczepanek# create destination path if not already present 29dfef8292SPaul Szczepanekos.makedirs(dst, exist_ok=True) 30dfef8292SPaul Szczepanek 31f5ab2074SBruce Richardson# run sphinx, putting the html output in a "html" directory 32e5feab93SBruce Richardsonwith open(join(dst, 'sphinx_html.out'), 'w') as out: 33*497cf548SPaul Szczepanek # don't append html dir if dst is already nested in a html dir 34*497cf548SPaul Szczepanek last_two_dirs = os.path.join(*os.path.normpath(dst).split(os.path.sep)[-2:]) 35*497cf548SPaul Szczepanek html_dst = dst if 'html' in last_two_dirs else join(dst, 'html') 36*497cf548SPaul Szczepanek process = run(sphinx_cmd + ['-b', 'html', src, html_dst], stdout=out) 37f5ab2074SBruce Richardson 38f5ab2074SBruce Richardson# create a gcc format .d file giving all the dependencies of this doc build 39f5ab2074SBruce Richardsonwith open(join(dst, '.html.d'), 'w') as d: 40f5ab2074SBruce Richardson d.write('html: ' + ' '.join(srcfiles) + '\n') 416572fc92SBruce Richardson 42c946829eSThomas Monjalon# copy custom CSS file 43c946829eSThomas Monjaloncss = 'custom.css' 44c946829eSThomas Monjalonsrc_css = join(src, css) 45*497cf548SPaul Szczepanekdst_css = join(html_dst, '_static', 'css', css) 46c946829eSThomas Monjalonif not os.path.exists(dst_css) or not filecmp.cmp(src_css, dst_css): 47c946829eSThomas Monjalon os.makedirs(os.path.dirname(dst_css), exist_ok=True) 48c946829eSThomas Monjalon shutil.copyfile(src_css, dst_css) 49c946829eSThomas Monjalon 506572fc92SBruce Richardsonsys.exit(process.returncode) 51