source: rtems-source-builder/source-builder/sb/check.py @ 0e22c3c

4.11
Last change on this file since 0e22c3c was 0e22c3c, checked in by Chris Johns <chrisj@…>, on Mar 17, 2016 at 5:39:57 AM

sb: Support --dry-run --with-download for 3rd party RTEMS BSP packages.

The building of 3rd party packages for an RTEMS BSP requires a valid
BSP so the standard method to download the source for releasing does
not work. This change adds support to allow this. The RTEMS BSP support
will not generate an error is no BSP or tools are provided or found.

The change addis logic operators to the %if statement so you can '
'

to 'or' and '&&' to 'and' logic expressions.

A new %log directive has been added to clean up the messages.

A new %{!define ...} has been added to aid checking within logic
expressions.

All command line --with/--without now appear as macros.

Add version.version to get just the RTEMS major and minor version.

Some pkg-config issues have been resolved.

Closes #2655.

  • Property mode set to 100644
File size: 5.7 KB
Line 
1#
2# RTEMS Tools Project (http://www.rtems.org/)
3# Copyright 2010-2016 Chris Johns (chrisj@rtems.org)
4# All rights reserved.
5#
6# This file is part of the RTEMS Tools package in 'rtems-tools'.
7#
8# Permission to use, copy, modify, and/or distribute this software for any
9# purpose with or without fee is hereby granted, provided that the above
10# copyright notice and this permission notice appear in all copies.
11#
12# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20#
21# Check the defaults for a specific host.
22#
23
24from __future__ import print_function
25
26import os
27
28import error
29import execute
30import log
31import options
32import path
33import version
34
35def _check_none(_opts, macro, value, constraint):
36    return True
37
38
39def _check_triplet(_opts, macro, value, constraint):
40    return True
41
42
43def _check_dir(_opts, macro, value, constraint, silent = False):
44    if constraint != 'none' and not path.isdir(value):
45        if constraint == 'required':
46            if not silent:
47                log.notice('error: dir: not found: (%s) %s' % (macro, value))
48            return False
49        if not silent and _opts.warn_all():
50            log.notice('warning: dir: not found: (%s) %s' % (macro, value))
51    return True
52
53
54def _check_exe(_opts, macro, value, constraint, silent = False):
55
56    if len(value) == 0 or constraint == 'none':
57        return True
58
59    orig_value = value
60
61    if path.isabspath(value):
62        if path.isfile(value):
63            return True
64        if os.name == 'nt':
65            if path.isfile('%s.exe' % (value)):
66                return True
67        value = path.basename(value)
68        absexe = True
69    else:
70        absexe = False
71
72    paths = os.environ['PATH'].split(os.pathsep)
73
74    if _check_paths(value, paths):
75        if absexe:
76            if not silent:
77                log.notice('warning: exe: absolute exe found in path: (%s) %s' % (macro, orig_value))
78        return True
79
80    if constraint == 'optional':
81        if not silent:
82            log.trace('warning: exe: optional exe not found: (%s) %s' % (macro, orig_value))
83        return True
84
85    if not silent:
86        log.notice('error: exe: not found: (%s) %s' % (macro, orig_value))
87    return False
88
89
90def _check_paths(name, paths):
91    for p in paths:
92        exe = path.join(p, name)
93        if path.isfile(exe):
94            return True
95        if os.name == 'nt':
96            if path.isfile('%s.exe' % (exe)):
97                return True
98    return False
99
100
101def path_check(opts, silent = False):
102    if 'PATH' in os.environ:
103        paths = os.environ['PATH'].split(os.pathsep)
104        for p in paths:
105            if len(p.strip()) == 0:
106                if not silent:
107                    log.notice('error: environment PATH contains an empty path')
108                return False
109            elif not options.host_windows and (p.strip() == '.' or p.strip() == '..'):
110                if not silent:
111                    log.notice('error: environment PATH invalid path: %s' % (p))
112                return False
113            elif not path.exists(p):
114                if not silent and opts.warn_all():
115                    log.notice('warning: environment PATH not found: %s' % (p))
116            elif not path.isdir(p):
117                if not silent and opts.warn_all():
118                    log.notice('warning: environment PATH not a directory: %s' % (p))
119    return True
120
121
122def host_setup(opts):
123    """ Basic sanity check. All executables and directories must exist."""
124
125    if not path_check(opts):
126        return False
127
128    checks = { 'none':    _check_none,
129               'triplet': _check_triplet,
130               'dir':     _check_dir,
131               'exe':     _check_exe }
132
133    sane = True
134
135    log.trace('--- check host set up : start"')
136    for d in list(opts.defaults.keys()):
137        try:
138            (test, constraint, value) = opts.defaults.get(d)
139        except:
140            if opts.defaults.get(d) is None:
141                raise error.general('invalid default: %s: not found' % (d))
142            else:
143                raise error.general('invalid default: %s [%r]' % (d, opts.defaults.get(d)))
144        if test != 'none':
145            value = opts.defaults.expand(value)
146            if test not in checks:
147                raise error.general('invalid check test: %s [%r]' % (test, opts.defaults.get(d)))
148            ok = checks[test](opts, d, value, constraint)
149            if ok:
150                tag = ' '
151            else:
152                tag = '*'
153            log.trace('%c %15s: %r -> "%s"' % (tag, d, opts.defaults.get(d), value))
154            if sane and not ok:
155                sane = False
156    log.trace('--- check host set up : end"')
157
158    return sane
159
160
161def check_exe(label, exe):
162    return _check_exe(None, label, exe, None, True)
163
164
165def run():
166    import sys
167    try:
168        _opts = options.load(args = sys.argv)
169        log.notice('RTEMS Source Builder - Check, %s' % (version.str()))
170        if host_setup(_opts):
171            print('Environment is ok')
172        else:
173            print('Environment is not correctly set up')
174    except error.general as gerr:
175        print(gerr)
176        sys.exit(1)
177    except error.internal as ierr:
178        print(ierr)
179        sys.exit(1)
180    except error.exit as eerr:
181        pass
182    except KeyboardInterrupt:
183        log.notice('abort: user terminated')
184        sys.exit(1)
185    sys.exit(0)
186
187
188if __name__ == '__main__':
189    run()
Note: See TracBrowser for help on using the repository browser.