regression.py 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  1. #!/usr/bin/python
  2. # Copyright MetaCommunications, Inc. 2003-2007
  3. # Copyright Redshift Software, Inc. 2007
  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. import glob
  9. import optparse
  10. import os
  11. import os.path
  12. import platform
  13. import sys
  14. import time
  15. #~ Place holder for xsl_reports/util module
  16. utils = None
  17. repo_root = {
  18. 'anon' : 'http://svn.boost.org/svn/boost/',
  19. 'user' : 'https://svn.boost.org/svn/boost/'
  20. }
  21. repo_path = {
  22. 'trunk' : 'trunk',
  23. 'release' : 'branches/release',
  24. 'build' : 'trunk/tools/build/v2',
  25. 'jam' : 'tags/tools/jam/Boost_Jam_3_1_16/src',
  26. 'regression' : 'trunk/tools/regression',
  27. 'boost-build.jam'
  28. : 'trunk/boost-build.jam'
  29. }
  30. class runner:
  31. def __init__(self,root):
  32. commands = map(
  33. lambda m: m[8:].replace('_','-'),
  34. filter(
  35. lambda m: m.startswith('command_'),
  36. runner.__dict__.keys())
  37. )
  38. commands.sort()
  39. commands = "commands: %s" % ', '.join(commands)
  40. opt = optparse.OptionParser(
  41. usage="%prog [options] [commands]",
  42. description=commands)
  43. #~ Base Options:
  44. opt.add_option( '--runner',
  45. help="runner ID (e.g. 'Metacomm')" )
  46. opt.add_option( '--comment',
  47. help="an HTML comment file to be inserted in the reports" )
  48. opt.add_option( '--tag',
  49. help="the tag for the results" )
  50. opt.add_option( '--toolsets',
  51. help="comma-separated list of toolsets to test with" )
  52. opt.add_option( '--incremental',
  53. help="do incremental run (do not remove previous binaries)",
  54. action='store_true' )
  55. opt.add_option( '--timeout',
  56. help="specifies the timeout, in minutes, for a single test run/compilation",
  57. type='int' )
  58. opt.add_option( '--bjam-options',
  59. help="options to pass to the regression test" )
  60. opt.add_option( '--bjam-toolset',
  61. help="bootstrap toolset for 'bjam' executable" )
  62. opt.add_option( '--pjl-toolset',
  63. help="bootstrap toolset for 'process_jam_log' executable" )
  64. opt.add_option( '--platform' )
  65. #~ Source Options:
  66. opt.add_option( '--user',
  67. help="Boost SVN user ID" )
  68. opt.add_option( '--local',
  69. help="the name of the boost tarball" )
  70. opt.add_option( '--force-update',
  71. help="do an SVN update (if applicable) instead of a clean checkout, even when performing a full run",
  72. action='store_true' )
  73. opt.add_option( '--have-source',
  74. help="do neither a tarball download nor an SVN update; used primarily for testing script changes",
  75. action='store_true' )
  76. #~ Connection Options:
  77. opt.add_option( '--ftp',
  78. help="FTP URL to upload results to." )
  79. opt.add_option( '--proxy',
  80. help="HTTP proxy server address and port (e.g.'http://www.someproxy.com:3128')" )
  81. opt.add_option( '--ftp-proxy',
  82. help="FTP proxy server (e.g. 'ftpproxy')" )
  83. opt.add_option( '--dart-server',
  84. help="the dart server to send results to" )
  85. #~ Debug Options:
  86. opt.add_option( '--debug-level',
  87. help="debugging level; controls the amount of debugging output printed",
  88. type='int' )
  89. opt.add_option( '--send-bjam-log',
  90. help="send full bjam log of the regression run",
  91. action='store_true' )
  92. opt.add_option( '--mail',
  93. help="email address to send run notification to" )
  94. opt.add_option( '--smtp-login',
  95. help="STMP server address/login information, in the following form: <user>:<password>@<host>[:<port>]" )
  96. opt.add_option( '--skip-tests',
  97. help="do not run bjam; used for testing script changes",
  98. action='store_true' )
  99. #~ Defaults
  100. self.runner = None
  101. self.comment='comment.html'
  102. self.tag='trunk'
  103. self.toolsets=None
  104. self.incremental=False
  105. self.timeout=5
  106. self.bjam_options=''
  107. self.bjam_toolset=''
  108. self.pjl_toolset=''
  109. self.platform=self.platform_name()
  110. self.user='anonymous'
  111. self.local=None
  112. self.force_update=False
  113. self.have_source=False
  114. self.ftp=None
  115. self.proxy=None
  116. self.ftp_proxy=None
  117. self.dart_server=None
  118. self.debug_level=0
  119. self.send_bjam_log=False
  120. self.mail=None
  121. self.smtp_login=None
  122. self.skip_tests=False
  123. ( _opt_, self.actions ) = opt.parse_args(None,self)
  124. if not self.actions or self.actions == []:
  125. self.actions = [ 'regression' ]
  126. #~ Initialize option dependent values.
  127. self.regression_root = root
  128. self.boost_root = os.path.join( self.regression_root, 'boost' )
  129. self.regression_results = os.path.join( self.regression_root, 'results' )
  130. if self.pjl_toolset != 'python':
  131. self.regression_log = os.path.join( self.regression_results, 'bjam.log' )
  132. else:
  133. self.regression_log = os.path.join( self.regression_results, 'bjam.xml' )
  134. self.tools_bb_root = os.path.join( self.regression_root,'tools_bb' )
  135. self.tools_bjam_root = os.path.join( self.regression_root,'tools_bjam' )
  136. self.tools_regression_root = os.path.join( self.regression_root,'tools_regression' )
  137. self.xsl_reports_dir = os.path.join( self.tools_regression_root, 'xsl_reports' )
  138. self.timestamp_path = os.path.join( self.regression_root, 'timestamp' )
  139. if sys.platform == 'win32':
  140. self.patch_boost = 'patch_boost.bat'
  141. self.bjam = { 'name' : 'bjam.exe' }
  142. self.process_jam_log = { 'name' : 'process_jam_log.exe' }
  143. else:
  144. self.patch_boost = 'patch_boost'
  145. self.bjam = { 'name' : 'bjam' }
  146. self.process_jam_log = { 'name' : 'process_jam_log' }
  147. self.bjam = {
  148. 'name' : self.bjam['name'],
  149. 'build_cmd' : self.bjam_build_cmd,
  150. 'path' : os.path.join(self.regression_root,self.bjam['name']),
  151. 'source_dir' : self.tools_bjam_root,
  152. 'build_dir' : self.tools_bjam_root,
  153. 'build_args' : ''
  154. }
  155. self.process_jam_log = {
  156. 'name' : self.process_jam_log['name'],
  157. 'build_cmd' : self.bjam_cmd,
  158. 'path' : os.path.join(self.regression_root,self.process_jam_log['name']),
  159. 'source_dir' : os.path.join(self.tools_regression_root,'build'),
  160. 'build_dir' : os.path.join(self.tools_regression_root,'build'),
  161. 'build_args' : 'process_jam_log -d2'
  162. }
  163. if self.debug_level > 0:
  164. self.log('Regression root = %s'%self.regression_root)
  165. self.log('Boost root = %s'%self.boost_root)
  166. self.log('Regression results = %s'%self.regression_results)
  167. self.log('Regression log = %s'%self.regression_log)
  168. self.log('BB root = %s'%self.tools_bb_root)
  169. self.log('Bjam root = %s'%self.tools_bjam_root)
  170. self.log('Tools root = %s'%self.tools_regression_root)
  171. self.log('XSL reports dir = %s'%self.xsl_reports_dir)
  172. self.log('Timestamp = %s'%self.timestamp_path)
  173. self.log('Patch Boost script = %s'%self.patch_boost)
  174. self.main()
  175. #~ The various commands that make up the testing sequence...
  176. def command_cleanup(self,*args):
  177. if not args or args == None or args == []: args = [ 'source', 'bin' ]
  178. if 'source' in args:
  179. self.log( 'Cleaning up "%s" directory ...' % self.boost_root )
  180. self.rmtree( self.boost_root )
  181. if 'bin' in args:
  182. boost_bin_dir = os.path.join( self.boost_root, 'bin' )
  183. self.log( 'Cleaning up "%s" directory ...' % boost_bin_dir )
  184. self.rmtree( boost_bin_dir )
  185. boost_binv2_dir = os.path.join( self.boost_root, 'bin.v2' )
  186. self.log( 'Cleaning up "%s" directory ...' % boost_binv2_dir )
  187. self.rmtree( boost_binv2_dir )
  188. self.log( 'Cleaning up "%s" directory ...' % self.regression_results )
  189. self.rmtree( self.regression_results )
  190. def command_get_tools(self):
  191. #~ Get Boost.Build v2...
  192. self.log( 'Getting Boost.Build v2...' )
  193. if self.user and self.user != '':
  194. os.chdir( os.path.dirname(self.tools_bb_root) )
  195. self.svn_command( 'co %s %s' % (
  196. self.svn_repository_url(repo_path['build']),
  197. os.path.basename(self.tools_bb_root) ) )
  198. else:
  199. self.retry( lambda: self.download_tarball(
  200. os.path.basename(self.tools_bb_root)+".tar.bz2",
  201. self.tarball_url(repo_path['build']) ) )
  202. self.unpack_tarball(
  203. self.tools_bb_root+".tar.bz2",
  204. os.path.basename(self.tools_bb_root) )
  205. #~ Get Boost.Jam...
  206. self.log( 'Getting Boost.Jam...' )
  207. if self.user and self.user != '':
  208. os.chdir( os.path.dirname(self.tools_bjam_root) )
  209. self.svn_command( 'co %s %s' % (
  210. self.svn_repository_url(repo_path['jam']),
  211. os.path.basename(self.tools_bjam_root) ) )
  212. else:
  213. self.retry( lambda: self.download_tarball(
  214. os.path.basename(self.tools_bjam_root)+".tar.bz2",
  215. self.tarball_url(repo_path['jam']) ) )
  216. self.unpack_tarball(
  217. self.tools_bjam_root+".tar.bz2",
  218. os.path.basename(self.tools_bjam_root) )
  219. #~ Get the regression tools and utilities...
  220. self.log( 'Getting regression tools an utilities...' )
  221. if self.user and self.user != '':
  222. os.chdir( os.path.dirname(self.tools_regression_root) )
  223. self.svn_command( 'co %s %s' % (
  224. self.svn_repository_url(repo_path['regression']),
  225. os.path.basename(self.tools_regression_root) ) )
  226. else:
  227. self.retry( lambda: self.download_tarball(
  228. os.path.basename(self.tools_regression_root)+".tar.bz2",
  229. self.tarball_url(repo_path['regression']) ) )
  230. self.unpack_tarball(
  231. self.tools_regression_root+".tar.bz2",
  232. os.path.basename(self.tools_regression_root) )
  233. #~ We get a boost-build.jam to make the tool build work even if there's
  234. #~ and existing boost-build.jam above the testing root.
  235. self.log( 'Getting boost-build.jam...' )
  236. self.http_get(
  237. self.svn_repository_url(repo_path['boost-build.jam']),
  238. os.path.join( self.regression_root, 'boost-build.jam' ) )
  239. def command_get_source(self):
  240. self.refresh_timestamp()
  241. self.log( 'Getting sources (%s)...' % self.timestamp() )
  242. if self.user and self.user != '':
  243. self.retry( self.svn_checkout )
  244. else:
  245. self.retry( self.get_tarball )
  246. pass
  247. def command_update_source(self):
  248. if self.user and self.user != '' \
  249. or os.path.exists( os.path.join( self.boost_root, '.svn' ) ):
  250. open( self.timestamp_path, 'w' ).close()
  251. self.log( 'Updating sources from SVN (%s)...' % self.timestamp() )
  252. self.retry( self.svn_update )
  253. else:
  254. self.command_get_source( )
  255. pass
  256. def command_patch(self):
  257. self.import_utils()
  258. patch_boost_path = os.path.join( self.regression_root, self.patch_boost )
  259. if os.path.exists( patch_boost_path ):
  260. self.log( 'Found patch file "%s". Executing it.' % patch_boost_path )
  261. os.chdir( self.regression_root )
  262. utils.system( [ patch_boost_path ] )
  263. pass
  264. def command_setup(self):
  265. self.command_patch()
  266. self.build_if_needed(self.bjam,self.bjam_toolset)
  267. if self.pjl_toolset != 'python':
  268. self.build_if_needed(self.process_jam_log,self.pjl_toolset)
  269. def command_test(self, *args):
  270. if not args or args == None or args == []: args = [ "test", "process" ]
  271. self.import_utils()
  272. self.log( 'Making "%s" directory...' % self.regression_results )
  273. utils.makedirs( self.regression_results )
  274. results_libs = os.path.join( self.regression_results, 'libs' )
  275. results_status = os.path.join( self.regression_results, 'status' )
  276. if "clean" in args:
  277. self.command_test_clean()
  278. if "test" in args:
  279. self.command_test_run()
  280. if "process" in args:
  281. if self.pjl_toolset != 'python':
  282. self.command_test_process()
  283. def command_test_clean(self):
  284. results_libs = os.path.join( self.regression_results, 'libs' )
  285. results_status = os.path.join( self.regression_results, 'status' )
  286. self.rmtree( results_libs )
  287. self.rmtree( results_status )
  288. def command_test_run(self):
  289. self.import_utils()
  290. if self.pjl_toolset != 'python':
  291. test_cmd = '%s -d2 --dump-tests %s "--build-dir=%s" >>"%s" 2>&1' % (
  292. self.bjam_cmd( self.toolsets ),
  293. self.bjam_options,
  294. self.regression_results,
  295. self.regression_log )
  296. else:
  297. test_cmd = '%s -d1 --dump-tests --verbose-test %s "--build-dir=%s" "--out-xml=%s"' % (
  298. self.bjam_cmd( self.toolsets ),
  299. self.bjam_options,
  300. self.regression_results,
  301. self.regression_log )
  302. self.log( 'Starting tests (%s)...' % test_cmd )
  303. cd = os.getcwd()
  304. os.chdir( os.path.join( self.boost_root, 'status' ) )
  305. utils.system( [ test_cmd ] )
  306. os.chdir( cd )
  307. def command_test_process(self):
  308. self.import_utils()
  309. self.log( 'Getting test case results out of "%s"...' % self.regression_log )
  310. cd = os.getcwd()
  311. os.chdir( os.path.join( self.boost_root, 'status' ) )
  312. utils.checked_system( [
  313. '"%s" "%s" <"%s"' % (
  314. self.tool_path(self.process_jam_log),
  315. self.regression_results,
  316. self.regression_log )
  317. ] )
  318. os.chdir( cd )
  319. def command_collect_logs(self):
  320. self.import_utils()
  321. comment_path = os.path.join( self.regression_root, self.comment )
  322. if not os.path.exists( comment_path ):
  323. self.log( 'Comment file "%s" not found; creating default comment.' % comment_path )
  324. f = open( comment_path, 'w' )
  325. f.write( '<p>Tests are run on %s platform.</p>' % self.platform_name() )
  326. f.close()
  327. source = 'tarball'
  328. revision = ''
  329. svn_root_file = os.path.join( self.boost_root, '.svn' )
  330. svn_info_file = os.path.join( self.boost_root, 'svn_info.txt' )
  331. if os.path.exists( svn_root_file ):
  332. source = 'SVN'
  333. self.svn_command( 'info --xml "%s" >"%s"' % (self.boost_root,svn_info_file) )
  334. if os.path.exists( svn_info_file ):
  335. f = open( svn_info_file, 'r' )
  336. svn_info = f.read()
  337. f.close()
  338. i = svn_info.find( 'Revision:' )
  339. if i < 0: i = svn_info.find( 'revision=' ) # --xml format
  340. if i >= 0:
  341. i += 10
  342. while svn_info[i] >= '0' and svn_info[i] <= '9':
  343. revision += svn_info[i]
  344. i += 1
  345. if self.pjl_toolset != 'python':
  346. from collect_and_upload_logs import collect_logs
  347. if self.incremental:
  348. run_type = 'incremental'
  349. else:
  350. run_type = 'full'
  351. collect_logs(
  352. self.regression_results,
  353. self.runner, self.tag, self.platform, comment_path,
  354. self.timestamp_path,
  355. self.user,
  356. source, run_type,
  357. self.dart_server, self.proxy,
  358. revision )
  359. else:
  360. from process_jam_log import BJamLog2Results
  361. if self.incremental:
  362. run_type = '--incremental'
  363. else:
  364. run_type = ''
  365. BJamLog2Results([
  366. '--output='+os.path.join(self.regression_results,self.runner+'.xml'),
  367. '--runner='+self.runner,
  368. '--comment='+comment_path,
  369. '--tag='+self.tag,
  370. '--platform='+self.platform,
  371. '--source='+source,
  372. '--revision='+revision,
  373. run_type,
  374. self.regression_log
  375. ])
  376. self.compress_file(
  377. os.path.join(self.regression_results,self.runner+'.xml'),
  378. os.path.join(self.regression_results,self.runner+'.zip')
  379. )
  380. def command_upload_logs(self):
  381. self.import_utils()
  382. from collect_and_upload_logs import upload_logs
  383. if self.ftp:
  384. self.retry(
  385. lambda:
  386. upload_logs(
  387. self.regression_results,
  388. self.runner, self.tag,
  389. self.user,
  390. self.ftp_proxy,
  391. self.debug_level, self.send_bjam_log,
  392. self.timestamp_path,
  393. self.dart_server,
  394. ftp_url = self.ftp )
  395. )
  396. else:
  397. self.retry(
  398. lambda:
  399. upload_logs(
  400. self.regression_results,
  401. self.runner, self.tag,
  402. self.user,
  403. self.ftp_proxy,
  404. self.debug_level, self.send_bjam_log,
  405. self.timestamp_path,
  406. self.dart_server )
  407. )
  408. def command_regression(self):
  409. import socket
  410. import string
  411. try:
  412. mail_subject = 'Boost regression for %s on %s' % ( self.tag,
  413. string.split(socket.gethostname(), '.')[0] )
  414. start_time = time.localtime()
  415. if self.mail:
  416. self.log( 'Sending start notification to "%s"' % self.mail )
  417. self.send_mail(
  418. '%s started at %s.' % ( mail_subject, format_time( start_time ) )
  419. )
  420. self.command_get_tools()
  421. if self.local is not None:
  422. self.log( 'Using local file "%s"' % self.local )
  423. b = os.path.basename( self.local )
  424. tag = b[ 0: b.find( '.' ) ]
  425. self.log( 'Tag: "%s"' % tag )
  426. self.unpack_tarball( self.local, self.boost_root )
  427. elif self.have_source:
  428. if not self.incremental: self.command_cleanup( [ 'bin' ] )
  429. else:
  430. if self.incremental or self.force_update:
  431. if not self.incremental: self.command_cleanup( [ 'bin' ] )
  432. else:
  433. self.command_cleanup()
  434. self.command_get_source()
  435. self.command_setup()
  436. # Not specifying --toolset in command line is not enough
  437. # that would mean to use Boost.Build default ones
  438. # We can skip test only we were explictly
  439. # told to have no toolsets in command line "--toolset="
  440. if self.toolsets != '': # --toolset=,
  441. if not self.skip_tests:
  442. self.command_test()
  443. self.command_collect_logs()
  444. self.command_upload_logs()
  445. if self.mail:
  446. self.log( 'Sending report to "%s"' % self.mail )
  447. end_time = time.localtime()
  448. self.send_mail(
  449. '%s completed successfully at %s.' % ( mail_subject, format_time( end_time ) )
  450. )
  451. except:
  452. if self.mail:
  453. self.log( 'Sending report to "%s"' % self.mail )
  454. traceback_ = '\n'.join( apply( traceback.format_exception, sys.exc_info() ) )
  455. end_time = time.localtime()
  456. self.send_mail(
  457. '%s failed at %s.' % ( mail_subject, format_time( end_time ) ),
  458. traceback_ )
  459. raise
  460. def command_show_revision(self):
  461. modified = '$Date$'
  462. revision = '$Revision$'
  463. import re
  464. re_keyword_value = re.compile( r'^\$\w+:\s+(.*)\s+\$$' )
  465. print '\n\tRevision: %s' % re_keyword_value.match( revision ).group( 1 )
  466. print '\tLast modified on: %s\n' % re_keyword_value.match( modified ).group( 1 )
  467. #~ Utilities...
  468. def main(self):
  469. for action in self.actions:
  470. action_m = "command_"+action.replace('-','_')
  471. if hasattr(self,action_m):
  472. getattr(self,action_m)()
  473. def platform_name(self):
  474. # See http://article.gmane.org/gmane.comp.lib.boost.testing/933
  475. if sys.platform == 'win32':
  476. return 'Windows'
  477. elif sys.platform == 'cygwin':
  478. return 'Windows/Cygwin'
  479. return platform.system()
  480. def log(self,message):
  481. sys.stdout.flush()
  482. sys.stderr.flush()
  483. sys.stderr.write( '# %s\n' % message )
  484. sys.stderr.flush()
  485. def rmtree(self,path):
  486. if os.path.exists( path ):
  487. import shutil
  488. #~ shutil.rmtree( unicode( path ) )
  489. if sys.platform == 'win32':
  490. os.system( 'del /f /s /q "%s" >nul 2>&1' % path )
  491. shutil.rmtree( unicode( path ) )
  492. else:
  493. os.system( 'rm -f -r "%s"' % path )
  494. def refresh_timestamp( self ):
  495. if os.path.exists( self.timestamp_path ):
  496. os.unlink( self.timestamp_path )
  497. open( self.timestamp_path, 'w' ).close()
  498. def timestamp( self ):
  499. return time.strftime(
  500. '%Y-%m-%dT%H:%M:%SZ',
  501. time.gmtime( os.stat( self.timestamp_path ).st_mtime ) )
  502. def retry( self, f, max_attempts=5, sleep_secs=10 ):
  503. for attempts in range( max_attempts, -1, -1 ):
  504. try:
  505. return f()
  506. except Exception, msg:
  507. self.log( '%s failed with message "%s"' % ( f.__name__, msg ) )
  508. if attempts == 0:
  509. self.log( 'Giving up.' )
  510. raise
  511. self.log( 'Retrying (%d more attempts).' % attempts )
  512. time.sleep( sleep_secs )
  513. def http_get( self, source_url, destination_file ):
  514. import urllib
  515. proxies = None
  516. if hasattr(self,'proxy') and self.proxy is not None:
  517. proxies = { 'http' : self.proxy }
  518. src = urllib.urlopen( source_url, proxies = proxies )
  519. f = open( destination_file, 'wb' )
  520. while True:
  521. data = src.read( 16*1024 )
  522. if len( data ) == 0: break
  523. f.write( data )
  524. f.close()
  525. src.close()
  526. def import_utils(self):
  527. global utils
  528. if utils is None:
  529. sys.path.append( self.xsl_reports_dir )
  530. import utils as utils_module
  531. utils = utils_module
  532. def build_if_needed( self, tool, toolset ):
  533. self.import_utils()
  534. if os.path.exists( tool[ 'path' ] ):
  535. self.log( 'Found preinstalled "%s"; will use it.' % tool[ 'path' ] )
  536. return
  537. self.log( 'Preinstalled "%s" is not found; building one...' % tool[ 'path' ] )
  538. if toolset is None:
  539. if self.toolsets is not None:
  540. toolset = string.split( self.toolsets, ',' )[0]
  541. else:
  542. toolset = tool[ 'default_toolset' ]
  543. self.log( 'Warning: No bootstrap toolset for "%s" was specified.' % tool[ 'name' ] )
  544. self.log( ' Using default toolset for the platform (%s).' % toolset )
  545. if os.path.exists( tool[ 'source_dir' ] ):
  546. self.log( 'Found "%s" source directory "%s"' % ( tool[ 'name' ], tool[ 'source_dir' ] ) )
  547. build_cmd = tool[ 'build_cmd' ]( toolset, tool['build_args'] )
  548. self.log( 'Building "%s" (%s)...' % ( tool[ 'name'], build_cmd ) )
  549. utils.system( [ 'cd "%s"' % tool[ 'source_dir' ], build_cmd ] )
  550. else:
  551. raise 'Could not find "%s" source directory "%s"' % ( tool[ 'name' ], tool[ 'source_dir' ] )
  552. if not tool.has_key( 'build_path' ):
  553. tool[ 'build_path' ] = self.tool_path( tool )
  554. if not os.path.exists( tool[ 'build_path' ] ):
  555. raise 'Failed to find "%s" after build.' % tool[ 'build_path' ]
  556. self.log( '%s succesfully built in "%s" location' % ( tool[ 'name' ], tool[ 'build_path' ] ) )
  557. def tool_path( self, name_or_spec ):
  558. if isinstance( name_or_spec, basestring ):
  559. return os.path.join( self.regression_root, name_or_spec )
  560. if os.path.exists( name_or_spec[ 'path' ] ):
  561. return name_or_spec[ 'path' ]
  562. if name_or_spec.has_key( 'build_path' ):
  563. return name_or_spec[ 'build_path' ]
  564. build_dir = name_or_spec[ 'build_dir' ]
  565. self.log( 'Searching for "%s" in "%s"...' % ( name_or_spec[ 'name' ], build_dir ) )
  566. for root, dirs, files in os.walk( build_dir ):
  567. if name_or_spec[ 'name' ] in files:
  568. return os.path.join( root, name_or_spec[ 'name' ] )
  569. raise Exception( 'Cannot find "%s" in any of the following locations:\n%s' % (
  570. name_or_spec[ 'name' ]
  571. , '\n'.join( [ name_or_spec[ 'path' ], build_dir ] )
  572. ) )
  573. def bjam_build_cmd( self, *rest ):
  574. if sys.platform == 'win32':
  575. cmd = 'build.bat %s' % self.bjam_toolset
  576. else:
  577. cmd = './build.sh %s' % self.bjam_toolset
  578. env_setup_key = 'BJAM_ENVIRONMENT_SETUP'
  579. if os.environ.has_key( env_setup_key ):
  580. return '%s & %s' % ( os.environ[env_setup_key], cmd )
  581. return cmd
  582. def bjam_cmd( self, toolsets, args = '', *rest ):
  583. build_path = self.regression_root
  584. if build_path[-1] == '\\': build_path += '\\'
  585. if self.timeout > 0:
  586. args += ' -l%s' % (self.timeout*60)
  587. cmd = '"%(bjam)s"' +\
  588. ' "-sBOOST_BUILD_PATH=%(bbpath)s"' +\
  589. ' "-sBOOST_ROOT=%(boost)s"' +\
  590. ' "--boost=%(boost)s"' +\
  591. ' "--boost-build=%(bb)s"' +\
  592. ' "--debug-configuration"' +\
  593. ' %(arg)s'
  594. cmd %= {
  595. 'bjam' : self.tool_path( self.bjam ),
  596. 'bbpath' : os.pathsep.join([build_path,self.tools_bb_root]),
  597. 'bb' : self.tools_bb_root,
  598. 'boost' : self.boost_root,
  599. 'arg' : args }
  600. if toolsets:
  601. import string
  602. cmd += ' ' + string.join(string.split( toolsets, ',' ), ' ' )
  603. return cmd
  604. def send_mail( self, subject, msg = '' ):
  605. import smtplib
  606. if not self.smtp_login:
  607. server_name = 'mail.%s' % mail.split( '@' )[-1]
  608. user_name = None
  609. password = None
  610. else:
  611. server_name = self.smtp_login.split( '@' )[-1]
  612. ( user_name, password ) = string.split( self.smtp_login.split( '@' )[0], ':' )
  613. log( ' Sending mail through "%s"...' % server_name )
  614. smtp_server = smtplib.SMTP( server_name )
  615. smtp_server.set_debuglevel( self.debug_level )
  616. if user_name:
  617. smtp_server.login( user_name, password )
  618. smtp_server.sendmail( self.mail, [ self.mail ],
  619. 'Subject: %s\nTo: %s\n\n%s' % ( subject, self.mail, msg ) )
  620. def compress_file( self, file_path, archive_path ):
  621. self.import_utils()
  622. utils.log( 'Compressing "%s"...' % file_path )
  623. try:
  624. import zipfile
  625. z = zipfile.ZipFile( archive_path, 'w', zipfile.ZIP_DEFLATED )
  626. z.write( file_path, os.path.basename( file_path ) )
  627. z.close()
  628. utils.log( 'Done writing "%s".'% archive_path )
  629. except Exception, msg:
  630. utils.log( 'Warning: Compressing falied (%s)' % msg )
  631. utils.log( ' Trying to compress using a platform-specific tool...' )
  632. try:
  633. import zip_cmd
  634. except ImportError:
  635. script_dir = os.path.dirname( os.path.abspath( sys.argv[0] ) )
  636. utils.log( 'Could not find \'zip_cmd\' module in the script directory (%s).' % script_dir )
  637. raise Exception( 'Compressing failed!' )
  638. else:
  639. if os.path.exists( archive_path ):
  640. os.unlink( archive_path )
  641. utils.log( 'Removing stale "%s".' % archive_path )
  642. zip_cmd.main( file_path, archive_path )
  643. utils.log( 'Done compressing "%s".' % archive_path )
  644. #~ Dowloading source, from SVN...
  645. def svn_checkout( self ):
  646. os.chdir( self.regression_root )
  647. self.svn_command( 'co %s %s' % (self.svn_repository_url(self.tag),'boost') )
  648. def svn_update( self ):
  649. os.chdir( self.boost_root )
  650. self.svn_command( 'update' )
  651. def svn_command( self, command ):
  652. svn_anonymous_command_line = 'svn --non-interactive %(command)s'
  653. svn_command_line = 'svn --non-interactive --username=%(user)s %(command)s'
  654. if not hasattr(self,'user') or self.user is None or self.user == 'anonymous':
  655. cmd = svn_anonymous_command_line % { 'command': command }
  656. else:
  657. cmd = svn_command_line % { 'user': self.user, 'command': command }
  658. self.log( 'Executing SVN command "%s"' % cmd )
  659. rc = os.system( cmd )
  660. if rc != 0:
  661. raise Exception( 'SVN command "%s" failed with code %d' % ( cmd, rc ) )
  662. def svn_repository_url( self, path ):
  663. if self.user != 'anonymous' and self.user != '':
  664. return '%s%s' % (repo_root['user'],path)
  665. else:
  666. return '%s%s' % (repo_root['anon'],path)
  667. #~ Downloading and extracting source archives, from tarballs or zipballs...
  668. def get_tarball( self, *args ):
  669. if not args or args == []:
  670. args = [ 'download', 'unpack' ]
  671. tarball_path = None
  672. if hasattr(self,'local') and self.local is not None:
  673. tarball_path = self.local
  674. elif 'download' in args:
  675. tarball_path = self.download_tarball(self.boost_tarball_name(),self.boost_tarball_url())
  676. if not tarball_path:
  677. tarball_path = os.path.join( self.regression_root, self.boost_tarball_url() )
  678. if 'unpack' in args:
  679. self.unpack_tarball( tarball_path, self.boost_root )
  680. pass
  681. def download_tarball( self, tarball_name, tarball_url ):
  682. tarball_path = os.path.join( self.regression_root, tarball_name )
  683. self.log( 'Downloading "%s" to "%s"...' % ( tarball_url, os.path.dirname( tarball_path ) ) )
  684. if os.path.exists( tarball_path ):
  685. os.unlink( tarball_path )
  686. self.http_get( tarball_url, tarball_path )
  687. return tarball_path
  688. def tarball_url( self, path ):
  689. return 'http://beta.boost.org/development/snapshot.php/%s' % path
  690. def boost_tarball_name( self ):
  691. return 'boost-%s.tar.bz2' % self.tag.split( '/' )[-1]
  692. def boost_tarball_url( self ):
  693. return self.tarball_url( self.tag )
  694. def unpack_tarball( self, tarball_path, target_path ):
  695. self.log( 'Looking for old unpacked archives...' )
  696. old_boost_dirs = self.find_boost_dirs( )
  697. for old_boost_dir in old_boost_dirs:
  698. if old_boost_dir != tarball_path:
  699. self.log( 'Deleting old directory %s.' % old_boost_dir )
  700. self.rmtree( old_boost_dir )
  701. self.log( 'Unpacking boost tarball ("%s")...' % tarball_path )
  702. tarball_name = os.path.basename( tarball_path )
  703. extension = tarball_name[ tarball_name.find( '.' ) : ]
  704. if extension in ( ".tar.gz", ".tar.bz2" ):
  705. import tarfile
  706. import stat
  707. mode = os.path.splitext( extension )[1][1:]
  708. tar = tarfile.open( tarball_path, 'r:%s' % mode )
  709. for tarinfo in tar:
  710. tar.extract( tarinfo, self.regression_root )
  711. if sys.platform == 'win32' and not tarinfo.isdir():
  712. # workaround what appears to be a Win32-specific bug in 'tarfile'
  713. # (modification times for extracted files are not set properly)
  714. f = os.path.join( self.regression_root, tarinfo.name )
  715. os.chmod( f, stat.S_IWRITE )
  716. os.utime( f, ( tarinfo.mtime, tarinfo.mtime ) )
  717. tar.close()
  718. elif extension in ( ".zip" ):
  719. import zipfile
  720. z = zipfile.ZipFile( tarball_path, 'r', zipfile.ZIP_DEFLATED )
  721. for f in z.infolist():
  722. destination_file_path = os.path.join( self.regression_root, f.filename )
  723. if destination_file_path[-1] == "/": # directory
  724. if not os.path.exists( destination_file_path ):
  725. os.makedirs( destination_file_path )
  726. else: # file
  727. result = open( destination_file_path, 'wb' )
  728. result.write( z.read( f.filename ) )
  729. result.close()
  730. z.close()
  731. else:
  732. raise 'Do not know how to unpack archives with extension \"%s\"' % extension
  733. boost_dir = self.find_boost_dirs()[0]
  734. self.log( ' Unpacked into directory "%s"' % boost_dir )
  735. if os.path.exists( target_path ):
  736. self.log( 'Deleting "%s" directory...' % target_path )
  737. self.rmtree( target_path )
  738. self.log( 'Renaming "%s" into "%s"' % ( boost_dir, target_path ) )
  739. os.rename( boost_dir, target_path )
  740. def find_boost_dirs( self ):
  741. return [
  742. x for x in
  743. glob.glob( os.path.join( self.regression_root, 'boost[-_]*' ) )
  744. if os.path.isdir( x )
  745. ]
粤ICP备19079148号