source: rtems-tools/wscript @ 3d2db56

5
Last change on this file since 3d2db56 was 95abe76, checked in by Chris Johns <chrisj@…>, on 11/28/18 at 18:40:08

waf: Fix version paths on Windows.

  • Property mode set to 100644
File size: 5.8 KB
Line 
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
31import os.path
32
33import wafwindows
34
35subdirs = ['rtemstoolkit',
36           'config',
37           'linkers',
38           'misc',
39           'tester',
40           'tools/gdb/python']
41
42def get_version(ctx):
43    #
44    # The file config/rtems-versin.ini contains the version.
45    #
46    from rtemstoolkit import version as rtemsversion
47    try:
48        version = rtemsversion.version()
49        revision = rtemsversion.revision()
50    except Exception as e:
51        ctx.fatal('invalid version file: %s' % (e))
52    release = '%s.%s' % (version, revision)
53    return version, release
54
55def recurse(ctx):
56    for sd in subdirs:
57        ctx.recurse(sd)
58
59def options(ctx):
60    ctx.add_option('--c-opts',
61                   default = '-O2',
62                   dest='c_opts',
63                   help = 'Set build options, default: -O2.')
64    ctx.add_option('--host',
65                   default = 'native',
66                   dest='host',
67                   help = 'Set host to build for, default: none.')
68    recurse(ctx)
69
70def init(ctx):
71    wafwindows.set_compilers()
72    try:
73        import waflib.Options
74        import waflib.ConfigSet
75        env = waflib.ConfigSet.ConfigSet()
76        env.load(waflib.Options.lockfile)
77        check_options(ctx, env.options['host'])
78        recurse(ctx)
79    except:
80        pass
81
82def shutdown(ctx):
83    pass
84
85def configure(ctx):
86    try:
87        ctx.load("doxygen", tooldir = 'waf-tools')
88    except:
89        pass
90    ctx.env.RTEMS_VERSION, ctx.env.RTEMS_RELEASE = get_version(ctx)
91    ctx.start_msg('Version')
92    ctx.end_msg('%s (%s)' % (ctx.env.RTEMS_RELEASE, ctx.env.RTEMS_VERSION))
93    ctx.env.C_OPTS = ctx.options.c_opts.split(',')
94    check_options(ctx, ctx.options.host)
95    #
96    # Common Python check.
97    #
98    ctx.load('python')
99    ctx.check_python_version((2,6,6))
100    #
101    # Find which versions of python are installed for testing.
102    #
103    ctx.find_program('python2', mandatory = False)
104    ctx.find_program('python3', mandatory = False)
105    #
106    # Installing the PYO,PYC seems broken on 1.8.19. The path is wrong.
107    #
108    ctx.env.PYO = 0
109    ctx.env.PYC = 0
110    recurse(ctx)
111
112def build(ctx):
113    if os.path.exists('VERSION'):
114        ctx.install_files('${PREFIX}/share/rtems/rtemstoolkit', ['VERSION'])
115    recurse(ctx)
116    if ctx.cmd == 'test':
117        rtemstoolkit_tests(ctx)
118
119def install(ctx):
120    recurse(ctx)
121
122def clean(ctx):
123    recurse(ctx)
124
125def rebuild(ctx):
126    import waflib.Options
127    waflib.Options.commands.extend(['clean', 'build'])
128
129def check_options(ctx, host):
130    if host in ['mingw32', 'x86_64-w64-mingw32']:
131        ctx.env.HOST = host
132        ctx.env.CC = '%s-gcc' % (host)
133        ctx.env.CXX = '%s-g++' % (host)
134        ctx.env.AR = '%s-ar' % (host)
135        ctx.env.PYTHON = 'python'
136    elif host is not 'native':
137        ctx.fatal('unknown host: %s' % (host));
138
139#
140# Custom commands
141#
142import waflib
143
144class test(waflib.Build.BuildContext):
145    fun = 'build'
146    cmd = 'test'
147
148class doxy(waflib.Build.BuildContext):
149    fun = 'build'
150    cmd = 'doxy'
151
152#
153# RTEMS Toolkit Tests.
154#
155# Run the tests from the top directory so they are run as python modules.
156#
157def rtemstoolkit_tests(ctx):
158    log = ctx.path.find_or_declare('tests.log')
159    ctx.logger = waflib.Logs.make_logger(log.abspath(), 'build')
160    failures = False
161    for py in ['2', '3']:
162        PY = 'PYTHON%s' % (py)
163        if PY in ctx.env:
164            from rtemstoolkit import all as toolkit_tests
165            from rtemstoolkit import args as toolkit_test_args
166            for tt in toolkit_tests:
167                test = 'rtemstoolkit.%s' % (tt)
168                ctx.start_msg('Test python%s %s' % (py, test))
169                cmd = '%s -m %s' % (ctx.env[PY][0], test)
170                if tt in toolkit_test_args:
171                    cmd += ' ' + ' '.join(toolkit_test_args[tt])
172                ctx.to_log('test command: ' + cmd)
173                try:
174                    (out, err) = ctx.cmd_and_log(cmd,
175                                                 output = waflib.Context.BOTH,
176                                                 quiet = waflib.Context.BOTH)
177                    ctx.to_log(out)
178                    ctx.to_log(err)
179                    ctx.end_msg('pass')
180                except waflib.Errors.WafError as e:
181                    failures = True
182                    ctx.to_log(e.stdout)
183                    ctx.to_log(e.stderr)
184                    ctx.end_msg('fail', color = 'RED')
185    if failures:
186        ctx.fatal('Test failures')
Note: See TracBrowser for help on using the repository browser.