diff --git a/.docs/.gitignore b/.docs/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/.docs/.gitignore @@ -0,0 +1 @@ +__pycache__/ diff --git a/.docs/Doxyfile b/.docs/Doxyfile new file mode 100644 index 0000000..66b36c2 --- /dev/null +++ b/.docs/Doxyfile @@ -0,0 +1,9 @@ +# The API reference of the documentation site (api/), run by .docs/hooks.py +# from the repository's root after `mkdocs build`. +@INCLUDE = .docs/Doxyfile.base +PROJECT_NAME = "clang-retro MFC" +PROJECT_BRIEF = "The MFC classes" +INPUT = include \ + src +FILE_PATTERNS = *.h *.cpp *.inl +OPTIMIZE_OUTPUT_FOR_C = NO diff --git a/.docs/Doxyfile.base b/.docs/Doxyfile.base new file mode 100644 index 0000000..e5ecb16 --- /dev/null +++ b/.docs/Doxyfile.base @@ -0,0 +1,55 @@ +# Doxygen settings shared by the clang-retro sites' API references. +# Each repository's .docs/Doxyfile includes this one and sets PROJECT_NAME, +# INPUT and the rest; .docs/hooks.py runs it after `mkdocs build` and puts +# the HTML in /api/. + +OUTPUT_DIRECTORY = $(RETRO_API_OUT) +HTML_OUTPUT = api +CREATE_SUBDIRS = NO +GENERATE_HTML = YES +GENERATE_LATEX = NO +GENERATE_TREEVIEW = YES +SEARCHENGINE = YES +SERVER_BASED_SEARCH = NO +QUIET = YES +WARNINGS = NO +WARN_IF_UNDOCUMENTED = NO +WARN_IF_DOC_ERROR = NO +WARN_NO_PARAMDOC = NO + +RECURSIVE = YES +EXTRACT_ALL = YES +EXTRACT_STATIC = YES +EXTRACT_PRIVATE = NO +EXTRACT_LOCAL_CLASSES = YES +SOURCE_BROWSER = YES +STRIP_CODE_COMMENTS = NO +REFERENCED_BY_RELATION = NO +REFERENCES_RELATION = NO +VERBATIM_HEADERS = YES +JAVADOC_AUTOBRIEF = YES +QT_AUTOBRIEF = YES +FULL_PATH_NAMES = YES +STRIP_FROM_PATH = $(RETRO_ROOT) +STRIP_FROM_INC_PATH = $(RETRO_ROOT) +SORT_MEMBER_DOCS = NO +HAVE_DOT = NO +EXCLUDE_PATTERNS = */tests/* */test/* */examples/* */demos/* */site/* + +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = YES +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +# The 16-bit and Toolbox keywords, so declarations parse as plain C. +PREDEFINED = __far= __near= __huge= _far= _near= _huge= \ + __pascal= _pascal= __export= _export= \ + __loadds= _loadds= __interrupt= _interrupt= \ + __cdecl= _cdecl= __stdcall= __attribute__(x)= \ + __declspec(x)= pascal= DOXYGEN + +HTML_COLORSTYLE = TOGGLE +HTML_COLORSTYLE_HUE = 135 +HTML_COLORSTYLE_SAT = 120 +HTML_COLORSTYLE_GAMMA = 90 +HTML_DYNAMIC_SECTIONS = YES +PROJECT_LOGO = $(RETRO_DOCS)/assets/logo-48.png diff --git a/.docs/__pycache__/hooks.cpython-313.pyc b/.docs/__pycache__/hooks.cpython-313.pyc deleted file mode 100644 index 821ad3f..0000000 Binary files a/.docs/__pycache__/hooks.cpython-313.pyc and /dev/null differ diff --git a/.docs/base.yml b/.docs/base.yml index 6be945a..e235ac1 100644 --- a/.docs/base.yml +++ b/.docs/base.yml @@ -68,6 +68,8 @@ markdown_extensions: validation: nav: omitted_files: info + # The API reference (api/) is made by doxygen after the site. + not_found: info links: not_found: warn anchors: info diff --git a/.docs/hooks.py b/.docs/hooks.py index f4f60fb..beda228 100644 --- a/.docs/hooks.py +++ b/.docs/hooks.py @@ -28,10 +28,16 @@ # branch: main # pages: repository files shown as site pages # README.md: index.md +# doxygen: .docs/Doxyfile an API reference built into /api/ +# after the site (from the root; needs +# doxygen, else it is left out with a note) +import logging import os import posixpath import re +import shutil +import subprocess from mkdocs.exceptions import PluginError @@ -41,6 +47,7 @@ _HEADING = re.compile(r'^(#{1,6})\s+(.*?)\s*#*\s*$') _LINK = re.compile(r'(!?)\[((?:[^\[\]]|\[[^\]]*\])*)\]\(\s*]+)>?(\s+"[^"]*")?\s*\)') _settings = {} +log = logging.getLogger("mkdocs.hooks.retro") def on_config(config): @@ -177,3 +184,21 @@ def on_page_markdown(markdown, page, config, files): last = m.end() parts.append(_fix_links(markdown[last:], page_path, page_path)) return "".join(parts) + + +def on_post_build(config): + doxyfile = _settings.get("doxygen") + if not doxyfile: + return + if shutil.which("doxygen") is None: + log.info("doxygen is not installed: the API reference (api/) is left out") + return + env = dict(os.environ, + RETRO_API_OUT=os.path.abspath(config.site_dir), + RETRO_ROOT=_settings["root"], + RETRO_DOCS=os.path.abspath(config.docs_dir)) + result = subprocess.run(["doxygen", doxyfile], cwd=_settings["root"], env=env, + capture_output=True, text=True) + if result.returncode != 0: + raise PluginError(f"doxygen {doxyfile} failed:\n{result.stderr}") + log.info("API reference written to %s", os.path.join(config.site_dir, "api")) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 4ab7a27..41e46f6 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -36,6 +36,7 @@ jobs: python-version: '3.12' cache: pip cache-dependency-path: .docs/requirements.txt + - run: sudo apt-get install -y --no-install-recommends doxygen - run: pip install -r .docs/requirements.txt - run: mkdocs build --strict - name: Is GitHub Pages on? diff --git a/docs/assets/logo-48.png b/docs/assets/logo-48.png new file mode 100644 index 0000000..354be70 Binary files /dev/null and b/docs/assets/logo-48.png differ diff --git a/mkdocs.yml b/mkdocs.yml index c957551..8a1de28 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -12,6 +12,7 @@ hooks: extra: retro: + doxygen: .docs/Doxyfile github: clang-retro/mfc branch: main pages: @@ -27,4 +28,5 @@ nav: - "Plans and layout": plans.md - "Contributing": contributing.md - "License": license.md + - API reference: api/index.html - "All clang-retro projects": https://clang-retro.github.io/