[c0ac12a] | 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 | |
---|
[1a2fcaf] | 28 | import os |
---|
| 29 | import shutil |
---|
| 30 | import subprocess |
---|
| 31 | from typing import List |
---|
[c0ac12a] | 32 | import yaml |
---|
| 33 | |
---|
[5df0bec] | 34 | import rtemsqual.applconfig |
---|
[1a2fcaf] | 35 | import rtemsqual.build |
---|
| 36 | from rtemsqual.items import ItemCache |
---|
[c0ac12a] | 37 | import rtemsqual.glossary |
---|
| 38 | |
---|
| 39 | |
---|
[1a2fcaf] | 40 | def _run_command(args: List[str], cwd: str) -> int: |
---|
| 41 | task = subprocess.Popen(args, |
---|
| 42 | stdout=subprocess.PIPE, |
---|
| 43 | stderr=subprocess.STDOUT, |
---|
| 44 | cwd=cwd) |
---|
| 45 | while True: |
---|
| 46 | line = task.stdout.readline() |
---|
| 47 | if line: |
---|
| 48 | print(line.decode("utf-8").strip()) |
---|
| 49 | elif task.poll() is not None: |
---|
| 50 | break |
---|
| 51 | return task.wait() |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | def _run_pre_qualified_only_build(config: dict, item_cache: ItemCache) -> None: |
---|
| 55 | files = rtemsqual.build.gather_files(config, item_cache) |
---|
| 56 | source_dir = config["source-directory"] |
---|
| 57 | workspace_dir = config["workspace-directory"] |
---|
| 58 | for a_file in files: |
---|
| 59 | src = os.path.join(source_dir, a_file) |
---|
| 60 | dst = os.path.join(workspace_dir, a_file) |
---|
| 61 | os.makedirs(os.path.dirname(dst), exist_ok=True) |
---|
| 62 | shutil.copy2(src, dst) |
---|
| 63 | with open(os.path.join(workspace_dir, "config.ini"), "w") as config_ini: |
---|
| 64 | config_ini.write(f"""[{config["arch"]}/{config["bsp"]}] |
---|
| 65 | RTEMS_SMP = True |
---|
| 66 | RTEMS_QUAL = True |
---|
| 67 | RTEMS_QUAL_ONLY = True |
---|
| 68 | BUILD_TESTS = False |
---|
| 69 | BUILD_VALIDATIONTESTS = True |
---|
| 70 | """) |
---|
| 71 | specs = os.path.relpath(os.path.join(source_dir, "spec"), workspace_dir) |
---|
| 72 | _run_command(["./waf", "configure", "--rtems-specs", specs], workspace_dir) |
---|
| 73 | _run_command(["./waf"], workspace_dir) |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | def main() -> None: |
---|
[c0ac12a] | 77 | """ Generates glossaries of terms according to the configuration. """ |
---|
| 78 | with open("config.ini", "r") as out: |
---|
| 79 | config = yaml.safe_load(out.read()) |
---|
[1a2fcaf] | 80 | item_cache = ItemCache(config["spec"]) |
---|
[c0ac12a] | 81 | rtemsqual.glossary.generate(config["glossary"], item_cache) |
---|
[5df0bec] | 82 | rtemsqual.applconfig.generate(config["appl-config"], item_cache) |
---|
[1a2fcaf] | 83 | _run_pre_qualified_only_build(config["build"], item_cache) |
---|
[c0ac12a] | 84 | |
---|
| 85 | |
---|
| 86 | if __name__ == "__main__": |
---|
| 87 | main() |
---|