diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2021-10-04 22:19:07 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-04 22:19:07 +0300 |
commit | 2d65472c725f18b343aee00bf91b9ac98c08b95f (patch) | |
tree | 530a0d6ffee4ee96e875302cbeba660c93056d41 /docs/refman/main.py | |
parent | 75dd9fb67f793c687fa45744f3b276e35c87ca09 (diff) | |
parent | b672ebca886dd6dc9b0f775eb769764750fd302c (diff) | |
download | meson-2d65472c725f18b343aee00bf91b9ac98c08b95f.zip meson-2d65472c725f18b343aee00bf91b9ac98c08b95f.tar.gz meson-2d65472c725f18b343aee00bf91b9ac98c08b95f.tar.bz2 |
Merge pull request #8960 from mensinda/yamlDoc
Reference Manual 2.0
Diffstat (limited to 'docs/refman/main.py')
-rw-r--r-- | docs/refman/main.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/docs/refman/main.py b/docs/refman/main.py new file mode 100644 index 0000000..cb040ce --- /dev/null +++ b/docs/refman/main.py @@ -0,0 +1,75 @@ +# Copyright 2021 The Meson development team + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from pathlib import Path +import argparse +import typing as T + +from mesonbuild import mlog + +from .loaderbase import LoaderBase +from .loaderyaml import LoaderYAML + +from .generatorbase import GeneratorBase +from .generatorprint import GeneratorPrint +from .generatorpickle import GeneratorPickle +from .generatormd import GeneratorMD + +meson_root = Path(__file__).absolute().parents[2] + +def main() -> int: + parser = argparse.ArgumentParser(description='Meson reference manual generator') + parser.add_argument('-l', '--loader', type=str, default='yaml', choices=['yaml'], help='Information loader backend') + parser.add_argument('-g', '--generator', type=str, choices=['print', 'pickle', 'md'], required=True, help='Generator backend') + parser.add_argument('-s', '--sitemap', type=Path, default=meson_root / 'docs' / 'sitemap.txt', help='Path to the input sitemap.txt') + parser.add_argument('-o', '--out', type=Path, required=True, help='Output directory for generated files') + parser.add_argument('--link-defs', type=Path, help='Output file for the MD generator link definition file') + parser.add_argument('--depfile', type=Path, default=None, help='Set to generate a depfile') + parser.add_argument('--force-color', action='store_true', help='Force enable colors') + args = parser.parse_args() + + if args.force_color: + mlog.colorize_console = lambda: True + + loaders: T.Dict[str, T.Callable[[], LoaderBase]] = { + 'yaml': lambda: LoaderYAML(meson_root / 'docs' / 'yaml'), + } + + loader = loaders[args.loader]() + refMan = loader.load() + + generators: T.Dict[str, T.Callable[[], GeneratorBase]] = { + 'print': lambda: GeneratorPrint(refMan), + 'pickle': lambda: GeneratorPickle(refMan, args.out), + 'md': lambda: GeneratorMD(refMan, args.out, args.sitemap, args.link_defs), + } + generator = generators[args.generator]() + + # Generate the depfile if required + if args.depfile is not None: + assert isinstance(args.depfile, Path) + assert isinstance(args.out, Path) + + # Also add all files of this package + script_files = list(Path(__file__).resolve().parent.glob('**/*.py')) + templates = list(Path(__file__).resolve().parent.glob('**/*.mustache')) + + out_text = f'{args.out.resolve().as_posix()}: \\\n' + for input in loader.input_files + script_files + templates: + out_text += f' {input.resolve().as_posix():<93} \\\n' + + args.depfile.write_text(out_text, encoding='utf-8') + + generator.generate() + return 0 |