compiler_status.cpp 32 KB

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