process_jam_log.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  1. // process jam regression test output into XML -----------------------------//
  2. // Copyright Beman Dawes 2002. Distributed under the Boost
  3. // Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/tools/regression for documentation.
  6. #include "detail/tiny_xml.hpp"
  7. #include "boost/filesystem/operations.hpp"
  8. #include "boost/filesystem/fstream.hpp"
  9. #include "boost/filesystem/exception.hpp"
  10. #include "boost/filesystem/convenience.hpp"
  11. #include <iostream>
  12. #include <string>
  13. #include <cstring>
  14. #include <map>
  15. #include <utility> // for make_pair
  16. #include <ctime>
  17. #include <cctype> // for tolower
  18. #include <cstdlib> // for exit
  19. using std::string;
  20. namespace xml = boost::tiny_xml;
  21. namespace fs = boost::filesystem;
  22. // options
  23. static bool echo = false;
  24. static bool create_dirs = false;
  25. static bool boost_build_v2 = true;
  26. namespace
  27. {
  28. struct test_info
  29. {
  30. string file_path; // relative boost-root
  31. string type;
  32. bool always_show_run_output;
  33. };
  34. typedef std::map< string, test_info > test2info_map; // key is test-name
  35. test2info_map test2info;
  36. fs::path boost_root;
  37. fs::path locate_root; // ALL_LOCATE_TARGET (or boost_root if none)
  38. // set_boost_root --------------------------------------------------------//
  39. void set_boost_root()
  40. {
  41. boost_root = fs::initial_path();
  42. for(;;)
  43. {
  44. if ( fs::exists( boost_root / "libs" ) )
  45. {
  46. fs::current_path( fs::initial_path() ); // restore initial path
  47. return;
  48. }
  49. fs::current_path( ".." );
  50. if ( boost_root == fs::current_path() )
  51. {
  52. fs::current_path( fs::initial_path() ); // restore initial path
  53. std::cout <<
  54. "Abort: process_jam_log must be run from within a boost directory tree\n";
  55. std::exit(1);
  56. }
  57. boost_root = fs::current_path();
  58. }
  59. }
  60. // append_html -------------------------------------------------------------//
  61. void append_html( const string & src, string & target )
  62. {
  63. // there are a few lines we want to ignore
  64. if ( src.find( "th target..." ) != string::npos
  65. || src.find( "cc1plus.exe: warning: changing search order for system directory" ) != string::npos
  66. || src.find( "cc1plus.exe: warning: as it has already been specified as a non-system directory" ) != string::npos
  67. ) return;
  68. // on some platforms (e.g. tru64cxx) the following line is a real performance boost
  69. target.reserve(src.size() * 2 + target.size());
  70. for ( string::size_type pos = 0; pos < src.size(); ++pos )
  71. {
  72. if ( src[pos] == '<' ) target += "&lt;";
  73. else if ( src[pos] == '>' ) target += "&gt;";
  74. else if ( src[pos] == '&' ) target += "&amp;";
  75. else target += src[pos];
  76. }
  77. }
  78. // timestamp ---------------------------------------------------------------//
  79. string timestamp()
  80. {
  81. char run_date[128];
  82. std::time_t tod;
  83. std::time( &tod );
  84. std::strftime( run_date, sizeof(run_date),
  85. "%Y-%m-%d %X UTC", std::gmtime( &tod ) );
  86. return string( run_date );
  87. }
  88. // convert path separators to forward slashes ------------------------------//
  89. void convert_path_separators( string & s )
  90. {
  91. for ( string::iterator itr = s.begin(); itr != s.end(); ++itr )
  92. if ( *itr == '\\' || *itr == '!' ) *itr = '/';
  93. }
  94. // trim_left ----------------------------------------------------------------//
  95. std::string trim_left( std::string const& s )
  96. {
  97. std::string::size_type const pos( s.find_first_not_of(' ') );
  98. return pos != std::string::npos
  99. ? s.substr( pos, s.size() - pos + 1 )
  100. : ""
  101. ;
  102. }
  103. // split --------------------------------------------------------------------//
  104. std::vector<std::string> split( std::string const& s )
  105. {
  106. std::string::size_type const pos( s.find_first_of(' ') );
  107. std::vector<std::string> result( 1, s.substr( 0, pos ) );
  108. if ( pos == std::string::npos )
  109. return result;
  110. std::vector<std::string> const rest( split( trim_left( s.substr( pos, s.size() - pos + 1 ) ) ) );
  111. result.insert( result.end(), rest.begin(), rest.end() );
  112. return result;
  113. }
  114. // extract a target directory path from a jam target string ----------------//
  115. // s may be relative to the initial_path:
  116. // ..\..\..\libs\foo\build\bin\libfoo.lib\vc7\debug\runtime-link-dynamic\boo.obj
  117. // s may be absolute:
  118. // d:\myboost\libs\foo\build\bin\libfoo.lib\vc7\debug\runtime-link-dynamic\boo.obj
  119. // return path is always relative to the boost directory tree:
  120. // libs/foo/build/bin/libfs.lib/vc7/debug/runtime-link-dynamic
  121. string target_directory( const string & s )
  122. {
  123. string temp( s );
  124. convert_path_separators( temp );
  125. temp.erase( temp.find_last_of( "/" ) ); // remove leaf
  126. temp = split( trim_left( temp ) ).back();
  127. if ( temp[0] == '.' ) temp.erase( 0, temp.find_first_not_of( "./" ) );
  128. else temp.erase( 0, locate_root.string().size()+1 );
  129. if ( echo )
  130. std::cout << "\ttarget_directory( \"" << s << "\") -> \"" << temp << "\"" << std::endl;
  131. return temp;
  132. }
  133. string::size_type target_name_end( const string & s )
  134. {
  135. string::size_type pos = s.find( ".test/" );
  136. if ( pos == string::npos ) pos = s.find( ".dll/" );
  137. if ( pos == string::npos ) pos = s.find( ".so/" );
  138. if ( pos == string::npos ) pos = s.find( ".lib/" );
  139. if ( pos == string::npos ) pos = s.find( ".pyd/" );
  140. if ( pos == string::npos ) pos = s.find( ".a/" );
  141. return pos;
  142. }
  143. string toolset( const string & s )
  144. {
  145. string::size_type pos = target_name_end( s );
  146. if ( pos == string::npos ) pos = s.find( "build/" );
  147. if ( pos == string::npos ) return "";
  148. pos = s.find( "/", pos ) + 1;
  149. return s.substr( pos, s.find( "/", pos ) - pos );
  150. }
  151. string test_name( const string & s )
  152. {
  153. string::size_type pos = target_name_end( s );
  154. if ( pos == string::npos ) return "";
  155. string::size_type pos_start = s.rfind( '/', pos ) + 1;
  156. return s.substr( pos_start,
  157. (s.find( ".test/" ) != string::npos
  158. ? pos : s.find( "/", pos )) - pos_start );
  159. }
  160. // Take a path to a target directory of test, and
  161. // returns library name corresponding to that path.
  162. string test_path_to_library_name( string const& path )
  163. {
  164. std::string result;
  165. string::size_type start_pos( path.find( "libs/" ) );
  166. if ( start_pos != string::npos )
  167. {
  168. // The path format is ...libs/functional/hash/test/something.test/....
  169. // So, the part between "libs" and "test/something.test" can be considered
  170. // as library name. But, for some libraries tests are located too deep,
  171. // say numeric/ublas/test/test1 directory, and some libraries have tests
  172. // in several subdirectories (regex/example and regex/test). So, nested
  173. // directory may belong to several libraries.
  174. // To disambituate, it's possible to place a 'sublibs' file in
  175. // a directory. It means that child directories are separate libraries.
  176. // It's still possible to have tests in the directory that has 'sublibs'
  177. // file.
  178. std::string interesting;
  179. start_pos += 5;
  180. string::size_type end_pos( path.find( ".test/", start_pos ) );
  181. end_pos = path.rfind('/', end_pos);
  182. if (path.substr(end_pos - 5, 5) == "/test")
  183. interesting = path.substr( start_pos, end_pos - 5 - start_pos );
  184. else
  185. interesting = path.substr( start_pos, end_pos - start_pos );
  186. // Take slash separate elements until we have corresponding 'sublibs'.
  187. end_pos = 0;
  188. for(;;)
  189. {
  190. end_pos = interesting.find('/', end_pos);
  191. if (end_pos == string::npos) {
  192. result = interesting;
  193. break;
  194. }
  195. result = interesting.substr(0, end_pos);
  196. if ( fs::exists( ( boost_root / "libs" ) / result / "sublibs" ) )
  197. {
  198. end_pos = end_pos + 1;
  199. }
  200. else
  201. break;
  202. }
  203. }
  204. return result;
  205. }
  206. // Tries to find target name in the string 'msg', starting from
  207. // position start.
  208. // If found, extract the directory name from the target name and
  209. // stores it in 'dir', and return the position after the target name.
  210. // Otherwise, returns string::npos.
  211. string::size_type parse_skipped_msg_aux(const string& msg,
  212. string::size_type start,
  213. string& dir)
  214. {
  215. dir.clear();
  216. string::size_type start_pos = msg.find( '<', start );
  217. if ( start_pos == string::npos ) return string::npos;
  218. ++start_pos;
  219. string::size_type end_pos = msg.find( '>', start_pos );
  220. dir += msg.substr( start_pos, end_pos - start_pos );
  221. if ( boost_build_v2 )
  222. {
  223. // The first letter is a magic value indicating
  224. // the type of grist.
  225. convert_path_separators( dir );
  226. dir.erase( 0, 1 );
  227. // We need path from root, not from 'status' dir.
  228. if (dir.find("../") == 0)
  229. dir.erase(0,3);
  230. else // dir is always relative to the boost directory tree
  231. dir.erase( 0, locate_root.string().size()+1 );
  232. }
  233. else
  234. {
  235. if ( dir[0] == '@' )
  236. {
  237. // new style build path, rooted build tree
  238. convert_path_separators( dir );
  239. dir.replace( 0, 1, "bin/" );
  240. }
  241. else
  242. {
  243. // old style build path, integrated build tree
  244. start_pos = dir.rfind( '!' );
  245. convert_path_separators( dir );
  246. string::size_type path_sep_pos = dir.find( '/', start_pos + 1 );
  247. if ( path_sep_pos != string::npos )
  248. dir.insert( path_sep_pos, "/bin" );
  249. else
  250. {
  251. // see http://article.gmane.org/gmane.comp.lib.boost.devel/146688;
  252. // the following code assumes that: a) 'dir' is not empty,
  253. // b) 'end_pos != string::npos' and c) 'msg' always ends with '...'
  254. if ( dir[dir.size() - 1] == '@' )
  255. dir += "/" + msg.substr( end_pos + 1, msg.size() - end_pos - 1 - 3 );
  256. }
  257. }
  258. }
  259. return end_pos;
  260. }
  261. // the format of paths is really kinky, so convert to normal form
  262. // first path is missing the leading "..\".
  263. // first path is missing "\bin" after "status".
  264. // second path is missing the leading "..\".
  265. // second path is missing "\bin" after "build".
  266. // second path uses "!" for some separators.
  267. void parse_skipped_msg( const string & msg,
  268. string & first_dir, string & second_dir )
  269. {
  270. string::size_type pos = parse_skipped_msg_aux(msg, 0, first_dir);
  271. if (pos == string::npos)
  272. return;
  273. parse_skipped_msg_aux(msg, pos, second_dir);
  274. }
  275. // test_log hides database details -----------------------------------------//
  276. class test_log
  277. : boost::noncopyable
  278. {
  279. const string & m_target_directory;
  280. xml::element_ptr m_root;
  281. public:
  282. test_log( const string & target_directory,
  283. const string & test_name,
  284. const string & toolset,
  285. bool force_new_file )
  286. : m_target_directory( target_directory )
  287. {
  288. if ( !force_new_file )
  289. {
  290. fs::path pth( locate_root / target_directory / "test_log.xml" );
  291. fs::ifstream file( pth );
  292. if ( file ) // existing file
  293. {
  294. try
  295. {
  296. m_root = xml::parse( file, pth.string() );
  297. return;
  298. }
  299. catch(...)
  300. {
  301. // unable to parse existing XML file, fall through
  302. }
  303. }
  304. }
  305. string library_name( test_path_to_library_name( target_directory ) );
  306. test_info info;
  307. test2info_map::iterator itr( test2info.find( library_name + "/" + test_name ) );
  308. if ( itr != test2info.end() )
  309. info = itr->second;
  310. if ( !info.file_path.empty() )
  311. library_name = test_path_to_library_name( info.file_path );
  312. if ( info.type.empty() )
  313. {
  314. if ( target_directory.find( ".lib/" ) != string::npos
  315. || target_directory.find( ".dll/" ) != string::npos
  316. || target_directory.find( ".so/" ) != string::npos
  317. || target_directory.find( ".dylib/" ) != string::npos
  318. || target_directory.find( "/build/" ) != string::npos
  319. )
  320. {
  321. info.type = "lib";
  322. }
  323. else if ( target_directory.find( ".pyd/" ) != string::npos )
  324. info.type = "pyd";
  325. }
  326. m_root.reset( new xml::element( "test-log" ) );
  327. m_root->attributes.push_back(
  328. xml::attribute( "library", library_name ) );
  329. m_root->attributes.push_back(
  330. xml::attribute( "test-name", test_name ) );
  331. m_root->attributes.push_back(
  332. xml::attribute( "test-type", info.type ) );
  333. m_root->attributes.push_back(
  334. xml::attribute( "test-program", info.file_path ) );
  335. m_root->attributes.push_back(
  336. xml::attribute( "target-directory", target_directory ) );
  337. m_root->attributes.push_back(
  338. xml::attribute( "toolset", toolset ) );
  339. m_root->attributes.push_back(
  340. xml::attribute( "show-run-output",
  341. info.always_show_run_output ? "true" : "false" ) );
  342. }
  343. ~test_log()
  344. {
  345. fs::path pth( locate_root / m_target_directory / "test_log.xml" );
  346. if ( create_dirs && !fs::exists( pth.branch_path() ) )
  347. fs::create_directories( pth.branch_path() );
  348. fs::ofstream file( pth );
  349. if ( !file )
  350. {
  351. std::cout << "*****Warning - can't open output file: "
  352. << pth.string() << "\n";
  353. }
  354. else xml::write( *m_root, file );
  355. }
  356. const string & target_directory() const { return m_target_directory; }
  357. void remove_action( const string & action_name )
  358. // no effect if action_name not found
  359. {
  360. xml::element_list::iterator itr;
  361. for ( itr = m_root->elements.begin();
  362. itr != m_root->elements.end() && (*itr)->name != action_name;
  363. ++itr ) {}
  364. if ( itr != m_root->elements.end() ) m_root->elements.erase( itr );
  365. }
  366. void add_action( const string & action_name,
  367. const string & result,
  368. const string & timestamp,
  369. const string & content )
  370. {
  371. remove_action( action_name );
  372. xml::element_ptr action( new xml::element(action_name) );
  373. m_root->elements.push_back( action );
  374. action->attributes.push_back( xml::attribute( "result", result ) );
  375. action->attributes.push_back( xml::attribute( "timestamp", timestamp ) );
  376. action->content = content;
  377. }
  378. };
  379. // message_manager maps input messages into test_log actions ---------------//
  380. class message_manager
  381. : boost::noncopyable
  382. {
  383. string m_action_name; // !empty() implies action pending
  384. // IOW, a start_message awaits stop_message
  385. string m_target_directory;
  386. string m_test_name;
  387. string m_toolset;
  388. bool m_note; // if true, run result set to "note"
  389. // set false by start_message()
  390. // data needed to stop further compile action after a compile failure
  391. // detected in the same target directory
  392. string m_previous_target_directory;
  393. bool m_compile_failed;
  394. public:
  395. message_manager() : m_note(false) {}
  396. ~message_manager() { /*assert( m_action_name.empty() );*/ }
  397. bool note() const { return m_note; }
  398. void note( bool value ) { m_note = value; }
  399. void start_message( const string & action_name,
  400. const string & target_directory,
  401. const string & test_name,
  402. const string & toolset,
  403. const string & prior_content )
  404. {
  405. assert( !target_directory.empty() );
  406. if ( !m_action_name.empty() ) stop_message( prior_content );
  407. m_action_name = action_name;
  408. m_target_directory = target_directory;
  409. m_test_name = test_name;
  410. m_toolset = toolset;
  411. m_note = false;
  412. if ( m_previous_target_directory != target_directory )
  413. {
  414. m_previous_target_directory = target_directory;
  415. m_compile_failed = false;
  416. }
  417. }
  418. void stop_message( const string & content )
  419. {
  420. if ( m_action_name.empty() ) return;
  421. stop_message( m_action_name, m_target_directory,
  422. "succeed", timestamp(), content );
  423. }
  424. void stop_message( const string & action_name,
  425. const string & target_directory,
  426. const string & result,
  427. const string & timestamp,
  428. const string & content )
  429. // the only valid action_names are "compile", "link", "run", "lib"
  430. {
  431. // My understanding of the jam output is that there should never be
  432. // a stop_message that was not preceeded by a matching start_message.
  433. // That understanding is built into message_manager code.
  434. assert( m_action_name == action_name );
  435. assert( m_target_directory == target_directory );
  436. assert( result == "succeed" || result == "fail" );
  437. // if test_log.xml entry needed
  438. if ( !m_compile_failed
  439. || action_name != "compile"
  440. || m_previous_target_directory != target_directory )
  441. {
  442. if ( action_name == "compile"
  443. && result == "fail" ) m_compile_failed = true;
  444. test_log tl( target_directory,
  445. m_test_name, m_toolset, action_name == "compile" );
  446. tl.remove_action( "lib" ); // always clear out lib residue
  447. // dependency removal
  448. if ( action_name == "lib" )
  449. {
  450. tl.remove_action( "compile" );
  451. tl.remove_action( "link" );
  452. tl.remove_action( "run" );
  453. }
  454. else if ( action_name == "compile" )
  455. {
  456. tl.remove_action( "link" );
  457. tl.remove_action( "run" );
  458. if ( result == "fail" ) m_compile_failed = true;
  459. }
  460. else if ( action_name == "link" )
  461. {
  462. tl.remove_action( "run" );
  463. }
  464. // dependency removal won't work right with random names, so assert
  465. else { assert( action_name == "run" ); }
  466. // add the "run" stop_message action
  467. tl.add_action( action_name,
  468. result == "succeed" && note() ? std::string("note") : result,
  469. timestamp, content );
  470. }
  471. m_action_name = ""; // signal no pending action
  472. m_previous_target_directory = target_directory;
  473. }
  474. };
  475. }
  476. // main --------------------------------------------------------------------//
  477. int main( int argc, char ** argv )
  478. {
  479. // Turn off synchronization with corresponding C standard library files. This
  480. // gives a significant speed improvement on platforms where the standard C++
  481. // streams are implemented using standard C files.
  482. std::ios::sync_with_stdio(false);
  483. fs::initial_path();
  484. if ( argc <= 1 )
  485. std::cout << "Usage: bjam [bjam-args] | process_jam_log [--echo] [--create-directories] [--v1|v2] [locate-root]\n"
  486. "locate-root - the same as the bjam ALL_LOCATE_TARGET\n"
  487. " parameter, if any. Default is boost-root.\n"
  488. "create-directories - if the directory for xml file doesn't exists - creates it.\n"
  489. " usually used for processing logfile on different machine\n"
  490. "v2 - bjam version 2 used (default).\n"
  491. "v1 - bjam version 1 used.\n"
  492. ;
  493. set_boost_root();
  494. boost_root.normalize();
  495. if ( argc > 1 && std::strcmp( argv[1], "--echo" ) == 0 )
  496. {
  497. echo = true;
  498. --argc; ++argv;
  499. }
  500. if (argc > 1 && std::strcmp( argv[1], "--create-directories" ) == 0 )
  501. {
  502. create_dirs = true;
  503. --argc; ++argv;
  504. }
  505. if ( argc > 1 && std::strcmp( argv[1], "--v2" ) == 0 )
  506. {
  507. boost_build_v2 = true;
  508. --argc; ++argv;
  509. }
  510. if ( argc > 1 && std::strcmp( argv[1], "--v1" ) == 0 )
  511. {
  512. boost_build_v2 = false;
  513. --argc; ++argv;
  514. }
  515. if (argc > 1)
  516. {
  517. locate_root = fs::path( argv[1], fs::native );
  518. if ( !locate_root.is_complete() )
  519. locate_root = ( fs::initial_path() / locate_root ).normalize();
  520. --argc; ++argv;
  521. }
  522. else
  523. {
  524. locate_root = boost_root;
  525. }
  526. std::cout << "boost_root: " << boost_root.string() << '\n'
  527. << "locate_root: " << locate_root.string() << '\n';
  528. message_manager mgr;
  529. string line;
  530. string content;
  531. bool capture_lines = false;
  532. std::istream* input;
  533. if (argc > 1)
  534. {
  535. input = new std::ifstream(argv[1]);
  536. }
  537. else
  538. {
  539. input = &std::cin;
  540. }
  541. // This loop looks at lines for certain signatures, and accordingly:
  542. // * Calls start_message() to start capturing lines. (start_message() will
  543. // automatically call stop_message() if needed.)
  544. // * Calls stop_message() to stop capturing lines.
  545. // * Capture lines if line capture on.
  546. int line_num = 0;
  547. while ( std::getline( *input, line ) )
  548. {
  549. ++line_num;
  550. std::vector<std::string> const line_parts( split( line ) );
  551. std::string const line_start( line_parts[0] != "...failed"
  552. ? line_parts[0]
  553. : line_parts[0] + " " + line_parts[1]
  554. );
  555. if ( echo )
  556. {
  557. std::cout
  558. << "line " << line_num << ": " << line << "\n"
  559. << "\tline_start: " << line_start << "\n";
  560. }
  561. // create map of test-name to test-info
  562. if ( line_start.find( "boost-test(" ) == 0 )
  563. {
  564. string::size_type pos = line.find( '"' );
  565. string test_name( line.substr( pos+1, line.find( '"', pos+1)-pos-1 ) );
  566. test_info info;
  567. info.always_show_run_output
  568. = line.find( "\"always_show_run_output\"" ) != string::npos;
  569. info.type = line.substr( 11, line.find( ')' )-11 );
  570. for (unsigned int i = 0; i!=info.type.size(); ++i )
  571. { info.type[i] = std::tolower( info.type[i] ); }
  572. pos = line.find( ':' );
  573. // the rest of line is missing if bjam didn't know how to make target
  574. if ( pos + 1 != line.size() )
  575. {
  576. info.file_path = line.substr( pos+3,
  577. line.find( "\"", pos+3 )-pos-3 );
  578. convert_path_separators( info.file_path );
  579. if ( info.file_path.find( "libs/libs/" ) == 0 ) info.file_path.erase( 0, 5 );
  580. if ( test_name.find( "/" ) == string::npos )
  581. test_name = "/" + test_name;
  582. test2info.insert( std::make_pair( test_name, info ) );
  583. // std::cout << test_name << ", " << info.type << ", " << info.file_path << "\n";
  584. }
  585. else
  586. {
  587. std::cout << "*****Warning - missing test path: " << line << "\n"
  588. << " (Usually occurs when bjam doesn't know how to make a target)\n";
  589. }
  590. continue;
  591. }
  592. // these actions represent both the start of a new action
  593. // and the end of a failed action
  594. else if ( line_start.find( "C++-action" ) != string::npos
  595. || line_start.find( "vc-C++" ) != string::npos
  596. || line_start.find( "C-action" ) != string::npos
  597. || line_start.find( "Cc-action" ) != string::npos
  598. || line_start.find( "vc-Cc" ) != string::npos
  599. || line_start.find( ".compile.") != string::npos
  600. || line_start.find( "compile-") != string::npos
  601. || line_start.find( "-compile") != string::npos
  602. || line_start.find( "Link-action" ) != string::npos
  603. || line_start.find( "vc-Link" ) != string::npos
  604. || line_start.find( "Archive-action" ) != string::npos
  605. || line_start.find( ".archive") != string::npos
  606. || ( line_start.find( ".link") != string::npos &&
  607. // .linkonce is present in gcc linker messages about
  608. // unresolved symbols. We don't have to parse those
  609. line_start.find( ".linkonce" ) == string::npos )
  610. )
  611. {
  612. if ( !test2info.size() )
  613. {
  614. std::cout << "*****Error - No \"boost-test\" lines encountered.\n"
  615. " (Usually occurs when bjam was envoked without the --dump-tests option\n"
  616. " or bjam was envoked in the wrong directory)\n";
  617. return 1;
  618. }
  619. string action( ( line_start.find( "Link-action" ) != string::npos
  620. || line_start.find( "vc-Link" ) != string::npos
  621. || line_start.find( "Archive-action" ) != string::npos
  622. || line_start.find( ".archive") != string::npos
  623. || line_start.find( ".link") != string::npos
  624. )
  625. ? "link" : "compile"
  626. );
  627. if ( line_start.find( "...failed " ) != string::npos )
  628. {
  629. mgr.stop_message( action, target_directory( line ),
  630. "fail", timestamp(), content );
  631. }
  632. else
  633. {
  634. string target_dir( target_directory( line ) );
  635. mgr.start_message( action, target_dir,
  636. test_name( target_dir ), toolset( target_dir ), content );
  637. }
  638. content = "\n";
  639. capture_lines = true;
  640. }
  641. // these actions are only used to stop the previous action
  642. else if ( line_start.find( "-Archive" ) != string::npos
  643. || line_start.find( "MkDir" ) == 0 )
  644. {
  645. mgr.stop_message( content );
  646. content.clear();
  647. capture_lines = false;
  648. }
  649. else if ( line_start.find( "execute-test" ) != string::npos
  650. || line_start.find( "capture-output" ) != string::npos )
  651. {
  652. if ( line_start.find( "...failed " ) != string::npos )
  653. {
  654. mgr.stop_message( "run", target_directory( line ),
  655. "fail", timestamp(), content );
  656. content = "\n";
  657. capture_lines = true;
  658. }
  659. else
  660. {
  661. string target_dir( target_directory( line ) );
  662. mgr.start_message( "run", target_dir,
  663. test_name( target_dir ), toolset( target_dir ), content );
  664. // contents of .output file for content
  665. capture_lines = false;
  666. content = "\n";
  667. fs::ifstream file( locate_root / target_dir
  668. / (test_name(target_dir) + ".output") );
  669. if ( file )
  670. {
  671. string ln;
  672. while ( std::getline( file, ln ) )
  673. {
  674. if ( ln.find( "<note>" ) != string::npos ) mgr.note( true );
  675. append_html( ln, content );
  676. content += "\n";
  677. }
  678. }
  679. }
  680. }
  681. // bjam indicates some prior dependency failed by a "...skipped" message
  682. else if ( line_start.find( "...skipped" ) != string::npos
  683. && line.find( "<directory-grist>" ) == string::npos
  684. )
  685. {
  686. mgr.stop_message( content );
  687. content.clear();
  688. capture_lines = false;
  689. if ( line.find( " for lack of " ) != string::npos )
  690. {
  691. capture_lines = ( line.find( ".run for lack of " ) == string::npos );
  692. string target_dir;
  693. string lib_dir;
  694. parse_skipped_msg( line, target_dir, lib_dir );
  695. if ( target_dir != lib_dir ) // it's a lib problem
  696. {
  697. mgr.start_message( "lib", target_dir,
  698. test_name( target_dir ), toolset( target_dir ), content );
  699. content = lib_dir;
  700. mgr.stop_message( "lib", target_dir, "fail", timestamp(), content );
  701. content = "\n";
  702. }
  703. }
  704. }
  705. else if ( line_start.find( "**passed**" ) != string::npos
  706. || line_start.find( "failed-test-file" ) != string::npos
  707. || line_start.find( "command-file-dump" ) != string::npos )
  708. {
  709. mgr.stop_message( content );
  710. content = "\n";
  711. capture_lines = true;
  712. }
  713. else if ( capture_lines ) // hang onto lines for possible later use
  714. {
  715. append_html( line, content );;
  716. content += "\n";
  717. }
  718. }
  719. mgr.stop_message( content );
  720. if (input != &std::cin)
  721. delete input;
  722. return 0;
  723. }
粤ICP备19079148号