process_jam_log.cpp 29 KB

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