compiler_status.cpp 32 KB

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