source: rtems-source-builder/source-builder/sb/check.py @ 53027a9

4.104.114.95
Last change on this file since 53027a9 was db65c6a, checked in by Chris Johns <chrisj@…>, on 05/15/13 at 02:15:14

Support Canadian cross builds on FreeBSD (and other hosts).

Set up the rules to manage the separate host and build setting to
allow a Canadian cross to complete.

Update the scripts to move the build directory and host/build
flags into the defaults so they are common for all build
configurations.

  • Property mode set to 100644
File size: 4.4 KB
Line 
1#
2# RTEMS Tools Project (http://www.rtems.org/)
3# Copyright 2010-2012 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
24import os
25
26import error
27import execute
28import log
29import options
30import path
31import version
32
33def _check_none(_opts, macro, value, constraint):
34    return True
35
36
37def _check_triplet(_opts, macro, value, constraint):
38    return True
39
40
41def _check_dir(_opts, macro, value, constraint):
42    if constraint != 'none' and not path.isdir(value):
43        if constraint == 'required':
44            log.notice('error: dir: not found: (%s) %s' % (macro, value))
45            return False
46        if _opts.warn_all():
47            log.notice('warning: dir: not found: (%s) %s' % (macro, value))
48    return True
49
50
51def _check_exe(_opts, macro, value, constraint):
52
53    if len(value) == 0 or constraint == 'none':
54        return True
55
56    orig_value = value
57
58    if path.isabspath(value):
59        if path.isfile(value):
60            return True
61        if os.name == 'nt':
62            if path.isfile('%s.exe' % (value)):
63                return True
64        value = path.basename(value)
65        absexe = True
66    else:
67        absexe = False
68
69    paths = os.environ['PATH'].split(os.pathsep)
70
71    if _check_paths(value, paths):
72        if absexe:
73            log.notice('warning: exe: absolute exe found in path: (%s) %s' % (macro, orig_value))
74        return True
75
76    if constraint == 'optional':
77        log.trace('warning: exe: optional exe not found: (%s) %s' % (macro, orig_value))
78        return True
79
80    log.notice('error: exe: not found: (%s) %s' % (macro, orig_value))
81    return False
82
83
84def _check_paths(name, paths):
85    for p in paths:
86        exe = path.join(p, name)
87        if path.isfile(exe):
88            return True
89        if os.name == 'nt':
90            if path.isfile('%s.exe' % (exe)):
91                return True
92    return False
93
94
95def host_setup(opts):
96    """ Basic sanity check. All executables and directories must exist."""
97
98    checks = { 'none':    _check_none,
99               'triplet': _check_triplet,
100               'dir':     _check_dir,
101               'exe':     _check_exe }
102
103    sane = True
104
105    for d in opts.defaults.keys():
106        try:
107            (test, constraint, value) = opts.defaults.get(d)
108        except:
109            if opts.defaults.get(d) is None:
110                raise error.general('invalid default: %s: not found' % (d))
111            else:
112                raise error.general('invalid default: %s [%r]' % (d, opts.defaults.get(d)))
113        if test != 'none':
114            value = opts.defaults.expand(value)
115            if test not in checks:
116                raise error.general('invalid check test: %s [%r]' % (test, opts.defaults.get(d)))
117            ok = checks[test](opts, d, value, constraint)
118            if ok:
119                tag = ' '
120            else:
121                tag = '*'
122            log.trace('%c %15s: %r -> "%s"' % (tag, d, opts.defaults.get(d), value))
123            if sane and not ok:
124                sane = False
125
126    return sane
127
128
129def check_exe(label, exe):
130    return _check_exe(None, label, exe, None)
131
132
133def run():
134    import sys
135    try:
136        _opts = options.load(args = sys.argv)
137        log.notice('RTEMS Source Builder - Check, v%s' % (version.str()))
138        if host_setup(_opts):
139            print 'Environment is ok'
140        else:
141            print 'Environment is not correctly set up'
142    except error.general, gerr:
143        print gerr
144        sys.exit(1)
145    except error.internal, ierr:
146        print ierr
147        sys.exit(1)
148    except error.exit, eerr:
149        pass
150    except KeyboardInterrupt:
151        log.notice('abort: user terminated')
152        sys.exit(1)
153    sys.exit(0)
154
155
156if __name__ == '__main__':
157    run()
Note: See TracBrowser for help on using the repository browser.