From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1851) id 4F4793858403; Mon, 7 Nov 2022 21:08:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4F4793858403 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667855281; bh=EFmVmpfBdSUl/MdBoK1zNr9IbI5HbKsQ3h7YvomK41U=; h=From:To:Subject:Date:From; b=wuSnKUmzA1GFEgaYsbcDLhQ1M64aY7N/ZBvdy9lv656ZX/ZGvakFbeygsnlOha/wT tYs6G5fvD4ZRq8+kRFkhPj0k4TCnUElE2Oj+k3AYw7Aovt25HF+kE1ygrsKorAcmlW OWTd5NBX5ICVDc3VEcjcizL1bbiuVM2ZqejtYpJY= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Martin Liska To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/marxin/heads/sphinx-final)] sphinx: add update_web_docs_git.py script X-Act-Checkin: gcc X-Git-Author: Martin Liska X-Git-Refname: refs/users/marxin/heads/sphinx-final X-Git-Oldrev: d960b0d090bfc8456340422f2ef18cc7c11f5674 X-Git-Newrev: 8654f8e76a9b6700762f97b0445d599655d7e491 Message-Id: <20221107210801.4F4793858403@sourceware.org> Date: Mon, 7 Nov 2022 21:08:01 +0000 (GMT) List-Id: https://gcc.gnu.org/g:8654f8e76a9b6700762f97b0445d599655d7e491 commit 8654f8e76a9b6700762f97b0445d599655d7e491 Author: Martin Liska Date: Mon Nov 7 22:07:47 2022 +0100 sphinx: add update_web_docs_git.py script maintainer-scripts/ChangeLog: * update_web_docs_git.py: New file. Diff: --- maintainer-scripts/update_web_docs_git.py | 75 +++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/maintainer-scripts/update_web_docs_git.py b/maintainer-scripts/update_web_docs_git.py new file mode 100755 index 00000000000..81fe22087f1 --- /dev/null +++ b/maintainer-scripts/update_web_docs_git.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python3 + +# Generate documentation from Sphinx files. + +import argparse +import os +import shutil +import subprocess +import tempfile +from pathlib import Path + +GITROOT = '/git/gcc.git' +BUGURL = 'https://gcc.gnu.org/bugs/' + +parser = argparse.ArgumentParser(description='Update web documentation.') +parser.add_argument('output_folder', help='Output folder') +parser.add_argument('--gitrepo', help='Git repository', default=GITROOT) +args = parser.parse_args() + + +def find_configs(): + for root, _, files in os.walk('.'): + for f in files: + full = os.path.join(root, f) + if f == 'conf.py': + # find name of the documentation + lines = open(full).read().splitlines() + docname = None + for line in lines: + if line.startswith('name = '): + docname = line.split()[-1].strip("'") + break + assert docname + yield (Path(root).resolve(), docname) + + +with tempfile.TemporaryDirectory() as folder: + print(f'Using {folder} as temporary directory') + os.chdir(folder) + subprocess.check_output(f'git clone {args.gitrepo} --depth=1', shell=True) + # TODO: remove + os.chdir('gcc') + cmd = 'git fetch origin refs/users/marxin/heads/sphinx-final --depth=1' + subprocess.check_output(cmd, shell=True) + subprocess.check_output('git checkout FETCH_HEAD', shell=True) + configs = list(find_configs()) + + # Prepare folders + output = Path(args.output_folder) + if not output.exists(): + output.mkdir() + + temp = Path('tmp').resolve() + temp.mkdir() + + # Prepare default env. variables + childenv = os.environ.copy() + childenv['BUGURL'] = BUGURL + + # Build and copy the documentation + for config_folder, docname in sorted(configs): + print('=== BUILDING:', config_folder, docname, '===') + + # Build HTML + cmd = f'make -C doc html SOURCEDIR={config_folder} BUILDDIR={temp}/{docname}' + subprocess.check_output(cmd, shell=True, env=childenv) + os.unlink(f'{temp}/{docname}/html/.buildinfo') + shutil.copytree(f'{temp}/{docname}/html', f'{output}/{docname}', + dirs_exist_ok=True) + + # Build PDF + cmd = f'make -C doc latexpdf SOURCEDIR={config_folder} BUILDDIR={temp}/pdf/{docname}' + subprocess.check_output(cmd, shell=True, env=childenv) + shutil.copyfile(f'{temp}/pdf/{docname}/latex/{docname}.pdf', + f'{output}/{docname}.pdf')