library_test.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/usr/bin/env python
  2. # Copyright Rene Rivera 2016
  3. #
  4. # Distributed under the Boost Software License, Version 1.0.
  5. # (See accompanying file LICENSE_1_0.txt or copy at
  6. # http://www.boost.org/LICENSE_1_0.txt)
  7. import os.path
  8. import shutil
  9. import sys
  10. from common import toolset_info, main, utils, script_common, ci_cli, set_arg
  11. __dirname__ = os.path.dirname(os.path.realpath(__file__))
  12. class script(script_common):
  13. '''
  14. Main script to test a Boost C++ Library.
  15. '''
  16. def __init__(self, ci_klass, **kargs):
  17. script_common.__init__(self, ci_klass, **kargs)
  18. def init(self, opt, kargs):
  19. opt.add_option( '--toolset',
  20. help="single toolset to test with" )
  21. opt.add_option( '--target',
  22. help="test target to build for testing, defaults to TARGET or 'minimal'")
  23. opt.add_option( '--address-model',
  24. help="address model to test, ie 64 or 32" )
  25. opt.add_option( '--variant',
  26. help="variant to test, ie debug, release" )
  27. set_arg(kargs, 'toolset', os.getenv("TOOLSET"))
  28. set_arg(kargs, 'target', os.getenv('TARGET', 'minimal'))
  29. set_arg(kargs, 'address_model', os.getenv("ADDRESS_MODEL",None))
  30. set_arg(kargs, 'variant', os.getenv("VARIANT","debug"))
  31. set_arg(kargs, 'cxxflags', os.getenv("CXXFLAGS",None))
  32. return kargs
  33. def start(self):
  34. script_common.start(self)
  35. # Some setup we need to redo for each invocation.
  36. self.b2_dir = os.path.join(self.build_dir, 'b2')
  37. def command_install(self):
  38. script_common.command_install(self)
  39. # Fetch & install toolset..
  40. utils.log( "Install toolset: %s"%(self.toolset) )
  41. if self.toolset:
  42. self.command_install_toolset(self.toolset)
  43. def command_before_build(self):
  44. script_common.command_before_build(self)
  45. # Fetch dependencies.
  46. utils.git_clone('boostorg','build','develop',repo_dir=self.b2_dir)
  47. # Create config file for b2 toolset.
  48. if not isinstance(self.ci, ci_cli):
  49. cxxflags = None
  50. if self.cxxflags:
  51. cxxflags = self.cxxflags.split()
  52. cxxflags = " <cxxflags>".join(cxxflags)
  53. utils.make_file(os.path.join(self.repo_dir, 'project-config.jam'),
  54. """
  55. using %(toolset)s : %(version)s : %(command)s : %(cxxflags)s ;
  56. using python : %(pyversion)s : "%(python)s" ;
  57. """%{
  58. 'toolset':toolset_info[self.toolset]['toolset'],
  59. 'version':toolset_info[self.toolset]['version'],
  60. 'command':toolset_info[self.toolset]['command'],
  61. 'cxxflags':"<cxxflags>"+cxxflags if cxxflags else "",
  62. 'pyversion':"%s.%s"%(sys.version_info[0],sys.version_info[1]),
  63. 'python':sys.executable.replace("\\","\\\\")
  64. })
  65. # "Convert" boostorg-predef into standalone b2 project.
  66. if os.path.exists(os.path.join(self.repo_dir,'build.jam')) and not os.path.exists(os.path.join(self.repo_dir,'project-root.jam')):
  67. os.rename(os.path.join(self.repo_dir,'build.jam'), os.path.join(self.repo_dir,'project-root.jam'))
  68. def command_build(self):
  69. script_common.command_build(self)
  70. # Set up tools.
  71. if not isinstance(self.ci, ci_cli) and toolset_info[self.toolset]['command']:
  72. os.environ['PATH'] = os.pathsep.join([
  73. os.path.dirname(toolset_info[self.toolset]['command']),
  74. os.environ['PATH']])
  75. # Bootstrap Boost Build engine.
  76. os.chdir(self.b2_dir)
  77. if sys.platform == 'win32':
  78. utils.check_call(".\\bootstrap.bat")
  79. else:
  80. utils.check_call("./bootstrap.sh")
  81. os.environ['PATH'] = os.pathsep.join([self.b2_dir, os.environ['PATH']])
  82. os.environ['BOOST_BUILD_PATH'] = self.b2_dir
  83. # Run the limited tests.
  84. print("--- Testing %s ---"%(self.repo_dir))
  85. os.chdir(os.path.join(self.repo_dir,'test'))
  86. toolset_to_test = ""
  87. if self.toolset:
  88. if not isinstance(self.ci, ci_cli):
  89. toolset_to_test = toolset_info[self.toolset]['toolset']
  90. else:
  91. toolset_to_test = self.toolset
  92. self.b2(
  93. '-d1',
  94. '-p0',
  95. 'preserve-test-targets=off',
  96. '--dump-tests',
  97. '--verbose-test',
  98. '--build-dir=%s'%(self.build_dir),
  99. '--out-xml=%s'%(os.path.join(self.build_dir,'regression.xml')),
  100. '' if not toolset_to_test else 'toolset=%s'%(toolset_to_test),
  101. '' if not self.address_model else 'address-model=%s'%(self.address_model),
  102. 'variant=%s'%(self.variant),
  103. self.target
  104. )
  105. # Generate a readable test report.
  106. import build_log
  107. log_main = build_log.Main([
  108. '--output=console',
  109. os.path.join(self.build_dir,'regression.xml')])
  110. # And exit with an error if the report contains failures.
  111. # This lets the CI notice the error and report a failed build.
  112. # And hence trigger the failure machinery, like sending emails.
  113. if log_main.failed:
  114. self.ci.finish(-1)
  115. def command_before_cache(self):
  116. script_common.command_before_cache(self)
  117. os.chdir(self.b2_dir)
  118. utils.check_call("git","clean","-dfqx")
  119. utils.check_call("git","status","-bs")
  120. # utils.check_call("git","submodule","--quiet","foreach","git","clean","-dfqx")
  121. # utils.check_call("git","submodule","foreach","git","status","-bs")
  122. main(script)