|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# |
| 3 | +# InspIRCd -- Internet Relay Chat Daemon |
| 4 | +# |
| 5 | +# Copyright (C) 2022 Sadie Powell <[email protected]> |
| 6 | +# |
| 7 | +# This file is part of InspIRCd. InspIRCd is free software: you can |
| 8 | +# redistribute it and/or modify it under the terms of the GNU General Public |
| 9 | +# License as published by the Free Software Foundation, version 2. |
| 10 | +# |
| 11 | +# This program is distributed in the hope that it will be useful, but WITHOUT |
| 12 | +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 13 | +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 14 | +# details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU General Public License |
| 17 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | +# |
| 19 | + |
| 20 | + |
| 21 | +import os |
| 22 | +import re |
| 23 | +import shutil |
| 24 | +import subprocess |
| 25 | +import sys |
| 26 | +import tempfile |
| 27 | + |
| 28 | +CC_BOLD = "\x1B[1m" if sys.stdout.isatty() else '' |
| 29 | +CC_RED = "\x1B[1;31m" if sys.stdout.isatty() else '' |
| 30 | +CC_RESET = "\x1B[0m" if sys.stdout.isatty() else '' |
| 31 | + |
| 32 | +# INSPIRCD_BRANCHES contains a space-delimited list of git branch names. |
| 33 | +INSPIRCD_BRANCHES = os.getenv('INSPIRCD_BRANCHES', 'master').split() |
| 34 | + |
| 35 | +# INSPIRCD_REPOSITORY contains the location of the InspIRCd git repository. |
| 36 | +INSPIRCD_REPOSITORY = os.getenv('INSPIRCD_REPOSITORY', 'https://github.com/inspircd/inspircd.git') |
| 37 | + |
| 38 | +# INSPIRCD_TAGS contains a space-delimited list of git tag prefixes. |
| 39 | +INSPIRCD_TAGS = os.getenv('INSPIRCD_TAGS', '').split() |
| 40 | + |
| 41 | +def error(message): |
| 42 | + print(f"{CC_RED}Error:{CC_RESET} {message}!", file=sys.stderr) |
| 43 | + sys.exit(1) |
| 44 | + |
| 45 | +GIT = os.getenv('GIT', 'git') |
| 46 | +if not shutil.which(GIT): |
| 47 | + error(f"Git ({GIT}) must be installed to build the API docs") |
| 48 | + |
| 49 | +DOXYGEN = os.getenv('DOXYGEN', 'doxygen') |
| 50 | +if not shutil.which(DOXYGEN): |
| 51 | + error(f"Doxygen ({DOXYGEN}) must be installed to build the API docs") |
| 52 | + |
| 53 | +SITE_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'site') |
| 54 | +for file in os.listdir(SITE_DIR): |
| 55 | + abs_file = os.path.join(SITE_DIR, file) |
| 56 | + if os.path.isdir(abs_file) and os.path.exists(os.path.join(abs_file, 'doxygen.css')): |
| 57 | + print(f"Removing {CC_BOLD}{abs_file}{CC_RESET} from a previous run ...") |
| 58 | + shutil.rmtree(abs_file) |
| 59 | + |
| 60 | +with tempfile.TemporaryDirectory() as git: |
| 61 | + print(f"Cloning {CC_BOLD}{INSPIRCD_REPOSITORY}{CC_RESET} to {git} ...") |
| 62 | + if subprocess.call([GIT, 'clone', INSPIRCD_REPOSITORY, git]): |
| 63 | + sys.exit(1) |
| 64 | + os.chdir(git) |
| 65 | + |
| 66 | + # Build the list of refs to build docs for. |
| 67 | + references = {} |
| 68 | + for branch in INSPIRCD_BRANCHES: |
| 69 | + references[branch] = [branch] |
| 70 | + for tag in subprocess.check_output([GIT, 'tag', '--list', '--sort', '-v:refname'], encoding='utf-8').split('\n'): |
| 71 | + for tag_prefix in INSPIRCD_TAGS: |
| 72 | + if tag.startswith(tag_prefix): |
| 73 | + versions = re.match(r'^v((((\d+)\.\d+)\.\d+).*)', tag) |
| 74 | + if not versions: |
| 75 | + continue |
| 76 | + if not tag in references: |
| 77 | + references[tag] = [] |
| 78 | + for version in versions.groups(): |
| 79 | + references[tag].append(version) |
| 80 | + |
| 81 | + DOXYGEN_DIR = os.path.join(git, 'docs', 'doxygen', 'html') |
| 82 | + for reference, directories in references.items(): |
| 83 | + print(f"Building API docs for {CC_BOLD}{reference}{CC_RESET} ...") |
| 84 | + if os.system(f"{GIT} clean -dfx && {GIT} checkout {reference} && {DOXYGEN} docs/Doxyfile 1>/dev/null"): |
| 85 | + sys.exit(1) |
| 86 | + |
| 87 | + for directory in directories: |
| 88 | + site_dir = os.path.join(SITE_DIR, directory) |
| 89 | + if os.path.exists(site_dir): |
| 90 | + continue |
| 91 | + print(f"Copying API docs from {CC_BOLD}{DOXYGEN_DIR}{CC_RESET} to {CC_BOLD}{site_dir}{CC_RESET} ...") |
| 92 | + shutil.copytree(DOXYGEN_DIR, site_dir) |
0 commit comments