source: rtems-source-builder/source-builder/sb/check.py @ d4eb08f

4.104.114.95
Last change on this file since d4eb08f was d4eb08f, checked in by Chris Johns <chrisj@…>, on 02/07/15 at 06:58:17

Windows native build fixes.

The testing of building on Windows is done using MSYS2.

  • Property mode set to 100644
File size: 5.5 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, silent = False):
42    if constraint != 'none' and not path.isdir(value):
43        if constraint == 'required':
44            if not silent:
45                log.notice('error: dir: not found: (%s) %s' % (macro, value))
46            return False
47        if not silent and _opts.warn_all():
48            log.notice('warning: dir: not found: (%s) %s' % (macro, value))
49    return True
50
51
52def _check_exe(_opts, macro, value, constraint, silent = False):
53
54    if len(value) == 0 or constraint == 'none':
55        return True
56
57    orig_value = value
58
59    if path.isabspath(value):
60        if path.isfile(value):
61            return True
62        if os.name == 'nt':
63            if path.isfile('%s.exe' % (value)):
64                return True
65        value = path.basename(value)
66        absexe = True
67    else:
68        absexe = False
69
70    paths = os.environ['PATH'].split(os.pathsep)
71
72    if _check_paths(value, paths):
73        if absexe:
74            if not silent:
75                log.notice('warning: exe: absolute exe found in path: (%s) %s' % (macro, orig_value))
76        return True
77
78    if constraint == 'optional':
79        if not silent:
80            log.trace('warning: exe: optional exe not found: (%s) %s' % (macro, orig_value))
81        return True
82
83    if not silent:
84        log.notice('error: exe: not found: (%s) %s' % (macro, orig_value))
85    return False
86
87
88def _check_paths(name, paths):
89    for p in paths:
90        exe = path.join(p, name)
91        if path.isfile(exe):
92            return True
93        if os.name == 'nt':
94            if path.isfile('%s.exe' % (exe)):
95                return True
96    return False
97
98
99def path_check(opts, silent = False):
100    if 'PATH' in os.environ:
101        paths = os.environ['PATH'].split(os.pathsep)
102        for p in paths:
103            if len(p.strip()) == 0:
104                if not silent:
105                    log.notice('error: environment PATH contains an empty path')
106                return False
107            elif not options.host_windows and (p.strip() == '.' or p.strip() == '..'):
108                if not silent:
109                    log.notice('error: environment PATH invalid path: %s' % (p))
110                return False
111            elif not path.exists(p):
112                if not silent and opts.warn_all():
113                    log.notice('warning: environment PATH not found: %s' % (p))
114            elif not path.isdir(p):
115                if not silent and opts.warn_all():
116                    log.notice('warning: environment PATH not a directory: %s' % (p))
117    return True
118
119
120def host_setup(opts):
121    """ Basic sanity check. All executables and directories must exist."""
122
123    if not path_check(opts):
124        return False
125
126    checks = { 'none':    _check_none,
127               'triplet': _check_triplet,
128               'dir':     _check_dir,
129               'exe':     _check_exe }
130
131    sane = True
132
133    for d in opts.defaults.keys():
134        try:
135            (test, constraint, value) = opts.defaults.get(d)
136        except:
137            if opts.defaults.get(d) is None:
138                raise error.general('invalid default: %s: not found' % (d))
139            else:
140                raise error.general('invalid default: %s [%r]' % (d, opts.defaults.get(d)))
141        if test != 'none':
142            value = opts.defaults.expand(value)
143            if test not in checks:
144                raise error.general('invalid check test: %s [%r]' % (test, opts.defaults.get(d)))
145            ok = checks[test](opts, d, value, constraint)
146            if ok:
147                tag = ' '
148            else:
149                tag = '*'
150            log.trace('%c %15s: %r -> "%s"' % (tag, d, opts.defaults.get(d), value))
151            if sane and not ok:
152                sane = False
153
154    return sane
155
156
157def check_exe(label, exe):
158    return _check_exe(None, label, exe, None, True)
159
160
161def run():
162    import sys
163    try:
164        _opts = options.load(args = sys.argv)
165        log.notice('RTEMS Source Builder - Check, v%s' % (version.str()))
166        if host_setup(_opts):
167            print 'Environment is ok'
168        else:
169            print 'Environment is not correctly set up'
170    except error.general, gerr:
171        print gerr
172        sys.exit(1)
173    except error.internal, ierr:
174        print ierr
175        sys.exit(1)
176    except error.exit, eerr:
177        pass
178    except KeyboardInterrupt:
179        log.notice('abort: user terminated')
180        sys.exit(1)
181    sys.exit(0)
182
183
184if __name__ == '__main__':
185    run()
Note: See TracBrowser for help on using the repository browser.