compiler_status.cpp 30 KB

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