source: rtems-central/rtemsqual/build.py @ 05246b3

Last change on this file since 05246b3 was 9dad293, checked in by Sebastian Huber <sebastian.huber@…>, on 04/28/20 at 09:29:48

items: Use generator functions for item links

This enables an easy access to link attributes.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1# SPDX-License-Identifier: BSD-2-Clause
2""" This module provides support for the build specification. """
3
4# Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25# POSSIBILITY OF SUCH DAMAGE.
26
27from typing import Dict, List
28
29from rtemsqual.items import Item, ItemCache
30
31BSPMap = Dict[str, Dict[str, Item]]
32ItemMap = Dict[str, Item]
33
34
35def _extend_by_install_and_source(item: Item, source_files: List[str]) -> None:
36    for install in item["install"]:
37        source_files.extend(install["source"])
38    source_files.extend(item["source"])
39
40
41def _extend_by_source(item: Item, source_files: List[str]) -> None:
42    source_files.extend(item["source"])
43
44
45def _extend_by_nothing(_item: Item, _source_files: List[str]) -> None:
46    pass
47
48
49_EXTEND_SOURCE_FILES = {
50    "ada-test-program": _extend_by_nothing,
51    "bsp": _extend_by_install_and_source,
52    "config-file": _extend_by_nothing,
53    "config-header": _extend_by_nothing,
54    "test-program": _extend_by_source,
55    "group": _extend_by_nothing,
56    "library": _extend_by_install_and_source,
57    "objects": _extend_by_install_and_source,
58    "option": _extend_by_nothing,
59    "script": _extend_by_nothing,
60    "start-file": _extend_by_source,
61}
62
63
64def _gather_source_files(item: Item, enabled: List[str],
65                         source_files: List[str]) -> None:
66    for parent in item.parents():
67        if parent["type"] == "build" and parent["build-type"] in [
68                "group", "objects", "start-file", "test-program"
69        ] and parent.is_enabled(enabled):
70            _gather_source_files(parent, enabled, source_files)
71    _EXTEND_SOURCE_FILES[item["build-type"]](item, source_files)
72
73
74def gather_files(config: dict, item_cache: ItemCache) -> List[str]:
75    """ Generates a list of files form the build specification. """
76    bsps = {}  # type: BSPMap
77    for item in item_cache.all.values():
78        if item["type"] == "build" and item["build-type"] == "bsp":
79            arch_bsps = bsps.setdefault(item["arch"].strip(), {})
80            arch_bsps[item["bsp"].strip()] = item
81    source_files = config["sources"]  # type: List[str]
82    arch = config["arch"]
83    bsp = config["bsp"]
84    enabled = [arch, arch + "/" + bsp] + config["enabled"]
85    _gather_source_files(bsps[arch][bsp], enabled, source_files)
86    for uid in config["uids"]:
87        _gather_source_files(item_cache[uid], enabled, source_files)
88    return source_files
Note: See TracBrowser for help on using the repository browser.