library_status.cpp 32 KB

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