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