ra.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # -*- mode: Python -*-
  2. # -*- coding: utf-8 -*-
  3. # (c) Daniel Llorens - 2016, 2017
  4. # This library is free software; you can redistribute it and/or modify it under
  5. # the terms of the GNU Lesser General Public License as published by the Free
  6. # Software Foundation; either version 3 of the License, or (at your option) any
  7. # later version.
  8. # Utilities for SConstructs
  9. import os, string
  10. from colorama import Fore, Back, Style
  11. from os.path import join, abspath
  12. from subprocess import call
  13. def take_from_environ(env, var, wrapper=(lambda x: x), default=None):
  14. if var in os.environ and os.environ[var]!='':
  15. env[var] = wrapper(os.environ[var])
  16. elif default is not None:
  17. env[var] = default
  18. def to_test(env, variant_dir, source, args):
  19. """
  20. Run program with args to produce a check stamp. The name of the first source
  21. is used to generate the name of the stamp.
  22. """
  23. class tester:
  24. def __init__(self, args):
  25. self.args = args
  26. def __call__(self, target, source, env):
  27. print("-> running %s \n___________________" % str(self.args))
  28. r = os.spawnl(os.P_WAIT, self.args[0], self.args[0], *self.args[1:])
  29. print("^^^^^^^^^^^^^^^^^^^")
  30. print('r ', r)
  31. if not r:
  32. print("PASSED %s" % str(self.args))
  33. call(['touch', target[0].abspath])
  34. else:
  35. print("FAILED %s" % str(self.args))
  36. return r
  37. stamp = env.File(join(variant_dir, str(source[0])) + string.join(args[1:]) + '.check')
  38. return env.Command(stamp, source, tester(args))
  39. def to_test_ra(env_, variant_dir):
  40. def f(source, target='', cxxflags=[], cppdefines=[]):
  41. if len(cxxflags)==0 or len(cppdefines)==0:
  42. env = env_
  43. else:
  44. env = env_.Clone()
  45. env.Append(CXXFLAGS=cxxflags + ['-U' + k for k in cppdefines.keys()], CPPDEFINES=cppdefines)
  46. if len(target)==0:
  47. target = source
  48. obj = env.Object(target, [source + '.C'])
  49. test = env.Program(target, obj)
  50. to_test(env, variant_dir, test, [test[0].abspath])
  51. return f
  52. def print_summary(GetBuildFailures, tag):
  53. test_item_tally = 0
  54. test_tally = 0
  55. build_tally = 0
  56. print('\n' + Style.BRIGHT + 'Summary for ' + tag + Style.RESET_ALL + '\n--------')
  57. for bf in GetBuildFailures():
  58. if str(bf.node).endswith('.check') and (bf.status > 0):
  59. print((Style.BRIGHT + Fore.RED + '%s ' + Style.RESET_ALL + Fore.RESET + ' failed (%d)') \
  60. % (bf.node, bf.status))
  61. test_item_tally += bf.status
  62. test_tally += 1
  63. else:
  64. print((Style.BRIGHT + Fore.YELLOW + '%s ' + Style.RESET_ALL + Fore.RESET + ' failed (%s)') \
  65. % (bf.node, bf.errstr))
  66. build_tally += 1
  67. print('%d targets failed to build.' % build_tally)
  68. print('%d tests failed with %d total failures.' % (test_tally, test_item_tally))