compiler_status.cpp 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104
  1. // Generate Compiler Status HTML from jam regression test output -----------//
  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. /*******************************************************************************
  7. This program was designed to work unchanged on all platforms and
  8. configurations. All output which is platform or configuration dependent
  9. is obtained from external sources such as the .xml file from
  10. process_jam_log execution, the tools/build/xxx-tools.jam files, or the
  11. output of the config_info tests.
  12. Please avoid adding platform or configuration dependencies during
  13. program maintenance.
  14. *******************************************************************************/
  15. #include <boost/config/warning_disable.hpp>
  16. #include "boost/config.hpp"
  17. #include "boost/filesystem/operations.hpp"
  18. #include "boost/filesystem/convenience.hpp"
  19. #include "boost/filesystem/fstream.hpp"
  20. #include "detail/tiny_xml.hpp"
  21. namespace fs = boost::filesystem;
  22. namespace xml = boost::tiny_xml;
  23. #include <cstdlib> // for abort, exit
  24. #include <cctype> // for toupper
  25. #include <string>
  26. #include <vector>
  27. #include <set>
  28. #include <map>
  29. #include <algorithm>
  30. #include <iostream>
  31. #include <fstream>
  32. #include <ctime>
  33. #include <stdexcept>
  34. #include <cassert>
  35. using std::string;
  36. const string pass_msg( "Pass" );
  37. const string warn_msg( "<i>Warn</i>" );
  38. const string fail_msg( "<font color=\"#FF0000\"><i>Fail</i></font>" );
  39. const string note_msg( "<sup>*</sup>" );
  40. const string missing_residue_msg( "<i>Missing</i>" );
  41. const std::size_t max_compile_msg_size = 10000;
  42. namespace
  43. {
  44. fs::path boost_root; // boost-root complete path
  45. fs::path locate_root; // locate-root (AKA ALL_LOCATE_TARGET) complete path
  46. bool compile_time;
  47. bool run_time;
  48. bool ignore_pass;
  49. bool no_warn;
  50. bool no_links;
  51. bool boost_build_v2 = true;
  52. fs::path jamfile_path;
  53. fs::directory_iterator end_itr;
  54. // It's immportant for reliability that we find the same compilers for each
  55. // test, and that they match the column header. So save the names at the
  56. // time column headings are generated.
  57. std::vector<string> toolsets;
  58. fs::ifstream jamfile;
  59. fs::ofstream report;
  60. fs::ofstream links_file;
  61. string links_name;
  62. fs::path notes_path;
  63. string notes_html;
  64. fs::path notes_map_path;
  65. typedef std::multimap< string, string > notes_map; // key is test_name-toolset,
  66. // value is note bookmark
  67. notes_map notes;
  68. string specific_compiler; // if running on one toolset only
  69. const string empty_string;
  70. std::vector<int> error_count;
  71. // prefix for library and test hyperlink prefix
  72. string svn_root ( "http://svn.boost.org/trac/boost/browser/trunk/" );
  73. string url_prefix_dir_view( svn_root );
  74. string url_prefix_checkout_view( svn_root );
  75. string url_suffix_text_view( "" );
  76. // get revision number (as a string) if boost_root is svn working copy -----//
  77. string revision( const fs::path & boost_root )
  78. {
  79. string rev;
  80. fs::path entries( boost_root / ".svn" / "entries" );
  81. fs::ifstream entries_file( entries );
  82. if ( entries_file )
  83. {
  84. std::getline( entries_file, rev );
  85. std::getline( entries_file, rev );
  86. std::getline( entries_file, rev );
  87. std::getline( entries_file, rev ); // revision number as a string
  88. }
  89. return rev;
  90. }
  91. // build notes_bookmarks from notes HTML -----------------------------------//
  92. void build_notes_bookmarks()
  93. {
  94. if ( notes_map_path.empty() ) return;
  95. fs::ifstream notes_map_file( notes_map_path );
  96. if ( !notes_map_file )
  97. {
  98. std::cerr << "Could not open --notes-map input file: " << notes_map_path.string() << std::endl;
  99. std::exit( 1 );
  100. }
  101. string line;
  102. while( std::getline( notes_map_file, line ) )
  103. {
  104. string::size_type pos = 0;
  105. if ( (pos = line.find( ',', pos )) == string::npos ) continue;
  106. string key(line.substr( 0, pos ) );
  107. string bookmark( line.substr( pos+1 ) );
  108. // std::cout << "inserting \"" << key << "\",\"" << bookmark << "\"\n";
  109. notes.insert( notes_map::value_type( key, bookmark ) );
  110. }
  111. }
  112. // load_notes_html ---------------------------------------------------------//
  113. bool load_notes_html()
  114. {
  115. if ( notes_path.empty() ) return false;
  116. fs::ifstream notes_file( notes_path );
  117. if ( !notes_file )
  118. {
  119. std::cerr << "Could not open --notes input file: " << notes_path.string() << std::endl;
  120. std::exit( 1 );
  121. }
  122. string line;
  123. bool in_body( false );
  124. while( std::getline( notes_file, line ) )
  125. {
  126. if ( in_body && line.find( "</body>" ) != string::npos ) in_body = false;
  127. if ( in_body ) notes_html += line;
  128. else if ( line.find( "<body>" ) ) in_body = true;
  129. }
  130. return true;
  131. }
  132. // relative path between two paths -----------------------------------------//
  133. void relative_path( const fs::path & from, const fs::path & to,
  134. fs::path & target )
  135. {
  136. if ( from.string().size() <= to.string().size() ) return;
  137. target /= "..";
  138. relative_path( from.branch_path(), to, target );
  139. return;
  140. }
  141. // extract object library name from target directory string ----------------//
  142. string extract_object_library_name( const string & s )
  143. {
  144. string t( s );
  145. string::size_type pos = t.find( "/build/" );
  146. if ( pos != string::npos ) pos += 7;
  147. else if ( (pos = t.find( "/test/" )) != string::npos ) pos += 6;
  148. else return "";
  149. return t.substr( pos, t.find( "/", pos ) - pos );
  150. }
  151. // find_file ---------------------------------------------------------------//
  152. // given a directory to recursively search
  153. bool find_file( const fs::path & dir_path, const string & name,
  154. fs::path & path_found, const string & ignore_dir_named="" )
  155. {
  156. if ( !fs::exists( dir_path ) ) return false;
  157. for ( fs::directory_iterator itr( dir_path ); itr != end_itr; ++itr )
  158. if ( fs::is_directory( *itr )
  159. && itr->filename() != ignore_dir_named )
  160. {
  161. if ( find_file( *itr, name, path_found ) ) return true;
  162. }
  163. else if ( itr->filename() == name )
  164. {
  165. path_found = *itr;
  166. return true;
  167. }
  168. return false;
  169. }
  170. // platform_desc -----------------------------------------------------------//
  171. string platform_desc()
  172. {
  173. string result = BOOST_PLATFORM;
  174. result[0] = std::toupper( result[0] );
  175. return result;
  176. }
  177. // version_desc ------------------------------------------------------------//
  178. // from locate-root/status/bin/config_info.test/xxx/.../config_info.output
  179. string version_desc( const string & compiler_name )
  180. {
  181. string result;
  182. fs::path dot_output_path;
  183. if ( find_file( locate_root / "bin/boost/status/config_info.test"
  184. / compiler_name, "config_info.output", dot_output_path )
  185. || find_file( locate_root / "status/bin/config_info.test"
  186. / compiler_name, "config_info.output", dot_output_path ) )
  187. {
  188. fs::ifstream file( dot_output_path );
  189. if ( file )
  190. {
  191. if( std::getline( file, result ) )
  192. {
  193. string::size_type pos = result.find( "version " );
  194. if ( pos != string::npos )
  195. {
  196. result.erase( 0, pos+8 );
  197. }
  198. else result.clear();
  199. }
  200. }
  201. }
  202. return result;
  203. }
  204. // compiler_desc -----------------------------------------------------------//
  205. // from boost-root/tools/build/xxx-tools.jam
  206. string compiler_desc( const string & compiler_name )
  207. {
  208. string result;
  209. fs::path tools_path( boost_root / "tools/build/v1" / (compiler_name
  210. + "-tools.jam") );
  211. if ( !fs::exists( tools_path ) )
  212. tools_path = boost_root / "tools/build" / (compiler_name + "-tools.jam");
  213. fs::ifstream file( tools_path );
  214. if ( file )
  215. {
  216. while( std::getline( file, result ) )
  217. {
  218. if ( result.substr( 0, 3 ) == "#//" )
  219. {
  220. result.erase( 0, 3 );
  221. return result;
  222. }
  223. }
  224. result.clear();
  225. }
  226. return result;
  227. }
  228. // target_directory --------------------------------------------------------//
  229. // this amounts to a request to find a unique leaf directory
  230. fs::path target_directory( const fs::path & root )
  231. {
  232. if ( !fs::exists( root ) ) return fs::path("no-such-path");
  233. fs::path child;
  234. for ( fs::directory_iterator itr( root ); itr != end_itr; ++itr )
  235. {
  236. if ( fs::is_directory( *itr ) )
  237. {
  238. // SunCC creates an internal subdirectory everywhere it writes
  239. // object files. This confuses the target_directory() algorithm.
  240. // This patch ignores the SunCC internal directory. Jens Maurer
  241. if ( (*itr).filename() == "SunWS_cache" ) continue;
  242. // SGI does something similar for template instantiations. Jens Maurer
  243. if( (*itr).filename() == "ii_files" ) continue;
  244. if ( child.empty() ) child = *itr;
  245. else
  246. {
  247. std::cout << "Warning: only first of two target possibilities will be reported for: \n "
  248. << root.string() << ": " << child.filename()
  249. << " and " << (*itr).filename() << "\n";
  250. }
  251. }
  252. }
  253. if ( child.empty() ) return root; // this dir has no children
  254. return target_directory( child );
  255. }
  256. // element_content ---------------------------------------------------------//
  257. const string & element_content(
  258. const xml::element & root, const string & name )
  259. {
  260. static string empty_string;
  261. xml::element_list::const_iterator itr;
  262. for ( itr = root.elements.begin();
  263. itr != root.elements.end() && (*itr)->name != name;
  264. ++itr ) {}
  265. return itr != root.elements.end() ? (*itr)->content : empty_string;
  266. }
  267. // find_element ------------------------------------------------------------//
  268. const xml::element empty_element;
  269. const xml::element & find_element(
  270. const xml::element & root, const string & name )
  271. {
  272. xml::element_list::const_iterator itr;
  273. for ( itr = root.elements.begin();
  274. itr != root.elements.end() && (*itr)->name != name;
  275. ++itr ) {}
  276. return itr != root.elements.end() ? *((*itr).get()) : empty_element;
  277. }
  278. // attribute_value ----------------------------------------------------------//
  279. const string & attribute_value( const xml::element & element,
  280. const string & attribute_name )
  281. {
  282. static const string empty_string;
  283. xml::attribute_list::const_iterator atr;
  284. for ( atr = element.attributes.begin();
  285. atr != element.attributes.end() && atr->name != attribute_name;
  286. ++atr ) {}
  287. return atr == element.attributes.end() ? empty_string : atr->value;
  288. }
  289. // find_bin_path -----------------------------------------------------------//
  290. // Takes a relative path from boost root to a Jamfile.
  291. // Returns the directory where the build targets from
  292. // that Jamfile are located. If not found, emits a warning
  293. // and returns empty path.
  294. const fs::path find_bin_path(const string& relative)
  295. {
  296. fs::path bin_path;
  297. if (boost_build_v2)
  298. {
  299. if ( relative == "status" )
  300. bin_path = locate_root / "bin.v2" / "libs";
  301. else
  302. {
  303. bin_path = locate_root / "bin.v2" / relative;
  304. if (!fs::exists(bin_path))
  305. bin_path = locate_root / "bin" / relative;
  306. }
  307. if (!fs::exists(bin_path))
  308. {
  309. std::cerr << "warning: could not find build results for '"
  310. << relative << "'.\n";
  311. std::cerr << "warning: tried directory "
  312. << bin_path.native_directory_string() << "\n";
  313. bin_path = "";
  314. }
  315. }
  316. else
  317. {
  318. bin_path = locate_root / "bin/boost" / relative;
  319. if (!fs::exists(bin_path))
  320. {
  321. bin_path = locate_root / "bin" / relative / "bin";
  322. if (!fs::exists(bin_path))
  323. {
  324. bin_path = fs::path( locate_root / relative / "bin" );
  325. if (!fs::exists(bin_path))
  326. {
  327. bin_path = fs::path( locate_root / "bin/boost/libs" /
  328. relative.substr( relative.find( '/' )+1 ) );
  329. }
  330. }
  331. }
  332. if (!fs::exists(bin_path))
  333. {
  334. std::cerr << "warning: could not find build results for '"
  335. << relative << "'.\n";
  336. bin_path = "";
  337. }
  338. }
  339. return bin_path;
  340. }
  341. // generate_report ---------------------------------------------------------//
  342. // return 0 if nothing generated, 1 otherwise, except 2 if compiler msgs
  343. int generate_report( const xml::element & db,
  344. const string & source_library_name,
  345. const string & test_type,
  346. const string & test_name, // possibly object library name
  347. const string & toolset,
  348. bool pass,
  349. bool always_show_run_output = false )
  350. {
  351. // compile msgs sometimes modified, so make a local copy
  352. string compile( ((pass && no_warn)
  353. ? empty_string : element_content( db, "compile" )) );
  354. const string & link( pass ? empty_string : element_content( db, "link" ) );
  355. const string & run( (pass && !always_show_run_output)
  356. ? empty_string : element_content( db, "run" ) );
  357. string lib( (pass ? empty_string : element_content( db, "lib" )) );
  358. // some compilers output the filename even if there are no errors or
  359. // warnings; detect this if one line of output and it contains no space.
  360. string::size_type pos = compile.find( '\n', 1 );
  361. if ( pos != string::npos && compile.size()-pos <= 2
  362. && compile.find( ' ' ) == string::npos ) compile.clear();
  363. if ( lib.empty()
  364. && (compile.empty() || test_type == "compile_fail")
  365. && link.empty() && run.empty() ) return 0;
  366. int result = 1; // some kind of msg for sure
  367. // limit compile message length
  368. if ( compile.size() > max_compile_msg_size )
  369. {
  370. compile.erase( max_compile_msg_size );
  371. compile += "...\n (remainder deleted because of excessive size)\n";
  372. }
  373. links_file << "<h2><a name=\""
  374. << source_library_name << "-" << test_name << "-" << toolset << "\">"
  375. << source_library_name << " - " << test_name << " - " << toolset << "</a></h2>\n";
  376. if ( !compile.empty() )
  377. {
  378. ++result;
  379. links_file << "<h3>Compiler output:</h3><pre>"
  380. << compile << "</pre>\n";
  381. }
  382. if ( !link.empty() )
  383. links_file << "<h3>Linker output:</h3><pre>" << link << "</pre>\n";
  384. if ( !run.empty() )
  385. links_file << "<h3>Run output:</h3><pre>" << run << "</pre>\n";
  386. // for an object library failure, generate a reference to the object
  387. // library failure message, and (once only) generate the object
  388. // library failure message itself
  389. static std::set< string > failed_lib_target_dirs; // only generate once
  390. if ( !lib.empty() )
  391. {
  392. if ( lib[0] == '\n' ) lib.erase( 0, 1 );
  393. string object_library_name( extract_object_library_name( lib ) );
  394. // changing the target directory naming scheme breaks
  395. // extract_object_library_name()
  396. assert( !object_library_name.empty() );
  397. if ( object_library_name.empty() )
  398. std::cerr << "Failed to extract object library name from " << lib << "\n";
  399. links_file << "<h3>Library build failure: </h3>\n"
  400. "See <a href=\"#"
  401. << source_library_name << "-"
  402. << object_library_name << "-" << toolset << "\">"
  403. << source_library_name << " - "
  404. << object_library_name << " - " << toolset << "</a>";
  405. if ( failed_lib_target_dirs.find( lib ) == failed_lib_target_dirs.end() )
  406. {
  407. failed_lib_target_dirs.insert( lib );
  408. fs::path pth( locate_root / lib / "test_log.xml" );
  409. fs::ifstream file( pth );
  410. if ( file )
  411. {
  412. xml::element_ptr db = xml::parse( file, pth.string() );
  413. generate_report( *db, source_library_name, test_type, object_library_name, toolset, false );
  414. }
  415. else
  416. {
  417. links_file << "<h2><a name=\""
  418. << object_library_name << "-" << toolset << "\">"
  419. << object_library_name << " - " << toolset << "</a></h2>\n"
  420. "test_log.xml not found\n";
  421. }
  422. }
  423. }
  424. return result;
  425. }
  426. // add_notes --------------------------------------------------------------//
  427. void add_notes( const string & key, bool fail, string & sep, string & target )
  428. {
  429. notes_map::const_iterator itr = notes.lower_bound( key );
  430. if ( itr != notes.end() && itr->first == key )
  431. {
  432. for ( ; itr != notes.end() && itr->first == key; ++itr )
  433. {
  434. string note_desc( itr->second[0] == '-'
  435. ? itr->second.substr( 1 ) : itr->second );
  436. if ( fail || itr->second[0] == '-' )
  437. {
  438. target += sep;
  439. sep = ",";
  440. target += "<a href=\"";
  441. target += "#";
  442. target += note_desc;
  443. target += "\">";
  444. target += note_desc;
  445. target += "</a>";
  446. }
  447. }
  448. }
  449. }
  450. // get_notes -------------------------------------------------------------//
  451. string get_notes( const string & toolset,
  452. const string & library, const string & test, bool fail )
  453. {
  454. string sep;
  455. string target( "<sup>" );
  456. add_notes( toolset + "/" + library + "/" + test, fail, sep, target );
  457. add_notes( "*/" + library + "/" + test, fail, sep, target );
  458. add_notes( toolset + "/" + library + "/*", fail, sep, target );
  459. add_notes( "*/" + library + "/*", fail, sep, target );
  460. if ( target == "<sup>" ) target.clear();
  461. else target += "</sup>";
  462. return target;
  463. }
  464. // do_cell ---------------------------------------------------------------//
  465. bool do_cell(
  466. int compiler,
  467. const string & lib_name,
  468. const fs::path & test_dir,
  469. const string & test_type,
  470. const string & test_name,
  471. const string & toolset,
  472. string & target,
  473. bool always_show_run_output )
  474. // return true if any results except simple pass_msg
  475. {
  476. fs::path target_dir( target_directory( test_dir / toolset ) );
  477. bool pass = false;
  478. if ( !fs::exists( target_dir / "test_log.xml" ) )
  479. {
  480. std::cerr << "Missing jam_log.xml in target:\n "
  481. << target_dir.string() << "\n";
  482. target += "<td>" + missing_residue_msg + "</td>";
  483. return true;
  484. }
  485. int anything_generated = 0;
  486. bool note = false;
  487. fs::path pth( target_dir / "test_log.xml" );
  488. fs::ifstream file( pth );
  489. if ( !file ) // could not open jam_log.xml
  490. {
  491. std::cerr << "Can't open jam_log.xml in target:\n "
  492. << target_dir.string() << "\n";
  493. target += "<td>" + missing_residue_msg + "</td>";
  494. return false;
  495. }
  496. xml::element_ptr dbp = xml::parse( file, pth.string() );
  497. const xml::element & db( *dbp );
  498. std::string test_type_base( test_type );
  499. if ( test_type_base == "run_pyd" ) test_type_base = "run";
  500. else if ( test_type_base.size() > 5 )
  501. {
  502. const string::size_type trailer = test_type_base.size() - 5;
  503. if ( test_type_base.substr( trailer ) == "_fail" )
  504. {
  505. test_type_base.erase( trailer );
  506. }
  507. }
  508. const xml::element & test_type_element( find_element( db, test_type_base ) );
  509. pass = !test_type_element.name.empty()
  510. && attribute_value( test_type_element, "result" ) != "fail";
  511. if ( !no_links )
  512. {
  513. note = attribute_value( test_type_element, "result" ) == "note";
  514. // generate bookmarked report of results, and link to it
  515. anything_generated
  516. = generate_report( db, lib_name, test_type, test_name, toolset, pass,
  517. always_show_run_output || note );
  518. }
  519. target += "<td>";
  520. // generate the status table cell pass/warn/fail HTML
  521. if ( anything_generated != 0 )
  522. {
  523. target += "<a href=\"";
  524. target += links_name;
  525. target += "#";
  526. target += lib_name;
  527. target += "-";
  528. target += test_name;
  529. target += "-";
  530. target += toolset;
  531. target += "\">";
  532. target += pass
  533. ? (anything_generated < 2 ? pass_msg : warn_msg)
  534. : fail_msg;
  535. target += "</a>";
  536. if ( pass && note ) target += note_msg;
  537. }
  538. else target += pass ? pass_msg : fail_msg;
  539. // if notes, generate the superscript HTML
  540. if ( !notes.empty() )
  541. target += get_notes( toolset, lib_name, test_name, !pass );
  542. // generate compile-time if requested
  543. if ( compile_time )
  544. {
  545. const xml::element & compile_element( find_element( db, "compile" ) );
  546. if ( !compile_element.name.empty() )
  547. {
  548. string times = attribute_value( compile_element, "timings" );
  549. if ( !times.empty() )
  550. {
  551. target += "<br>";
  552. target += times.substr( 0, times.find( " " ) );
  553. }
  554. }
  555. }
  556. // generate run-time if requested
  557. if ( run_time )
  558. {
  559. const xml::element & run_element( find_element( db, "run" ) );
  560. if ( !run_element.name.empty() )
  561. {
  562. string times = attribute_value( run_element, "timings" );
  563. if ( !times.empty() )
  564. {
  565. target += "<br>";
  566. target += times.substr( 0, times.find( " " ) );
  567. }
  568. }
  569. }
  570. if ( !pass ) ++error_count[compiler];
  571. target += "</td>";
  572. return (anything_generated != 0) || !pass;
  573. }
  574. // do_row ------------------------------------------------------------------//
  575. void do_row(
  576. const fs::path & test_dir, // locate_root / "status/bin/any_test.test"
  577. const string & test_name, // "any_test"
  578. string & target )
  579. {
  580. // get library name, test-type, test-program path, etc., from the .xml file
  581. string lib_name;
  582. string test_path( test_name ); // test_name is default if missing .test
  583. string test_type( "unknown" );
  584. bool always_show_run_output( false );
  585. fs::path xml_file_path;
  586. if ( find_file( test_dir, "test_log.xml", xml_file_path ) )
  587. {
  588. fs::ifstream file( xml_file_path );
  589. if ( file )
  590. {
  591. xml::element_ptr dbp = xml::parse( file, xml_file_path.string() );
  592. const xml::element & db( *dbp );
  593. test_path = attribute_value( db, "test-program" );
  594. lib_name = attribute_value( db, "library" );
  595. test_type = attribute_value( db, "test-type" );
  596. always_show_run_output
  597. = attribute_value( db, "show-run-output" ) == "true";
  598. }
  599. }
  600. // generate the library name, test name, and test type table data
  601. string::size_type row_start_pos = target.size();
  602. target += "<tr><td><a href=\"" + url_prefix_dir_view + "/libs/" + lib_name
  603. + "\">" + lib_name + "</a></td>";
  604. target += "<td><a href=\"" + url_prefix_checkout_view + "/" + test_path
  605. + url_suffix_text_view + "\">" + test_name + "</a>";
  606. if ( compile_time ) target += "<br> Compile time:";
  607. if ( run_time ) target += "<br> Run time:";
  608. target += "</td>";
  609. target += "<td>" + test_type + "</td>";
  610. bool no_warn_save = no_warn;
  611. //if ( test_type.find( "fail" ) != string::npos ) no_warn = true;
  612. // for each compiler, generate <td>...</td> html
  613. bool anything_to_report = false;
  614. int compiler = 0;
  615. for ( std::vector<string>::const_iterator itr=toolsets.begin();
  616. itr != toolsets.end(); ++itr, ++compiler )
  617. {
  618. anything_to_report |= do_cell( compiler, lib_name, test_dir, test_type, test_name, *itr, target,
  619. always_show_run_output );
  620. }
  621. target += "</tr>";
  622. if ( ignore_pass && !anything_to_report ) target.erase( row_start_pos );
  623. no_warn = no_warn_save;
  624. }
  625. // do_rows_for_sub_tree ----------------------------------------------------//
  626. void do_rows_for_sub_tree(
  627. const fs::path & bin_dir, std::vector<string> & results )
  628. {
  629. for ( fs::directory_iterator itr( bin_dir ); itr != end_itr; ++itr )
  630. {
  631. if ( fs::is_directory( *itr )
  632. && itr->string().find( ".test" ) == (itr->string().size()-5) )
  633. {
  634. results.push_back( std::string() );
  635. do_row( *itr,
  636. itr->filename().substr( 0, itr->filename().size()-5 ),
  637. results[results.size()-1] );
  638. }
  639. }
  640. }
  641. // find_compilers ------------------------------------------------------------//
  642. void find_compilers(const fs::path & bin_dir)
  643. {
  644. fs::directory_iterator compiler_itr( bin_dir );
  645. if ( specific_compiler.empty() )
  646. std::clog << "Using " << bin_dir.string() << " to determine compilers\n";
  647. for (; compiler_itr != end_itr; ++compiler_itr )
  648. {
  649. if ( fs::is_directory( *compiler_itr ) // check just to be sure
  650. && compiler_itr->filename() != "test" ) // avoid strange directory (Jamfile bug?)
  651. {
  652. if ( specific_compiler.size() != 0
  653. && specific_compiler != compiler_itr->filename() ) continue;
  654. toolsets.push_back( compiler_itr->filename() );
  655. string desc( compiler_desc( compiler_itr->filename() ) );
  656. string vers( version_desc( compiler_itr->filename() ) );
  657. report << "<td>"
  658. << (desc.size() ? desc : compiler_itr->filename())
  659. << (vers.size() ? (string( "<br>" ) + vers ) : string( "" ))
  660. << "</td>\n";
  661. error_count.push_back( 0 );
  662. }
  663. }
  664. }
  665. // do_table_body -----------------------------------------------------------//
  666. void do_table_body( const fs::path & bin_dir )
  667. {
  668. // rows are held in a vector so they can be sorted, if desired.
  669. std::vector<string> results;
  670. // do primary bin directory
  671. do_rows_for_sub_tree( bin_dir, results );
  672. // do subinclude bin directories
  673. jamfile.clear();
  674. jamfile.seekg(0);
  675. string line;
  676. bool run_tests = false;
  677. while( std::getline( jamfile, line ) )
  678. {
  679. bool v2(false);
  680. string::size_type sub_pos( line.find( "subinclude" ) );
  681. if ( sub_pos == string::npos ) {
  682. sub_pos = line.find( "build-project" );
  683. v2 = true;
  684. }
  685. if ( sub_pos != string::npos
  686. && line.find( '#' ) > sub_pos )
  687. {
  688. if (v2)
  689. sub_pos = line.find_first_not_of( " \t./", sub_pos+13 );
  690. else
  691. sub_pos = line.find_first_not_of( " \t./", sub_pos+10 );
  692. if ( sub_pos == string::npos ) continue;
  693. string subinclude_bin_dir(
  694. line.substr( sub_pos, line.find_first_of( " \t", sub_pos )-sub_pos ) );
  695. fs::path bin_path = find_bin_path(subinclude_bin_dir);
  696. if (!bin_path.empty())
  697. do_rows_for_sub_tree( bin_path, results );
  698. }
  699. if ( ! run_tests )
  700. {
  701. string::size_type run_pos = line.find("run-tests");
  702. if ( run_pos != string::npos && line.find_first_not_of(" \t") == run_pos )
  703. run_tests = true;
  704. }
  705. else
  706. {
  707. if ( line.find(";") != string::npos )
  708. run_tests = false;
  709. else
  710. {
  711. string::size_type pos = line.find_first_not_of( " \t" );
  712. if ( pos != string::npos && line[pos] != '#' )
  713. {
  714. string::size_type end_pos = line.find_first_of(" \t#", pos);
  715. string::iterator end = end_pos != string::npos ? line.begin() + end_pos : line.end();
  716. string run_tests_bin_dir(line.begin() + pos, end);
  717. fs::path bin_path = find_bin_path("libs/" + run_tests_bin_dir);
  718. if (!bin_path.empty())
  719. do_rows_for_sub_tree( bin_path, results );
  720. }
  721. }
  722. }
  723. }
  724. std::sort( results.begin(), results.end() );
  725. for ( std::vector<string>::iterator v(results.begin());
  726. v != results.end(); ++v )
  727. { report << *v << "\n"; }
  728. }
  729. // do_table ----------------------------------------------------------------//
  730. void do_table()
  731. {
  732. // Find test result locations, trying:
  733. // - Boost.Build V1 location with ALL_LOCATE_TARGET
  734. // - Boost.Build V2 location with top-lelve "build-dir"
  735. // - Boost.Build V1 location without ALL_LOCATE_TARGET
  736. string relative( fs::initial_path().string() );
  737. #ifdef BOOST_WINDOWS_API
  738. if (relative.size() > 1 && relative[1] == ':') relative[0] = std::tolower(relative[0]);
  739. #endif
  740. if ( relative.find(boost_root.string()) != string::npos )
  741. relative.erase( 0, boost_root.string().size()+1 );
  742. else if ( relative.find(locate_root.string()) != string::npos )
  743. relative.erase( 0, locate_root.string().size()+1 );
  744. fs::path bin_path = find_bin_path(relative);
  745. report << "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n";
  746. // generate the column headings
  747. report << "<tr><td>Library</td><td>Test Name</td>\n"
  748. "<td><a href=\"compiler_status.html#test-type\">Test Type</a></td>\n";
  749. if ( relative == "status" )
  750. {
  751. fs::recursive_directory_iterator ritr( bin_path );
  752. fs::recursive_directory_iterator end_ritr;
  753. while ( ritr != end_ritr
  754. && ((ritr->string().find( ".test" ) != (ritr->string().size()-5))
  755. || !fs::is_directory( *ritr )))
  756. ++ritr; // bypass chaff
  757. if ( ritr != end_ritr )
  758. {
  759. find_compilers( *ritr );
  760. }
  761. }
  762. else
  763. {
  764. fs::directory_iterator itr( bin_path );
  765. while ( itr != end_itr
  766. && ((itr->string().find( ".test" ) != (itr->string().size()-5))
  767. || !fs::is_directory( *itr )))
  768. ++itr; // bypass chaff
  769. if ( itr != end_itr )
  770. {
  771. find_compilers( *itr );
  772. }
  773. }
  774. report << "</tr>\n";
  775. // now the rest of the table body
  776. do_table_body( bin_path );
  777. // error total row
  778. report << "<tr> <td> &nbsp;</td><td>Number of Failures</td><td> &nbsp;</td>\n";
  779. // for each compiler, generate <td>...</td> html
  780. int compiler = 0;
  781. for ( std::vector<string>::const_iterator itr=toolsets.begin();
  782. itr != toolsets.end(); ++itr, ++compiler )
  783. {
  784. report << "<td align=\"center\">" << error_count[compiler] << "</td>\n";
  785. }
  786. report << "</tr>\n</table>\n";
  787. }
  788. } // unnamed namespace
  789. // main --------------------------------------------------------------------//
  790. #define BOOST_NO_CPP_MAIN_SUCCESS_MESSAGE
  791. #include <boost/test/included/prg_exec_monitor.hpp>
  792. int cpp_main( int argc, char * argv[] ) // note name!
  793. {
  794. fs::path comment_path;
  795. while ( argc > 1 && *argv[1] == '-' )
  796. {
  797. if ( argc > 2 && std::strcmp( argv[1], "--compiler" ) == 0 )
  798. { specific_compiler = argv[2]; --argc; ++argv; }
  799. else if ( argc > 2 && std::strcmp( argv[1], "--locate-root" ) == 0 )
  800. { locate_root = fs::path( argv[2], fs::native ); --argc; ++argv; }
  801. else if ( argc > 2 && std::strcmp( argv[1], "--comment" ) == 0 )
  802. { comment_path = fs::path( argv[2], fs::native ); --argc; ++argv; }
  803. else if ( argc > 2 && std::strcmp( argv[1], "--notes" ) == 0 )
  804. { notes_path = fs::path( argv[2], fs::native ); --argc; ++argv; }
  805. else if ( argc > 2 && std::strcmp( argv[1], "--notes-map" ) == 0 )
  806. { notes_map_path = fs::path( argv[2], fs::native ); --argc; ++argv; }
  807. else if ( std::strcmp( argv[1], "--ignore-pass" ) == 0 ) ignore_pass = true;
  808. else if ( std::strcmp( argv[1], "--no-warn" ) == 0 ) no_warn = true;
  809. else if ( std::strcmp( argv[1], "--v1" ) == 0 ) boost_build_v2 = false;
  810. else if ( std::strcmp( argv[1], "--v2" ) == 0 ) boost_build_v2 = true;
  811. else if ( argc > 2 && std::strcmp( argv[1], "--jamfile" ) == 0)
  812. { jamfile_path = fs::path( argv[2], fs::native ); --argc; ++argv; }
  813. else if ( std::strcmp( argv[1], "--compile-time" ) == 0 ) compile_time = true;
  814. else if ( std::strcmp( argv[1], "--run-time" ) == 0 ) run_time = true;
  815. else { std::cerr << "Unknown option: " << argv[1] << "\n"; argc = 1; }
  816. --argc;
  817. ++argv;
  818. }
  819. if ( argc != 3 && argc != 4 )
  820. {
  821. std::cerr <<
  822. "Usage: compiler_status [options...] boost-root status-file [links-file]\n"
  823. " boost-root is the path to the boost tree root directory.\n"
  824. " status-file and links-file are paths to the output files.\n"
  825. "Must be run from directory containing Jamfile\n"
  826. " options: --compiler name Run for named compiler only\n"
  827. " --ignore-pass Do not report tests which pass all compilers\n"
  828. " --no-warn Warnings not reported if test passes\n"
  829. " --locate-root path Path to ALL_LOCATE_TARGET for bjam;\n"
  830. " default boost-root.\n"
  831. " --comment path Path to file containing HTML\n"
  832. " to be copied into status-file.\n"
  833. " --notes path Path to file containing HTML\n"
  834. " to be copied into status-file.\n"
  835. " --notes-map path Path to file of toolset/test,n lines, where\n"
  836. " n is number of note bookmark in --notes file.\n"
  837. " --jamfile path Path to Jamfile. By default \"Jamfile\".\n"
  838. " --v1 Assume Boost.Build version 1.\n"
  839. " --v2 Assume Boost.Build version 2. (default)\n"
  840. " --ignore-pass Ignore passing tests.\n"
  841. " --no-warn Do not report warnings.\n"
  842. " --compile-time Show compile time.\n"
  843. " --run-time Show run time.\n"
  844. "Example: compiler_status --compiler gcc /boost-root cs.html cs-links.html\n"
  845. "Note: Only the leaf of the links-file path and --notes file string are\n"
  846. "used in status-file HTML links. Thus for browsing, status-file,\n"
  847. "links-file, and --notes file must all be in the same directory.\n"
  848. ;
  849. return 1;
  850. }
  851. boost_root = fs::path( argv[1], fs::native );
  852. if ( locate_root.empty() ) locate_root = boost_root;
  853. if (jamfile_path.empty())
  854. if (boost_build_v2)
  855. jamfile_path = "Jamfile.v2";
  856. else
  857. jamfile_path = "Jamfile";
  858. jamfile_path = fs::complete( jamfile_path, fs::initial_path() );
  859. jamfile.open( jamfile_path );
  860. if ( !jamfile )
  861. {
  862. std::cerr << "Could not open Jamfile: " << jamfile_path.native_file_string() << std::endl;
  863. return 1;
  864. }
  865. report.open( fs::path( argv[2], fs::native ) );
  866. if ( !report )
  867. {
  868. std::cerr << "Could not open report output file: " << argv[2] << std::endl;
  869. return 1;
  870. }
  871. if ( argc == 4 )
  872. {
  873. fs::path links_path( argv[3], fs::native );
  874. links_name = links_path.filename();
  875. links_file.open( links_path );
  876. if ( !links_file )
  877. {
  878. std::cerr << "Could not open links output file: " << argv[3] << std::endl;
  879. return 1;
  880. }
  881. }
  882. else no_links = true;
  883. build_notes_bookmarks();
  884. char run_date[128];
  885. std::time_t tod;
  886. std::time( &tod );
  887. std::strftime( run_date, sizeof(run_date),
  888. "%X UTC, %A %d %B %Y", std::gmtime( &tod ) );
  889. std::string rev = revision( boost_root );
  890. report << "<html>\n"
  891. "<head>\n"
  892. "<title>Boost Test Results</title>\n"
  893. "</head>\n"
  894. "<body bgcolor=\"#ffffff\" text=\"#000000\">\n"
  895. "<table border=\"0\">\n"
  896. "<tr>\n"
  897. "<td><img border=\"0\" src=\"http://www.boost.org/boost.png\" width=\"277\" "
  898. "height=\"86\"></td>\n"
  899. "<td>\n"
  900. "<h1>Boost Test Results - " + platform_desc() + "</h1>\n"
  901. "<b>Run</b> "
  902. << run_date;
  903. if ( !rev.empty() ) report << ", <b>Revision</b> " << rev;
  904. report << "\n";
  905. if ( compile_time )
  906. report << "<p>Times reported are elapsed wall clock time in seconds.</p>\n";
  907. if ( !comment_path.empty() )
  908. {
  909. fs::ifstream comment_file( comment_path );
  910. if ( !comment_file )
  911. {
  912. std::cerr << "Could not open \"--comment\" input file: " << comment_path.string() << std::endl;
  913. return 1;
  914. }
  915. char c;
  916. while ( comment_file.get( c ) ) { report.put( c ); }
  917. }
  918. report << "</td>\n</table>\n<br>\n";
  919. if ( !no_links )
  920. {
  921. links_file
  922. << "<html>\n"
  923. "<head>\n"
  924. "<title>Boost Test Details</title>\n"
  925. "</head>\n"
  926. "<body bgcolor=\"#ffffff\" text=\"#000000\">\n"
  927. "<table border=\"0\">\n"
  928. "<tr>\n"
  929. "<td><img border=\"0\" src=\"http://www.boost.org/boost.png\" width=\"277\" "
  930. "height=\"86\"></td>\n"
  931. "<td>\n"
  932. "<h1>Boost Test Details - " + platform_desc() + "</h1>\n"
  933. "<b>Run Date:</b> "
  934. << run_date;
  935. if ( !rev.empty() ) links_file << ", <b>Revision</b> " << rev;
  936. links_file << "\n</td>\n</table>\n<br>\n";
  937. }
  938. do_table();
  939. if ( load_notes_html() ) report << notes_html << "\n";
  940. report << "</body>\n"
  941. "</html>\n"
  942. ;
  943. if ( !no_links )
  944. {
  945. links_file
  946. << "</body>\n"
  947. "</html>\n"
  948. ;
  949. }
  950. return 0;
  951. }
粤ICP备19079148号