source: rtems-central/rtems_spec_to_x.py @ d3edaca

Last change on this file since d3edaca was e49c759, checked in by Sebastian Huber <sebastian.huber@…>, on 07/15/20 at 08:04:25

Rename "rtemsqual" in "rtemsspec"

  • Property mode set to 100755
File size: 4.1 KB
Line 
1#!/usr/bin/env python
2# SPDX-License-Identifier: BSD-2-Clause
3""" This script generates glossaries of terms from the specification. """
4
5# Copyright (C) 2019, 2020 embedded brains GmbH (http://www.embedded-brains.de)
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26# POSSIBILITY OF SUCH DAMAGE.
27
28import os
29import string
30import subprocess
31from typing import List
32
33import rtemsspec.applconfig
34import rtemsspec.build
35from rtemsspec.items import ItemCache
36import rtemsspec.glossary
37import rtemsspec.interface
38import rtemsspec.util
39import rtemsspec.validation
40
41
42def _run_command(args: List[str], cwd: str) -> int:
43    task = subprocess.Popen(args,
44                            stdout=subprocess.PIPE,
45                            stderr=subprocess.STDOUT,
46                            cwd=cwd)
47    assert task.stdout is not None
48    while True:
49        line = task.stdout.readline()
50        if line:
51            print(line.decode("utf-8").strip())
52        elif task.poll() is not None:
53            break
54    return task.wait()
55
56
57def _run_pre_qualified_only_build(config: dict, item_cache: ItemCache) -> None:
58    files = rtemsspec.build.gather_files(config, item_cache)
59    source_dir = config["source-directory"]
60    workspace_dir = config["workspace-directory"]
61    rtemsspec.util.copy_files(source_dir, workspace_dir, files)
62    with open(os.path.join(workspace_dir, "config.ini"), "w") as config_ini:
63        content = string.Template(config["config-ini"]).substitute(config)
64        config_ini.write(content)
65    specs = os.path.relpath(os.path.join(source_dir, "spec"), workspace_dir)
66    _run_command([
67        "./waf", "configure", "--rtems-specs", specs, "--rtems-top-group",
68        "/build/grp"
69    ], workspace_dir)
70    _run_command(["./waf"], workspace_dir)
71
72
73def _run_pre_qualified_doxygen(config: dict) -> None:
74    workspace_dir = config["workspace-directory"]
75    with open(config["doxyfile-template"], "r") as doxyfile_template:
76
77        class Template(string.Template):
78            """ Template class with custom delimiter. """
79            delimiter = "%"
80
81        doxyfile_vars = {}
82        doxyfile_vars["project_name"] = "RTEMS"
83        doxyfile_vars["output_directory"] = "doc"
84        content = Template(doxyfile_template.read()).substitute(doxyfile_vars)
85        with open(os.path.join(workspace_dir, "Doxyfile"), "w") as doxyfile:
86            doxyfile.write(content)
87    _run_command(["doxygen"], workspace_dir)
88
89
90def main() -> None:
91    """ Generates glossaries of terms according to the configuration. """
92    config = rtemsspec.util.load_config("config.yml")
93    item_cache = ItemCache(config["spec"])
94    rtemsspec.glossary.generate(config["glossary"], item_cache)
95    rtemsspec.applconfig.generate(config["appl-config"], item_cache)
96    rtemsspec.interface.generate(config["interface"], item_cache)
97    rtemsspec.validation.generate(config["validation"], item_cache)
98    _run_pre_qualified_only_build(config["build"], item_cache)
99    _run_pre_qualified_doxygen(config["build"])
100
101
102if __name__ == "__main__":
103    main()
Note: See TracBrowser for help on using the repository browser.