1 | # |
---|
2 | # RTEMS Tools Project (http://www.rtems.org/) |
---|
3 | # Copyright 2014-2018 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 | # Redistribution and use in source and binary forms, with or without |
---|
9 | # modification, are permitted provided that the following conditions are met: |
---|
10 | # |
---|
11 | # 1. Redistributions of source code must retain the above copyright notice, |
---|
12 | # this list of conditions and the following disclaimer. |
---|
13 | # |
---|
14 | # 2. Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | # this list of conditions and the following disclaimer in the documentation |
---|
16 | # and/or other materials provided with the distribution. |
---|
17 | # |
---|
18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
19 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
20 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
21 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
---|
22 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
23 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
24 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
26 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
27 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
28 | # POSSIBILITY OF SUCH DAMAGE. |
---|
29 | # |
---|
30 | |
---|
31 | import os.path |
---|
32 | |
---|
33 | import wafwindows |
---|
34 | |
---|
35 | subdirs = ['rtemstoolkit', |
---|
36 | 'config', |
---|
37 | 'linkers', |
---|
38 | 'misc', |
---|
39 | 'tester', |
---|
40 | 'tools/gdb/python', |
---|
41 | 'trace'] |
---|
42 | |
---|
43 | def get_version(ctx): |
---|
44 | # |
---|
45 | # The file config/rtems-versin.ini contains the version. |
---|
46 | # |
---|
47 | from rtemstoolkit import version as rtemsversion |
---|
48 | try: |
---|
49 | version = rtemsversion.version() |
---|
50 | revision = rtemsversion.revision() |
---|
51 | except Exception as e: |
---|
52 | ctx.fatal('invalid version file: %s' % (e)) |
---|
53 | release = '%s.%s' % (version, revision) |
---|
54 | return version, release |
---|
55 | |
---|
56 | def recurse(ctx): |
---|
57 | for sd in subdirs: |
---|
58 | ctx.recurse(sd) |
---|
59 | |
---|
60 | def options(ctx): |
---|
61 | ctx.add_option('--c-opts', |
---|
62 | default = '-O2', |
---|
63 | dest='c_opts', |
---|
64 | help = 'Set build options, default: -O2.') |
---|
65 | ctx.add_option('--host', |
---|
66 | default = 'native', |
---|
67 | dest='host', |
---|
68 | help = 'Set host to build for, default: none.') |
---|
69 | recurse(ctx) |
---|
70 | |
---|
71 | def init(ctx): |
---|
72 | wafwindows.set_compilers() |
---|
73 | try: |
---|
74 | import waflib.Options |
---|
75 | import waflib.ConfigSet |
---|
76 | env = waflib.ConfigSet.ConfigSet() |
---|
77 | env.load(waflib.Options.lockfile) |
---|
78 | check_options(ctx, env.options['host']) |
---|
79 | recurse(ctx) |
---|
80 | except: |
---|
81 | pass |
---|
82 | |
---|
83 | def shutdown(ctx): |
---|
84 | pass |
---|
85 | |
---|
86 | def configure(ctx): |
---|
87 | try: |
---|
88 | ctx.load("doxygen", tooldir = 'waf-tools') |
---|
89 | except: |
---|
90 | pass |
---|
91 | ctx.env.RTEMS_VERSION, ctx.env.RTEMS_RELEASE = get_version(ctx) |
---|
92 | ctx.start_msg('Version') |
---|
93 | ctx.end_msg('%s (%s)' % (ctx.env.RTEMS_RELEASE, ctx.env.RTEMS_VERSION)) |
---|
94 | ctx.env.C_OPTS = ctx.options.c_opts.split(',') |
---|
95 | check_options(ctx, ctx.options.host) |
---|
96 | # |
---|
97 | # Common Python check. |
---|
98 | # |
---|
99 | ctx.load('python') |
---|
100 | ctx.check_python_version((2,6,6)) |
---|
101 | # |
---|
102 | # Find which versions of python are installed for testing. |
---|
103 | # |
---|
104 | ctx.find_program('python', mandatory = False) |
---|
105 | ctx.find_program('python2', mandatory = False) |
---|
106 | ctx.find_program('python3', mandatory = False) |
---|
107 | # |
---|
108 | # Installing the PYO,PYC seems broken on 1.8.19. The path is wrong. |
---|
109 | # |
---|
110 | ctx.env.PYO = 0 |
---|
111 | ctx.env.PYC = 0 |
---|
112 | recurse(ctx) |
---|
113 | |
---|
114 | def build(ctx): |
---|
115 | if os.path.exists('VERSION'): |
---|
116 | ctx.install_files('${PREFIX}/share/rtems/rtemstoolkit', ['VERSION']) |
---|
117 | recurse(ctx) |
---|
118 | if ctx.cmd == 'test': |
---|
119 | rtemstoolkit_tests(ctx) |
---|
120 | |
---|
121 | def install(ctx): |
---|
122 | recurse(ctx) |
---|
123 | |
---|
124 | def clean(ctx): |
---|
125 | recurse(ctx) |
---|
126 | |
---|
127 | def rebuild(ctx): |
---|
128 | import waflib.Options |
---|
129 | waflib.Options.commands.extend(['clean', 'build']) |
---|
130 | |
---|
131 | def check_options(ctx, host): |
---|
132 | if host in ['mingw32', 'x86_64-w64-mingw32', 'i686-w64-mingw32']: |
---|
133 | ctx.env.HOST = host |
---|
134 | ctx.env.CC = '%s-gcc' % (host) |
---|
135 | ctx.env.CXX = '%s-g++' % (host) |
---|
136 | ctx.env.AR = '%s-ar' % (host) |
---|
137 | ctx.env.PYTHON = 'python' |
---|
138 | elif host != 'native': |
---|
139 | ctx.fatal('unknown host: %s' % (host)); |
---|
140 | |
---|
141 | # |
---|
142 | # Custom commands |
---|
143 | # |
---|
144 | import waflib |
---|
145 | |
---|
146 | class test(waflib.Build.BuildContext): |
---|
147 | fun = 'build' |
---|
148 | cmd = 'test' |
---|
149 | |
---|
150 | class doxy(waflib.Build.BuildContext): |
---|
151 | fun = 'build' |
---|
152 | cmd = 'doxy' |
---|
153 | |
---|
154 | # |
---|
155 | # RTEMS Toolkit Tests. |
---|
156 | # |
---|
157 | # Run the tests from the top directory so they are run as python modules. |
---|
158 | # |
---|
159 | def rtemstoolkit_tests(ctx): |
---|
160 | log = ctx.path.find_or_declare('tests.log') |
---|
161 | ctx.logger = waflib.Logs.make_logger(log.abspath(), 'build') |
---|
162 | failures = False |
---|
163 | from rtemstoolkit import all as toolkit_tests |
---|
164 | from rtemstoolkit import args as toolkit_test_args |
---|
165 | for tt in toolkit_tests: |
---|
166 | for py in ['', '2', '3']: |
---|
167 | PY = 'PYTHON%s' % (py) |
---|
168 | if PY in ctx.env: |
---|
169 | test = 'rtemstoolkit.%s' % (tt) |
---|
170 | ctx.start_msg('Test python%s %s' % (py, test)) |
---|
171 | cmd = '%s -m %s' % (ctx.env[PY][0], test) |
---|
172 | if tt in toolkit_test_args: |
---|
173 | cmd += ' ' + ' '.join(toolkit_test_args[tt]) |
---|
174 | ctx.to_log('test command: ' + cmd) |
---|
175 | try: |
---|
176 | (out, err) = ctx.cmd_and_log(cmd, |
---|
177 | output = waflib.Context.BOTH, |
---|
178 | quiet = waflib.Context.BOTH) |
---|
179 | ctx.to_log(out) |
---|
180 | ctx.to_log(err) |
---|
181 | ctx.end_msg('pass') |
---|
182 | except waflib.Errors.WafError as e: |
---|
183 | failures = True |
---|
184 | ctx.to_log(e.stdout) |
---|
185 | ctx.to_log(e.stderr) |
---|
186 | ctx.end_msg('fail', color = 'RED') |
---|
187 | if failures: |
---|
188 | ctx.fatal('Test failures') |
---|