summaryrefslogtreecommitdiffstats
path: root/source-builder/sb/rtems-kernel-config-check
blob: 2256925ff6c7ec9ff09736cdf2088c0d20d32adc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#! /usr/bin/env python
"""
SPDX-License-Identifier: BSD-2-Clause

COPYRIGHT (C) 2021 On-Line Applications Research Corporation (OAR).

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
"""

from __future__ import print_function

import argparse
import os.path
import sys

try:
    import ConfigParser
    configparser = ConfigParser  # used for python2
except ImportError:
    try:
        import configparser  # used for python3
    except ImportError:
        print("Could not import configparser. Exiting...", file=sys.stderr)
        sys.exit(1)


def run():
    parser = argparse.ArgumentParser()
    parser.add_argument("config", help="path to config file")
    parser.add_argument(
        "-a",
        "--arch",
        help="return target architecture specified in the config",
        action="store_true")
    parser.add_argument("-b",
                        "--bsp",
                        help="return BSP specified in the config",
                        action="store_true")
    parser.add_argument(
        "-c",
        "--arch-bsp",
        help="return target architecture and BSP specified in the config",
        action="store_true")
    parser.add_argument("-v",
                        "--rtems-version",
                        help="version of RTEMS",
                        type=int,
                        default=6)
    parser.add_argument("-t",
                        "--tests",
                        help="Build tests is true",
                        action="store_true")
    args = parser.parse_args()
    config = configparser.ConfigParser()

    if args.config[-4:] != ".ini":
        print("The config file is missing an *.ini extension.",
              file=sys.stderr)
        sys.exit(1)

    if not os.path.exists(args.config):
        print("Config file not found: " + args.config, file=sys.stderr)
        sys.exit(1)

    try:
        config.read(args.config)
    except configparser.MissingSectionHeaderError:
        print("There is no section header in the config file", file=sys.stderr)
        sys.exit(1)
    except configparser.ParsingError:
        print("An exception occured when parsing the config file",
              file=sys.stderr)
        sys.exit(1)
    except:
        print("An unknown exception occured", file=sys.stderr)

    for arch_bsp in config.sections():
        if len(arch_bsp.split("/")) != 2:
            print("arch/bsp section in config is missing '/'", file=sys.stderr)
            sys.exit(1)

    if (args.arch or args.bsp) and args.arch_bsp:
        args.arch = False

    if args.arch:
        print(' '.join([ab.split('/')[0] for ab in config.sections()]))
        return

    if args.bsp:
        print(' '.join([ab.split('/')[1] for ab in config.sections()]))
        return

    if args.arch_bsp:
        print(' '.join([arch_bsp for arch_bsp in config.sections()]))
        return

    if args.tests:
        for sec in ["DEFAULT"] + config.sections():
            for item in config[sec].items():
                if item[0] == 'buld_tests' or item[0] == 'build_samples':
                    print("True")
                    return
        print("False")
        return


if __name__ == "__main__":
    run()