library_status.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975
  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. //Note: This version of the original program builds a large table
  7. //which includes all build variations such as build/release, static/dynamic, etc.
  8. /*******************************************************************************
  9. This program was designed to work unchanged on all platforms and
  10. configurations. All output which is platform or configuration dependent
  11. is obtained from external sources such as the .xml file from
  12. process_jam_log execution, the tools/build/xxx-tools.jam files, or the
  13. output of the config_info tests.
  14. Please avoid adding platform or configuration dependencies during
  15. program maintenance.
  16. *******************************************************************************/
  17. #include "boost/filesystem/operations.hpp"
  18. #include "boost/filesystem/fstream.hpp"
  19. namespace fs = boost::filesystem;
  20. #include "detail/tiny_xml.hpp"
  21. namespace xml = boost::tiny_xml;
  22. #include "boost/iterator/transform_iterator.hpp"
  23. #include <cstdlib> // for abort, exit
  24. #include <string>
  25. #include <vector>
  26. #include <set>
  27. #include <map>
  28. #include <algorithm>
  29. #include <iostream>
  30. #include <fstream>
  31. #include <ctime>
  32. #include <stdexcept>
  33. #include <cassert>
  34. #include <utility>
  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 ignore_pass = false;
  47. bool no_warn = false;
  48. bool no_links = false;
  49. fs::directory_iterator end_itr;
  50. // transform pathname to something html can accept
  51. struct char_xlate {
  52. typedef char result_type;
  53. result_type operator()(char c) const{
  54. if(c == '/')
  55. return '-';
  56. return c;
  57. }
  58. };
  59. typedef boost::transform_iterator<char_xlate, std::string::const_iterator> html_from_path;
  60. template<class I1, class I2>
  61. std::ostream & operator<<(
  62. std::ostream &os,
  63. std::pair<I1, I2> p
  64. ){
  65. while(p.first != p.second)
  66. os << *p.first++;
  67. return os;
  68. }
  69. struct col_node {
  70. int rows, cols;
  71. bool is_leaf_directory;
  72. typedef std::map<std::string, col_node> subcolumns_t;
  73. subcolumns_t m_subcolumns;
  74. bool operator<(const col_node &cn) const;
  75. col_node() :
  76. is_leaf_directory(false)
  77. {}
  78. std::pair<int, int> get_spans();
  79. };
  80. std::pair<int, int> col_node::get_spans(){
  81. rows = 1;
  82. cols = 0;
  83. if(is_leaf_directory)
  84. cols = 1;
  85. subcolumns_t::iterator itr;
  86. for(itr = m_subcolumns.begin(); itr != m_subcolumns.end(); ++itr){
  87. std::pair<int, int> spans;
  88. spans = itr->second.get_spans();
  89. rows = std::max(rows, spans.first);
  90. cols += spans.second;
  91. }
  92. return std::make_pair(rows + 1, cols);
  93. }
  94. void build_node_tree(const fs::path & dir_root, col_node & node){
  95. bool is_leaf_directory = true;
  96. fs::directory_iterator itr(dir_root);
  97. while(itr != end_itr){
  98. if(fs::is_directory(*itr)){
  99. std::pair<col_node::subcolumns_t::iterator, bool> result
  100. = node.m_subcolumns.insert(
  101. std::make_pair(itr->leaf(), col_node())
  102. );
  103. build_node_tree(*itr, result.first->second);
  104. is_leaf_directory = false;
  105. }
  106. ++itr;
  107. }
  108. node.is_leaf_directory = is_leaf_directory;
  109. }
  110. fs::ofstream report;
  111. fs::ofstream links_file;
  112. string links_name;
  113. fs::path notes_path;
  114. string notes_html;
  115. fs::path notes_map_path;
  116. typedef std::multimap< string, string > notes_map; // key is test_name-toolset,
  117. // value is note bookmark
  118. notes_map notes;
  119. string specific_compiler; // if running on one toolset only
  120. const string empty_string;
  121. // build notes_bookmarks from notes HTML -----------------------------------//
  122. void build_notes_bookmarks()
  123. {
  124. if ( notes_map_path.empty() ) return;
  125. fs::ifstream notes_map_file( notes_map_path );
  126. if ( !notes_map_file )
  127. {
  128. std::cerr << "Could not open --notes-map input file: " << notes_map_path.string() << std::endl;
  129. std::exit( 1 );
  130. }
  131. string line;
  132. while( std::getline( notes_map_file, line ) )
  133. {
  134. string::size_type pos = 0;
  135. if ( (pos = line.find( ',', pos )) == string::npos ) continue;
  136. string key(line.substr( 0, pos ) );
  137. string bookmark( line.substr( pos+1 ) );
  138. // std::cout << "inserting \"" << key << "\",\"" << bookmark << "\"\n";
  139. notes.insert( notes_map::value_type( key, bookmark ) );
  140. }
  141. }
  142. // load_notes_html ---------------------------------------------------------//
  143. bool load_notes_html()
  144. {
  145. if ( notes_path.empty() ) return false;
  146. fs::ifstream notes_file( notes_path );
  147. if ( !notes_file )
  148. {
  149. std::cerr << "Could not open --notes input file: " << notes_path.string() << std::endl;
  150. std::exit( 1 );
  151. }
  152. string line;
  153. bool in_body( false );
  154. while( std::getline( notes_file, line ) )
  155. {
  156. if ( in_body && line.find( "</body>" ) != string::npos ) in_body = false;
  157. if ( in_body ) notes_html += line;
  158. else if ( line.find( "<body>" ) ) in_body = true;
  159. }
  160. return true;
  161. }
  162. // extract object library name from target directory string ----------------//
  163. string extract_object_library_name( const string & s )
  164. {
  165. string t( s );
  166. string::size_type pos = t.find( "/build/" );
  167. if ( pos != string::npos ) pos += 7;
  168. else if ( (pos = t.find( "/test/" )) != string::npos ) pos += 6;
  169. else return "";
  170. return t.substr( pos, t.find( "/", pos ) - pos );
  171. }
  172. // element_content ---------------------------------------------------------//
  173. const string & element_content(
  174. const xml::element & root, const string & name )
  175. {
  176. static string empty_string;
  177. xml::element_list::const_iterator itr;
  178. for ( itr = root.elements.begin();
  179. itr != root.elements.end() && (*itr)->name != name;
  180. ++itr ) {}
  181. return itr != root.elements.end() ? (*itr)->content : empty_string;
  182. }
  183. // find_element ------------------------------------------------------------//
  184. const xml::element & find_element(
  185. const xml::element & root, const string & name )
  186. {
  187. static const xml::element empty_element;
  188. xml::element_list::const_iterator itr;
  189. for ( itr = root.elements.begin();
  190. itr != root.elements.end() && (*itr)->name != name;
  191. ++itr ) {}
  192. return itr != root.elements.end() ? *((*itr).get()) : empty_element;
  193. }
  194. // attribute_value ----------------------------------------------------------//
  195. const string & attribute_value(
  196. const xml::element & element,
  197. const string & attribute_name
  198. ){
  199. xml::attribute_list::const_iterator atr;
  200. for(
  201. atr = element.attributes.begin();
  202. atr != element.attributes.end();
  203. ++atr
  204. ){
  205. if(atr->name == attribute_name)
  206. return atr->value;
  207. }
  208. static const string empty_string;
  209. return empty_string;
  210. }
  211. // generate_report ---------------------------------------------------------//
  212. // return 0 if nothing generated, 1 otherwise, except 2 if compiler msgs
  213. int generate_report(
  214. const xml::element & db,
  215. const std::string source_library_name,
  216. const string & test_type,
  217. const fs::path & target_dir,
  218. bool pass,
  219. bool always_show_run_output
  220. )
  221. {
  222. // compile msgs sometimes modified, so make a local copy
  223. string compile( ((pass && no_warn)
  224. ? empty_string : element_content( db, "compile" )) );
  225. const string & link( pass ? empty_string : element_content( db, "link" ) );
  226. const string & run( (pass && !always_show_run_output)
  227. ? empty_string : element_content( db, "run" ) );
  228. string lib( (pass ? empty_string : element_content( db, "lib" )) );
  229. // some compilers output the filename even if there are no errors or
  230. // warnings; detect this if one line of output and it contains no space.
  231. string::size_type pos = compile.find( '\n', 1 );
  232. if ( pos != string::npos && compile.size()-pos <= 2
  233. && compile.find( ' ' ) == string::npos ) compile.clear();
  234. if ( lib.empty()
  235. && (
  236. compile.empty() || test_type == "compile_fail"
  237. )
  238. && link.empty()
  239. && run.empty()
  240. )
  241. return 0;
  242. int result = 1; // some kind of msg for sure
  243. // limit compile message length
  244. if ( compile.size() > max_compile_msg_size )
  245. {
  246. compile.erase( max_compile_msg_size );
  247. compile += "...\n (remainder deleted because of excessive size)\n";
  248. }
  249. links_file << "<h2><a name=\"";
  250. links_file << std::make_pair(
  251. html_from_path(target_dir.string().begin()),
  252. html_from_path(target_dir.string().end())
  253. )
  254. << "\">"
  255. << std::make_pair(
  256. html_from_path(target_dir.string().begin()),
  257. html_from_path(target_dir.string().end())
  258. )
  259. ;
  260. links_file << "</a></h2>\n";;
  261. if ( !compile.empty() )
  262. {
  263. ++result;
  264. links_file << "<h3>Compiler output:</h3><pre>"
  265. << compile << "</pre>\n";
  266. }
  267. if ( !link.empty() )
  268. links_file << "<h3>Linker output:</h3><pre>" << link << "</pre>\n";
  269. if ( !run.empty() )
  270. links_file << "<h3>Run output:</h3><pre>" << run << "</pre>\n";
  271. // for an object library failure, generate a reference to the object
  272. // library failure message, and (once only) generate the object
  273. // library failure message itself
  274. static std::set< string > failed_lib_target_dirs; // only generate once
  275. if ( !lib.empty() )
  276. {
  277. if ( lib[0] == '\n' ) lib.erase( 0, 1 );
  278. string object_library_name( extract_object_library_name( lib ) );
  279. // changing the target directory naming scheme breaks
  280. // extract_object_library_name()
  281. assert( !object_library_name.empty() );
  282. if ( object_library_name.empty() )
  283. std::cerr << "Failed to extract object library name from " << lib << "\n";
  284. links_file << "<h3>Library build failure: </h3>\n"
  285. "See <a href=\"#"
  286. << source_library_name << "-"
  287. << object_library_name << "-"
  288. << std::make_pair(
  289. html_from_path(target_dir.string().begin()),
  290. html_from_path(target_dir.string().end())
  291. )
  292. << source_library_name << " - "
  293. << object_library_name << " - "
  294. << std::make_pair(
  295. html_from_path(target_dir.string().begin()),
  296. html_from_path(target_dir.string().end())
  297. )
  298. << "</a>";
  299. if ( failed_lib_target_dirs.find( lib ) == failed_lib_target_dirs.end() )
  300. {
  301. failed_lib_target_dirs.insert( lib );
  302. fs::path pth( locate_root / lib / "test_log.xml" );
  303. fs::ifstream file( pth );
  304. if ( file )
  305. {
  306. xml::element_ptr db = xml::parse( file, pth.string() );
  307. generate_report(
  308. *db,
  309. source_library_name,
  310. test_type,
  311. target_dir,
  312. false,
  313. false
  314. );
  315. }
  316. else
  317. {
  318. links_file << "<h2><a name=\""
  319. << object_library_name << "-"
  320. << std::make_pair(
  321. html_from_path(target_dir.string().begin()),
  322. html_from_path(target_dir.string().end())
  323. )
  324. << "\">"
  325. << object_library_name << " - "
  326. << std::make_pair(
  327. html_from_path(target_dir.string().begin()),
  328. html_from_path(target_dir.string().end())
  329. )
  330. << "</a></h2>\n"
  331. << "test_log.xml not found\n";
  332. }
  333. }
  334. }
  335. return result;
  336. }
  337. // add_notes --------------------------------------------------------------//
  338. void add_notes( const string & key, bool fail, string & sep, string & target )
  339. {
  340. notes_map::const_iterator itr = notes.lower_bound( key );
  341. if ( itr != notes.end() && itr->first == key )
  342. {
  343. for ( ; itr != notes.end() && itr->first == key; ++itr )
  344. {
  345. string note_desc( itr->second[0] == '-'
  346. ? itr->second.substr( 1 ) : itr->second );
  347. if ( fail || itr->second[0] == '-' )
  348. {
  349. target += sep;
  350. sep = ",";
  351. target += "<a href=\"";
  352. target += "#";
  353. target += note_desc;
  354. target += "\">";
  355. target += note_desc;
  356. target += "</a>";
  357. }
  358. }
  359. }
  360. }
  361. // do_cell ---------------------------------------------------------------//
  362. bool do_cell(
  363. const fs::path & target_dir,
  364. const string & lib_name,
  365. string & target,
  366. bool profile
  367. ){
  368. // return true if any results except pass_msg
  369. bool pass = false;
  370. fs::path xml_file_path( target_dir / "test_log.xml" );
  371. if ( !fs::exists( xml_file_path ) )
  372. {
  373. // suppress message because there are too many of them.
  374. // "missing" is a legitmate result as its not a requirement
  375. // that every test be run in every figuration.
  376. //std::cerr << "Missing jam_log.xml in target:\n "
  377. // << target_dir.string() << "\n";
  378. target += "<td align=\"right\">" + missing_residue_msg + "</td>";
  379. return true;
  380. }
  381. int anything_generated = 0;
  382. bool note = false;
  383. fs::ifstream file( xml_file_path );
  384. if ( !file ) // could not open jam_log.xml
  385. {
  386. std::cerr << "Can't open jam_log.xml in target:\n "
  387. << target_dir.string() << "\n";
  388. target += "<td>" + missing_residue_msg + "</td>";
  389. return false;
  390. }
  391. string test_type( "unknown" );
  392. bool always_show_run_output( false );
  393. xml::element_ptr dbp = xml::parse( file, xml_file_path.string() );
  394. const xml::element & db( *dbp );
  395. test_type = attribute_value( db, "test-type" );
  396. always_show_run_output
  397. = attribute_value( db, "show-run-output" ) == "true";
  398. std::string test_type_base( test_type );
  399. if ( test_type_base.size() > 5 )
  400. {
  401. const string::size_type trailer = test_type_base.size() - 5;
  402. if ( test_type_base.substr( trailer ) == "_fail" )
  403. {
  404. test_type_base.erase( trailer );
  405. }
  406. }
  407. if ( test_type_base.size() > 4 )
  408. {
  409. const string::size_type trailer = test_type_base.size() - 4;
  410. if ( test_type_base.substr( trailer ) == "_pyd" )
  411. {
  412. test_type_base.erase( trailer );
  413. }
  414. }
  415. const xml::element & test_type_element( find_element( db, test_type_base ) );
  416. pass = !test_type_element.name.empty()
  417. && attribute_value( test_type_element, "result" ) != "fail";
  418. if (!no_links){
  419. if(!test_type_element.name.empty())
  420. note = attribute_value( test_type_element, "result" ) == "note";
  421. anything_generated =
  422. generate_report(
  423. db,
  424. lib_name,
  425. test_type,
  426. target_dir,
  427. pass,
  428. always_show_run_output || note
  429. );
  430. }
  431. // generate the status table cell pass/warn/fail HTML
  432. target += "<td align=\"right\">";
  433. if ( anything_generated != 0 )
  434. {
  435. target += "<a href=\"";
  436. target += links_name;
  437. target += "#";
  438. std::copy(
  439. html_from_path(target_dir.string().begin()),
  440. html_from_path(target_dir.string().end()),
  441. std::back_inserter(target)
  442. );
  443. target += "\">";
  444. target += pass
  445. ? (anything_generated < 2 ? pass_msg : warn_msg)
  446. : fail_msg;
  447. target += "</a>";
  448. if ( pass && note ) target += note_msg;
  449. }
  450. else target += pass ? pass_msg : fail_msg;
  451. // if profiling
  452. if(profile && pass){
  453. // add link to profile
  454. target += " <a href=\"";
  455. target += (target_dir / "profile.txt").string();
  456. target += "\"><i>Profile</i></a>";
  457. }
  458. // if notes, generate the superscript HTML
  459. // if ( !notes.empty() )
  460. // target += get_notes( toolset, lib_name, test_name, !pass );
  461. target += "</td>";
  462. return (anything_generated != 0) || !pass;
  463. }
  464. bool visit_node_tree(
  465. const col_node & node,
  466. fs::path dir_root,
  467. const string & lib_name,
  468. string & target,
  469. bool profile
  470. ){
  471. bool retval = false;
  472. if(node.is_leaf_directory){
  473. retval = do_cell(
  474. dir_root,
  475. lib_name,
  476. target,
  477. profile
  478. );
  479. }
  480. col_node::subcolumns_t::const_iterator col_itr;
  481. for(
  482. col_itr = node.m_subcolumns.begin();
  483. col_itr != node.m_subcolumns.end();
  484. ++col_itr
  485. ){
  486. fs::path subdir = dir_root / col_itr->first;
  487. retval |= visit_node_tree(
  488. col_itr->second,
  489. subdir,
  490. lib_name,
  491. target,
  492. col_itr->first == "profile"
  493. );
  494. }
  495. return retval;
  496. }
  497. // emit results for each test
  498. void do_row(
  499. col_node test_node,
  500. const fs::path & test_dir,
  501. const string & lib_name,
  502. const string & test_name,
  503. string & target
  504. ){
  505. string::size_type row_start_pos = target.size();
  506. target += "<tr>";
  507. target += "<td>";
  508. //target += "<a href=\"" + url_prefix_dir_view + "/libs/" + lib_name + "\">";
  509. target += test_name;
  510. target += "</a>";
  511. target += "</td>";
  512. // target += "<td>" + test_type + "</td>";
  513. bool no_warn_save = no_warn;
  514. // if ( test_type.find( "fail" ) != string::npos ) no_warn = true;
  515. // emit cells on this row
  516. bool anything_to_report = visit_node_tree(
  517. test_node,
  518. test_dir,
  519. lib_name,
  520. target,
  521. false
  522. );
  523. target += "</tr>";
  524. if ( ignore_pass
  525. && ! anything_to_report )
  526. target.erase( row_start_pos );
  527. no_warn = no_warn_save;
  528. }
  529. // do_table_body -----------------------------------------------------------//
  530. void do_table_body(
  531. col_node root_node,
  532. const string & lib_name,
  533. const fs::path & test_lib_dir
  534. ){
  535. // rows are held in a vector so they can be sorted, if desired.
  536. std::vector<string> results;
  537. for ( fs::directory_iterator itr( test_lib_dir ); itr != end_itr; ++itr )
  538. {
  539. if(! fs::is_directory(*itr))
  540. continue;
  541. string test_name = itr->leaf();
  542. // strip off the ".test" is there is one
  543. string::size_type s = test_name.find( ".test" );
  544. if(string::npos != s)
  545. test_name.resize(s);
  546. results.push_back( std::string() );
  547. do_row(
  548. root_node, //*test_node_itr++,
  549. *itr, // test dir
  550. lib_name,
  551. test_name,
  552. results[results.size()-1]
  553. );
  554. }
  555. std::sort( results.begin(), results.end() );
  556. for (
  557. std::vector<string>::iterator v(results.begin());
  558. v != results.end();
  559. ++v
  560. ){
  561. report << *v << "\n";
  562. }
  563. }
  564. // column header-----------------------------------------------------------//
  565. int header_depth(const col_node & root){
  566. col_node::subcolumns_t::const_iterator itr;
  567. int max_depth = 1;
  568. for(itr = root.m_subcolumns.begin(); itr != root.m_subcolumns.end(); ++itr){
  569. max_depth = std::max(max_depth, itr->second.rows);
  570. }
  571. return max_depth;
  572. }
  573. void header_cell(int rows, int cols, const std::string & name){
  574. // add row cells
  575. report << "<td align=\"center\" " ;
  576. if(1 < cols)
  577. report << "colspan=\"" << cols << "\" " ;
  578. if(1 < rows)
  579. // span rows to the end the header
  580. report << "rowspan=\"" << rows << "\" " ;
  581. report << ">" ;
  582. report << name;
  583. report << "</td>\n";
  584. }
  585. void emit_column_headers(
  586. const col_node & node,
  587. int display_row,
  588. int current_row,
  589. int row_count
  590. ){
  591. if(current_row < display_row){
  592. if(! node.m_subcolumns.empty()){
  593. col_node::subcolumns_t::const_iterator itr;
  594. for(itr = node.m_subcolumns.begin(); itr != node.m_subcolumns.end(); ++itr){
  595. emit_column_headers(itr->second, display_row, current_row + 1, row_count);
  596. }
  597. }
  598. return;
  599. }
  600. if(node.is_leaf_directory && ! node.m_subcolumns.empty()){
  601. header_cell(row_count - current_row, 1, std::string(""));
  602. }
  603. col_node::subcolumns_t::const_iterator itr;
  604. for(itr = node.m_subcolumns.begin(); itr != node.m_subcolumns.end(); ++itr){
  605. if(1 == itr->second.rows)
  606. header_cell(row_count - current_row, itr->second.cols, itr->first);
  607. else
  608. header_cell(1, itr->second.cols, itr->first);
  609. }
  610. }
  611. fs::path find_lib_test_dir(){
  612. // walk up from the path were we started until we find
  613. // bin or bin.v2
  614. fs::path::const_iterator leaf_itr = fs::initial_path().end();
  615. fs::path test_lib_dir = fs::initial_path();
  616. for(;;){
  617. if(fs::is_directory( test_lib_dir / "bin.v2")){
  618. test_lib_dir /= "bin.v2";
  619. break;
  620. }
  621. if(fs::is_directory( test_lib_dir / "bin")){
  622. // v1 includes the word boost
  623. test_lib_dir /= "bin";
  624. test_lib_dir /= "boost";
  625. break;
  626. }
  627. if(test_lib_dir.empty())
  628. throw std::string("binary path not found");
  629. if(*leaf_itr != "libs")
  630. --leaf_itr;
  631. test_lib_dir.remove_leaf();
  632. }
  633. if(leaf_itr == fs::initial_path().end())
  634. throw std::string("must be run from within a library directory");
  635. while(leaf_itr != fs::initial_path().end()){
  636. test_lib_dir /= *leaf_itr++; // append "libs"
  637. }
  638. return test_lib_dir;
  639. }
  640. // note : uncomment the #if/#endif and what this compile !!!
  641. string find_lib_name(fs::path lib_test_dir){
  642. unsigned int count;
  643. fs::path::iterator e_itr = lib_test_dir.end();
  644. for(count = 0;; ++count){
  645. if(*--e_itr == "libs")
  646. break;
  647. if(lib_test_dir.empty())
  648. throw std::string("must be run from within a library directory");
  649. }
  650. string library_name;
  651. for(;;){
  652. library_name.append(*++e_itr);
  653. if(1 == --count)
  654. break;
  655. library_name.append("/");
  656. }
  657. return library_name;
  658. }
  659. fs::path find_boost_root(){
  660. fs::path boost_root = fs::initial_path();
  661. for(;;){
  662. if(fs::is_directory( boost_root / "boost")){
  663. break;
  664. }
  665. if(boost_root.empty())
  666. throw std::string("boost root not found");
  667. boost_root.remove_leaf();
  668. }
  669. return boost_root;
  670. }
  671. // do_table ----------------------------------------------------------------//
  672. void do_table(const string & lib_name)
  673. {
  674. col_node root_node;
  675. fs::path lib_test_dir = find_lib_test_dir();
  676. for ( fs::directory_iterator itr(lib_test_dir); itr != end_itr; ++itr )
  677. {
  678. if(! fs::is_directory(*itr))
  679. continue;
  680. build_node_tree(*itr, root_node);
  681. }
  682. // visit directory nodes and record nodetree
  683. report << "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n";
  684. // emit
  685. root_node.get_spans();
  686. int row_count = header_depth(root_node);
  687. report << "<tr>\n";
  688. report << "<td rowspan=\"" << row_count << "\">Test Name</td>\n";
  689. // emit column headers
  690. int row_index = 0;
  691. for(;;){
  692. emit_column_headers(root_node, row_index, 0, row_count);
  693. report << "</tr>" ;
  694. if(++row_index == row_count)
  695. break;
  696. report << "<tr>\n";
  697. }
  698. // now the rest of the table body
  699. do_table_body(root_node, lib_name, lib_test_dir);
  700. report << "</table>\n";
  701. }
  702. }// unnamed namespace
  703. // main --------------------------------------------------------------------//
  704. #define BOOST_NO_CPP_MAIN_SUCCESS_MESSAGE
  705. #include <boost/test/included/prg_exec_monitor.hpp>
  706. int cpp_main( int argc, char * argv[] ) // note name!
  707. {
  708. fs::path comment_path;
  709. while ( argc > 1 && *argv[1] == '-' )
  710. {
  711. if ( argc > 2 && std::strcmp( argv[1], "--compiler" ) == 0 )
  712. { specific_compiler = argv[2]; --argc; ++argv; }
  713. else if ( argc > 2 && std::strcmp( argv[1], "--locate-root" ) == 0 )
  714. { locate_root = fs::path( argv[2], fs::native ); --argc; ++argv; }
  715. else if ( argc > 2 && std::strcmp( argv[1], "--boost-root" ) == 0 )
  716. { boost_root = fs::path( argv[2], fs::native ); --argc; ++argv; }
  717. else if ( argc > 2 && std::strcmp( argv[1], "--comment" ) == 0 )
  718. { comment_path = fs::path( argv[2], fs::native ); --argc; ++argv; }
  719. else if ( argc > 2 && std::strcmp( argv[1], "--notes" ) == 0 )
  720. { notes_path = fs::path( argv[2], fs::native ); --argc; ++argv; }
  721. else if ( argc > 2 && std::strcmp( argv[1], "--notes-map" ) == 0 )
  722. { notes_map_path = fs::path( argv[2], fs::native ); --argc; ++argv; }
  723. else if ( std::strcmp( argv[1], "--ignore-pass" ) == 0 ) ignore_pass = true;
  724. else if ( std::strcmp( argv[1], "--no-warn" ) == 0 ) no_warn = true;
  725. else if ( std::strcmp( argv[1], "--v2" ) == 0 )
  726. {--argc; ++argv ;} // skip
  727. else if ( argc > 2 && std::strcmp( argv[1], "--jamfile" ) == 0)
  728. {--argc; ++argv;} // skip
  729. else { std::cerr << "Unknown option: " << argv[1] << "\n"; argc = 1; }
  730. --argc;
  731. ++argv;
  732. }
  733. if ( argc != 2 && argc != 3 )
  734. {
  735. std::cerr <<
  736. "Usage: library_status [options...] status-file [links-file]\n"
  737. " boost-root is the path to the boost tree root directory.\n"
  738. " status-file and links-file are paths to the output files.\n"
  739. " options: --compiler name Run for named compiler only\n"
  740. " --ignore-pass Do not report tests which pass all compilers\n"
  741. " --no-warn Warnings not reported if test passes\n"
  742. " --boost-root path default derived from current path.\n"
  743. " --locate-root path Path to ALL_LOCATE_TARGET for bjam;\n"
  744. " default boost-root.\n"
  745. " --comment path Path to file containing HTML\n"
  746. " to be copied into status-file.\n"
  747. " --notes path Path to file containing HTML\n"
  748. " to be copied into status-file.\n"
  749. " --notes-map path Path to file of toolset/test,n lines, where\n"
  750. " n is number of note bookmark in --notes file.\n"
  751. "Example: compiler_status --compiler gcc /boost-root cs.html cs-links.html\n"
  752. "Note: Only the leaf of the links-file path and --notes file string are\n"
  753. "used in status-file HTML links. Thus for browsing, status-file,\n"
  754. "links-file, and --notes file must all be in the same directory.\n"
  755. ;
  756. return 1;
  757. }
  758. if(boost_root.empty())
  759. boost_root = find_boost_root();
  760. if ( locate_root.empty() )
  761. locate_root = boost_root;
  762. report.open( fs::path( argv[1], fs::native ) );
  763. if ( !report )
  764. {
  765. std::cerr << "Could not open report output file: " << argv[2] << std::endl;
  766. return 1;
  767. }
  768. if ( argc == 3 )
  769. {
  770. fs::path links_path( argv[2], fs::native );
  771. links_name = links_path.leaf();
  772. links_file.open( links_path );
  773. if ( !links_file )
  774. {
  775. std::cerr << "Could not open links output file: " << argv[3] << std::endl;
  776. return 1;
  777. }
  778. }
  779. else no_links = true;
  780. build_notes_bookmarks();
  781. const string library_name = find_lib_name(fs::initial_path());
  782. char run_date[128];
  783. std::time_t tod;
  784. std::time( &tod );
  785. std::strftime( run_date, sizeof(run_date),
  786. "%X UTC, %A %d %B %Y", std::gmtime( &tod ) );
  787. report
  788. << "<html>\n"
  789. << "<head>\n"
  790. << "<title>Boost Library Status Automatic Test</title>\n"
  791. << "</head>\n"
  792. << "<body bgcolor=\"#ffffff\" text=\"#000000\">\n"
  793. << "<table border=\"0\">\n"
  794. << "<tr>\n"
  795. << "<td><img border=\"0\" "
  796. << "src=\""
  797. << boost_root / "boost.png"
  798. << "\" width=\"277\" "
  799. << "height=\"86\"></td>\n"
  800. << "<td>\n"
  801. << "<h1>Library Status: " + library_name + "</h1>\n"
  802. << "<b>Run Date:</b> "
  803. << run_date
  804. << "\n"
  805. ;
  806. if ( !comment_path.empty() )
  807. {
  808. fs::ifstream comment_file( comment_path );
  809. if ( !comment_file )
  810. {
  811. std::cerr << "Could not open \"--comment\" input file: " << comment_path.string() << std::endl;
  812. return 1;
  813. }
  814. char c;
  815. while ( comment_file.get( c ) ) { report.put( c ); }
  816. }
  817. report << "</td>\n</table>\n<br>\n";
  818. if ( !no_links )
  819. {
  820. links_file
  821. << "<html>\n"
  822. << "<head>\n"
  823. << "<title>Boost Library Status Error Log</title>\n"
  824. << "</head>\n"
  825. << "<body bgcolor=\"#ffffff\" text=\"#000000\">\n"
  826. << "<table border=\"0\">\n"
  827. << "<tr>\n"
  828. << "<td><img border=\"0\" src=\""
  829. << boost_root / "boost.png"
  830. << "\" width=\"277\" "
  831. << "height=\"86\"></td>\n"
  832. << "<td>\n"
  833. << "<h1>Library Status: " + library_name + "</h1>\n"
  834. << "<b>Run Date:</b> "
  835. << run_date
  836. << "\n</td>\n</table>\n<br>\n"
  837. ;
  838. }
  839. do_table(library_name);
  840. if ( load_notes_html() ) report << notes_html << "\n";
  841. report << "</body>\n"
  842. "</html>\n"
  843. ;
  844. if ( !no_links )
  845. {
  846. links_file
  847. << "</body>\n"
  848. "</html>\n"
  849. ;
  850. }
  851. return 0;
  852. }
粤ICP备19079148号