process_jam_log.cpp 29 KB

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