compiler_status.cpp 33 KB

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