forked from lloda/ra-ra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ra.py
101 lines (81 loc) · 3.38 KB
/
ra.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# -*- mode: Python -*-
# -*- coding: utf-8 -*-
# (c) Daniel Llorens - 2016, 2017
# This library is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option) any
# later version.
# Utilities for SConstructs
import os, string
from colorama import Fore, Back, Style
from os.path import join, abspath, split
from subprocess import call
def ensure_ext(s, ext):
"if s doesn't end with ext, append it."
p = s.rfind(ext)
return s if p+len(ext) == len(s) else s + ext
def remove_ext(s):
"clip string from the last dot until the end."
p = s.rfind('.')
assert p>=0, 'source must have an extension'
return s[0:p]
def path_parts(path):
path, tail = split(path)
return ([path] if path == os.sep else path_parts(path) if path else []) \
+ ([tail] if tail else [])
def take_from_environ(env, var, wrapper=(lambda x: x), default=None):
if var in os.environ and os.environ[var]!='':
env[var] = wrapper(os.environ[var])
elif default is not None:
env[var] = default
def to_test(env, variant_dir, source, args):
"""
Run program with args to produce a check stamp. The name of the first source
is used to generate the name of the stamp.
"""
class tester:
def __init__(self, args):
self.args = args
def __call__(self, target, source, env):
print("-> running %s \n___________________" % str(self.args))
r = os.spawnl(os.P_WAIT, self.args[0], self.args[0], *self.args[1:])
print("^^^^^^^^^^^^^^^^^^^")
print('r ', r)
if not r:
print("PASSED %s" % str(self.args))
call(['touch', target[0].abspath])
else:
print("FAILED %s" % str(self.args))
return r
stamp = env.File(join(variant_dir, str(source[0])) + string.join(args[1:]) + '.check')
return env.Command(stamp, source, tester(args))
def to_test_ra(env_, variant_dir):
def f(source, target='', cxxflags=[], cppdefines=[]):
if len(cxxflags)==0 or len(cppdefines)==0:
env = env_
else:
env = env_.Clone()
env.Append(CXXFLAGS=cxxflags + ['-U' + k for k in cppdefines.keys()], CPPDEFINES=cppdefines)
if len(target)==0:
target = source
obj = env.Object(target, [source + '.C'])
test = env.Program(target, obj)
to_test(env, variant_dir, test, [test[0].abspath])
return f
def print_summary(GetBuildFailures, tag):
test_item_tally = 0
test_tally = 0
build_tally = 0
print('\n' + Style.BRIGHT + 'Summary for ' + tag + Style.RESET_ALL + '\n--------')
for bf in GetBuildFailures():
if str(bf.node).endswith('.check') and (bf.status > 0):
print((Style.BRIGHT + Fore.RED + '%s ' + Style.RESET_ALL + Fore.RESET + ' failed (%d)') \
% (bf.node, bf.status))
test_item_tally += bf.status
test_tally += 1
else:
print((Style.BRIGHT + Fore.YELLOW + '%s ' + Style.RESET_ALL + Fore.RESET + ' failed (%s)') \
% (bf.node, bf.errstr))
build_tally += 1
print('%d targets failed to build.' % build_tally)
print('%d tests failed with %d total failures.' % (test_tally, test_item_tally))