process_jam_log.cpp 29 KB

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