summaryrefslogtreecommitdiff
path: root/tools/regression/src/library_status.cpp
blob: 3faa0f63c94ffa44e87d4b89e2c5c1532294218c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
//  Generate Library Status HTML from jam regression test output  -----------//

//  Copyright Bryce Lelbach 2011 
//  Copyright Beman Dawes 2002-2011.

//  Distributed under the Boost Software License, Version 1.0. (See accompanying
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//  See http://www.boost.org/tools/regression/ for documentation.

//Note: This version of the original program builds a large table
//which includes all build variations such as build/release, static/dynamic, etc.


/*******************************************************************************

This program was designed to work unchanged on all platforms and
configurations.  All output which is platform or configuration dependent
is obtained from external sources such as the .xml file from
process_jam_log execution, the tools/build/xxx-tools.jam files, or the
output of the config_info tests.

Please avoid adding platform or configuration dependencies during
program maintenance.

*******************************************************************************/

#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/foreach.hpp>

namespace fs = boost::filesystem;

#include "detail/tiny_xml.hpp"
namespace xml = boost::tiny_xml;

#include <boost/iterator/transform_iterator.hpp>

#include <cstdlib>  // for abort, exit
#include <string>
#include <vector>
#include <set>
#include <utility>  // for make_pair on STLPort
#include <map>
#include <algorithm> // max_element, find_if
#include <iostream>
#include <fstream>
#include <ctime>
#include <stdexcept>
#include <cassert>
#include <utility> // for pair

using std::string;

const string pass_msg( "Pass" );
const string warn_msg( "<i>Warn</i>" );
const string fail_msg( "<font color=\"#FF0000\"><i>Fail</i></font>" );
const string missing_residue_msg( "<i>Missing</i>" );

const std::size_t max_compile_msg_size = 10000;

namespace
{
    fs::path locate_root; // locate-root (AKA ALL_LOCATE_TARGET) complete path
    bool ignore_pass = false;
    bool no_warn = false;
    bool no_links = false;

    // transform pathname to something html can accept
    struct char_xlate {
        typedef char result_type;
        result_type operator()(char c) const{
            if(c == '/' || c == '\\')
                return '-';
            return c;
        }
    };
    typedef boost::transform_iterator<char_xlate, std::string::const_iterator> html_from_path; 

    template<class I1, class I2>
    std::ostream & operator<<(
    std::ostream &os, 
    std::pair<I1, I2> p
    ){
        while(p.first != p.second)
            os << *p.first++;
        return os;
    }

    struct col_node {
        int rows, cols;
        bool is_leaf;
        typedef std::pair<const std::string, col_node> subcolumn;
        typedef std::map<std::string, col_node> subcolumns_t;
        subcolumns_t m_subcolumns;
        bool operator<(const col_node &cn) const;
        col_node() :
            is_leaf(false)
        {}
        std::pair<int, int> get_spans();
    };

    std::pair<int, int> col_node::get_spans(){
        rows = 1;
        cols = 0;
        if(is_leaf){
            cols = 1;
        }
        if(! m_subcolumns.empty()){
            BOOST_FOREACH(
                subcolumn & s,
                m_subcolumns
            ){
                std::pair<int, int> spans;
                spans = s.second.get_spans();
                rows = (std::max)(rows, spans.first);
                cols += spans.second;
            }
            ++rows;
        }
        return std::make_pair(rows, cols);
    }

    void build_node_tree(const fs::path & dir_root, col_node & node){
        bool has_directories = false;
        bool has_files = false;
        BOOST_FOREACH(
            fs::directory_entry & d,
            std::make_pair(
                fs::directory_iterator(dir_root), 
                fs::directory_iterator()
            )
         ){
             if(fs::is_directory(d)){
                has_directories = true;
                std::pair<col_node::subcolumns_t::iterator, bool> result 
                    = node.m_subcolumns.insert(
                        std::make_pair(d.path().filename().string(), col_node())
                    );
                build_node_tree(d, result.first->second);
             }
             else{
                 has_files = true;
             }
        }
        if(has_directories && has_files)
            throw std::string("invalid bin directory structure");
        node.is_leaf = has_files;
    }

    fs::ofstream report;
    fs::ofstream links_file;
    string links_name;

    string specific_compiler; // if running on one toolset only

    const string empty_string;

    //  extract object library name from target directory string  ----------------//

    string extract_object_library_name( const string & s )
    {
        string t( s );
        string::size_type pos = t.find( "/build/" );
        if ( pos != string::npos ) pos += 7;
        else if ( (pos = t.find( "/test/" )) != string::npos ) pos += 6;
        else return "";
        return t.substr( pos, t.find( "/", pos ) - pos );
    }

    //  find_element  ------------------------------------------------------------//

    struct element_equal {
        const string & m_name;
        element_equal(const string & name) :
            m_name(name)
        {}
        bool operator()(const xml::element_ptr & xep) const {
            return xep.get()->name == m_name;
        }
    };

    xml::element_list::const_iterator find_element(
        const xml::element & root, const string & name 
    ){
        return std::find_if(
            root.elements.begin(), 
            root.elements.end(), 
            element_equal(name)
        );
    }

    //  element_content  ---------------------------------------------------------//
    const string & element_content(
        const xml::element & root, const string & name
    ){ 
        xml::element_list::const_iterator itr;
        itr = find_element(root, name);
        if(root.elements.end() == itr)
            return empty_string;
        return (*itr)->content;
    }

    //  attribute_value  ----------------------------------------------------------//

    struct attribute_equal {
        const string & m_name;
        attribute_equal(const string & name) :
            m_name(name)
        {}
        bool operator()(const xml::attribute & a) const {
            return a.name == m_name;
        }
    };

    const string & attribute_value( 
        const xml::element & element,
        const string & attribute_name 
    ){
        xml::attribute_list::const_iterator itr;
        itr = std::find_if(
            element.attributes.begin(), 
            element.attributes.end(), 
            attribute_equal(attribute_name)
        );
        if(element.attributes.end() == itr){
            static const string empty_string;
            return empty_string;
        }
        return itr->value;
    }

    //  generate_report  ---------------------------------------------------------//

    // return 0 if nothing generated, 1 otherwise, except 2 if compiler msgs
    int generate_report( 
        const xml::element & db,
        const std::string source_library_name,
        const string & test_type,
        const fs::path & target_dir,
        bool pass,
        bool always_show_run_output 
        )
    {
        // compile msgs sometimes modified, so make a local copy
        string compile( ((pass && no_warn)
            ? empty_string :  element_content( db, "compile" )) );

        const string & link( pass ? empty_string : element_content( db, "link" ) );
        const string & run( (pass && !always_show_run_output)
            ? empty_string : element_content( db, "run" ) );
        string lib( (pass ? empty_string : element_content( db, "lib" )) );

        // some compilers output the filename even if there are no errors or
        // warnings; detect this if one line of output and it contains no space.
        string::size_type pos = compile.find( '\n', 1 );
        if ( pos != string::npos && compile.size()-pos <= 2
            && compile.find( ' ' ) == string::npos ) compile.clear();

        if ( lib.empty() 
            && (
                compile.empty() || test_type == "compile_fail"
            ) 
            && link.empty() 
            && run.empty()
        ) 
            return 0; 

        int result = 1; // some kind of msg for sure

        // limit compile message length
        if ( compile.size() > max_compile_msg_size )
        {
            compile.erase( max_compile_msg_size );
            compile += "...\n   (remainder deleted because of excessive size)\n";
        }

        const string target_dir_string = target_dir.string();

        links_file << "<h2><a name=\"";
        links_file << std::make_pair(
            html_from_path(target_dir_string.begin()), 
            html_from_path(target_dir_string.end())
            )
            << "\">"
            << std::make_pair(
            html_from_path(target_dir_string.begin()), 
            html_from_path(target_dir_string.end())
            )
            ;
        links_file << "</a></h2>\n";;

        if ( !compile.empty() )
        {
            ++result;
            links_file << "<h3>Compiler output:</h3><pre>"
                << compile << "</pre>\n";
        }
        if ( !link.empty() )
            links_file << "<h3>Linker output:</h3><pre>" << link << "</pre>\n";
        if ( !run.empty() )
            links_file << "<h3>Run output:</h3><pre>" << run << "</pre>\n";

        // for an object library failure, generate a reference to the object
        // library failure message, and (once only) generate the object
        // library failure message itself
        static std::set< string > failed_lib_target_dirs; // only generate once
        if ( !lib.empty() )
        {
            if ( lib[0] == '\n' ) lib.erase( 0, 1 );
            string object_library_name( extract_object_library_name( lib ) );

            // changing the target directory naming scheme breaks
            // extract_object_library_name()
            assert( !object_library_name.empty() );
            if ( object_library_name.empty() )
                std::cerr << "Failed to extract object library name from " << lib << "\n";

            links_file << "<h3>Library build failure: </h3>\n"
                "See <a href=\"#"
                << source_library_name << "-"
                << object_library_name << "-" 
                << std::make_pair(
                html_from_path(target_dir_string.begin()), 
                html_from_path(target_dir_string.end())
                )
                << source_library_name << " - "
                << object_library_name << " - " 
                << std::make_pair(
                html_from_path(target_dir_string.begin()), 
                html_from_path(target_dir_string.end())
                )
                << "</a>";
            if ( failed_lib_target_dirs.find( lib ) == failed_lib_target_dirs.end() )
            {
                failed_lib_target_dirs.insert( lib );
                fs::path pth( locate_root / lib / "test_log.xml" );
                fs::ifstream file( pth );
                if ( file )
                {
                    xml::element_ptr db = xml::parse( file, pth.string() );
                    generate_report( 
                        *db, 
                        source_library_name, 
                        test_type,
                        target_dir,
                        false,
                        false
                    );
                }
                else
                {
                    links_file << "<h2><a name=\""
                        << object_library_name << "-" 
                        << std::make_pair(
                        html_from_path(target_dir_string.begin()), 
                        html_from_path(target_dir_string.end())
                        )
                        << "\">"
                        << object_library_name << " - " 
                        << std::make_pair(
                        html_from_path(target_dir_string.begin()), 
                        html_from_path(target_dir_string.end())
                        )
                        << "</a></h2>\n"
                        << "test_log.xml not found\n";
                }
            }
        }
        return result;
    }

    struct has_fail_result {
        //bool operator()(const boost::shared_ptr<const xml::element> e) const {
        bool operator()(const xml::element_ptr & e) const {
            return attribute_value(*e, "result") == "fail";
        }
    };

    //  do_cell  ---------------------------------------------------------------//
    bool do_cell(
        const fs::path & target_dir,
        const string & lib_name,
        const string & test_name,
        string & target,
        bool profile
    ){
        // return true if any results except pass_msg
        bool pass = false;

        fs::path xml_file_path( target_dir / "test_log.xml" );
        if ( !fs::exists( xml_file_path ) )
        {
            fs::path test_path = target_dir / (test_name + ".test");
            target += "<td align=\"right\">";
            target += fs::exists( test_path) ? pass_msg : fail_msg;
            target += "</td>";
            return true;
        }


        string test_type( "unknown" );
        bool always_show_run_output( false );

        fs::ifstream file( xml_file_path );
        xml::element_ptr dbp = xml::parse( file, xml_file_path.string() );
        const xml::element & db( *dbp );

        always_show_run_output
            = attribute_value( db, "show-run-output" ) == "true";

        // if we don't find any failures
        // mark it as a pass
        pass = (db.elements.end() == std::find_if(
            db.elements.begin(),
            db.elements.end(),
            has_fail_result()
        ));

        int anything_generated = 0;
        if (!no_links){
            anything_generated = 
                generate_report(
                db, 
                lib_name, 
                test_type,
                target_dir,
                pass,
                always_show_run_output
            );
        }

        // generate the status table cell pass/warn/fail HTML
        target += "<td align=\"right\">";
        if ( anything_generated != 0 )
        {
            target += "<a href=\"";
            target += links_name;
            target += "#";
            const string target_dir_string = target_dir.string();
            std::copy(
                html_from_path(target_dir_string.begin()), 
                html_from_path(target_dir_string.end()),
                std::back_inserter(target)
                );
            target += "\">";
            target += pass
                ? (anything_generated < 2 ? pass_msg : warn_msg)
                : fail_msg;
            target += "</a>";
        }
        else  target += pass ? pass_msg : fail_msg;

        // if profiling
        if(profile && pass){
            // add link to profile
            target += " <a href=\"";
            target += (target_dir / "profile.txt").string();
            target += "\"><i>Profile</i></a>";
        }
        target += "</td>";
        return (anything_generated != 0) || !pass;
    }

    bool visit_node_tree(
        const col_node & node,
        fs::path dir_root,
        const string & lib_name,
        const string & test_name,
        string & target,
        bool profile
    ){
        bool retval = false;
        if(node.is_leaf){
            return do_cell(
                dir_root,
                lib_name,
                test_name,
                target,
                profile
            );
        }
        BOOST_FOREACH(
            const col_node::subcolumn & s,
            node.m_subcolumns
        ){
            fs::path subdir = dir_root / s.first;
            retval |= visit_node_tree(
                s.second, 
                subdir,
                lib_name,
                test_name,
                target,
                s.first == "profile"
            );
        }
        return retval;
    }

    // emit results for each test
    void do_row(
        col_node test_node,
        const fs::path & test_dir,
        const string & lib_name,
        const string & test_name,
        string & target 
    ){
        string::size_type row_start_pos = target.size();

        target += "<tr>";

        target += "<td>";
        //target += "<a href=\"" + url_prefix_dir_view + "/libs/" + lib_name + "\">";
        target += test_name;
        //target += "</a>";
        target += "</td>";

        bool no_warn_save = no_warn;

        // emit cells on this row
        bool anything_to_report = visit_node_tree(
            test_node, 
            test_dir,
            lib_name,
            test_name,
            target,
            false
        );

        target += "</tr>";

        if ( ignore_pass 
        && ! anything_to_report ) 
            target.erase( row_start_pos );

        no_warn = no_warn_save;
    }

    //  do_table_body  -----------------------------------------------------------//

    void do_table_body(
        col_node root_node, 
        const string & lib_name,
        const fs::path & test_lib_dir 
    ){
        // rows are held in a vector so they can be sorted, if desired.
        std::vector<string> results;

        BOOST_FOREACH(
            fs::directory_entry & d,
            std::make_pair(
                fs::directory_iterator(test_lib_dir), 
                fs::directory_iterator()
            )
         ){
            if(! fs::is_directory(d))
                continue;

            // if the file name contains ".test"
            if(d.path().extension() != ".test")
                continue;

            string test_name = d.path().stem().string();

            results.push_back( std::string() ); 
            do_row(
                root_node, //*test_node_itr++,
                d, // test dir
                lib_name,
                test_name,
                results[results.size()-1] 
            );
        }

        std::sort( results.begin(), results.end() );

        BOOST_FOREACH(string &s, results)
            report << s << "\n";
    }

    //  column header-----------------------------------------------------------//
    int header_depth(const col_node & root){
        int max_depth = 1;
        BOOST_FOREACH(
            const col_node::subcolumn &s,
            root.m_subcolumns
        ){
            max_depth = (std::max)(max_depth, s.second.rows);
        }
        return max_depth;
    }

    void header_cell(int rows, int cols, const std::string & name){
        // add row cells
        report << "<td align=\"center\" " ;
        if(1 < cols)
            report << "colspan=\"" << cols << "\" " ;
        if(1 < rows)
            // span rows to the end the header
            report << "rowspan=\"" << rows << "\" " ;
        report << ">" ;
        report << name;
        report << "</td>\n";
    }

    void emit_column_headers(
        const col_node & node, 
        int display_row, 
        int current_row,
        int row_count
    ){
        if(current_row < display_row){
            if(! node.m_subcolumns.empty()){
                BOOST_FOREACH(
                    const col_node::subcolumn &s,
                    node.m_subcolumns
                ){
                    emit_column_headers(
                        s.second, 
                        display_row, 
                        current_row + 1, 
                        row_count
                    );
                }
            }
            return;
        }
        /*
        if(node.is_leaf && ! node.m_subcolumns.empty()){
            header_cell(row_count - current_row, 1, std::string(""));
        }
        */
        BOOST_FOREACH(col_node::subcolumn s, node.m_subcolumns){
            if(1 == s.second.rows)
                header_cell(row_count - current_row, s.second.cols, s.first);
            else
                header_cell(1, s.second.cols, s.first);
        }
    }

    fs::path find_lib_test_dir(fs::path const& initial_path){
        // walk up from the path were we started until we find
        // bin or bin.v2

        fs::path test_lib_dir = initial_path;
        do{
            if(fs::is_directory( test_lib_dir / "bin.v2")){
                test_lib_dir /= "bin.v2";
                break;
            }
            if(fs::is_directory( test_lib_dir / "bin")){
                // v1 includes the word boost
                test_lib_dir /= "bin";
                if(fs::is_directory( test_lib_dir / "boost")){
                    test_lib_dir /= "boost";
                }
                break;
            }
        }while(! test_lib_dir.empty());

        if(test_lib_dir.empty())
            throw std::string("binary path not found");

        return test_lib_dir;
    }

    string find_lib_name(fs::path lib_test_dir){
        // search the path backwards for the magic name "libs"
        fs::path::iterator e_itr = lib_test_dir.end();
        while(lib_test_dir.begin() != e_itr){
            if(*--e_itr == "libs")
                break;
        }

        // if its found
        if(lib_test_dir.begin() != e_itr){
            // use the whole path since the "libs"
            ++e_itr;
        }
        // otherwise, just use the last two components
        else{
            e_itr = lib_test_dir.end();
            if(e_itr != lib_test_dir.begin()){
                if(--e_itr != lib_test_dir.begin()){
                    --e_itr;
                }
            }
        }

        fs::path library_name;
        while(lib_test_dir.end() != e_itr){
            library_name /= *e_itr++;
        }
        return library_name.string();
    }

    fs::path find_boost_root(fs::path initial_path){
        fs::path boost_root = initial_path;
        for(;;){
            if(fs::is_directory( boost_root / "boost")){
                break;
            }
            if(boost_root.empty())
                throw std::string("boost root not found");
            boost_root.remove_filename();
        }

        return boost_root;
    }

    //  do_table  ----------------------------------------------------------------//
    void do_table(const fs::path & lib_test_dir, const string & lib_name)
    {
        col_node root_node;

        BOOST_FOREACH(
            fs::directory_entry & d,
            std::make_pair(
                fs::directory_iterator(lib_test_dir), 
                fs::directory_iterator()
            )
         ){
            if(! fs::is_directory(d))
                continue;
            fs::path p = d.path();
            if(p.extension() != ".test")
                continue;
            build_node_tree(d, root_node);
        }
        
        // visit directory nodes and record nodetree
        report << "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n";

        // emit
        root_node.get_spans();
        int row_count = header_depth(root_node);
        report << "<tr>\n";
        report << "<td rowspan=\"" << row_count << "\">Test Name</td>\n";

        // emit column headers
        int row_index = 0;
        for(;;){
            emit_column_headers(root_node, row_index, 0, row_count);
            report << "</tr>" ;
            if(++row_index == row_count)
                break;
            report << "<tr>\n";
        }

        // now the rest of the table body
        do_table_body(root_node, lib_name, lib_test_dir);

        report << "</table>\n";
   }
}// unnamed namespace

//  main  --------------------------------------------------------------------//

#define BOOST_NO_CPP_MAIN_SUCCESS_MESSAGE
#include <boost/test/included/prg_exec_monitor.hpp>

int cpp_main( int argc, char * argv[] ) // note name!
{
    fs::path initial_path = fs::initial_path();

    while ( argc > 1 && *argv[1] == '-' )
    {
        if ( argc > 2 && std::strcmp( argv[1], "--compiler" ) == 0 )
        { specific_compiler = argv[2]; --argc; ++argv; }
        else if ( argc > 2 && std::strcmp( argv[1], "--locate-root" ) == 0 )
        { locate_root = fs::path( argv[2] ); --argc; ++argv; }
        else if ( std::strcmp( argv[1], "--ignore-pass" ) == 0 ) ignore_pass = true;
        else if ( std::strcmp( argv[1], "--no-warn" ) == 0 ) no_warn = true;
        else if ( std::strcmp( argv[1], "--v2" ) == 0 )
        {--argc; ++argv ;} // skip
        else if ( argc > 2 && std::strcmp( argv[1], "--jamfile" ) == 0)
        {--argc; ++argv;} // skip
        else { std::cerr << "Unknown option: " << argv[1] << "\n"; argc = 1; }
        --argc;
        ++argv;
    }

    if ( argc != 2 && argc != 3 )
    {
        std::cerr <<
            "Usage: library_status [options...] status-file [links-file]\n"
            "  boost-root is the path to the boost tree root directory.\n"
            "  status-file and links-file are paths to the output files.\n"
            "  options: --compiler name     Run for named compiler only\n"
            "           --ignore-pass       Do not report tests which pass all compilers\n"
            "           --no-warn           Warnings not reported if test passes\n"
            "           --locate-root path  Path to ALL_LOCATE_TARGET for bjam;\n"
            "                               default boost-root.\n"
            "Example: library_status --compiler gcc /boost-root cs.html cs-links.html\n"
            "Note: Only the leaf of the links-file path is\n"
            "used in status-file HTML links. Thus for browsing, status-file,\n"
            "links-file must be in the same directory.\n"
            ;
        return 1;
    }

    if(locate_root.empty())
        if(! fs::exists("bin") && ! fs::exists("bin.v2"))
            locate_root = find_boost_root(initial_path);

    report.open( fs::path( argv[1] ) );
    if ( !report )
    {
        std::cerr << "Could not open report output file: " << argv[2] << std::endl;
        return 1;
    }

    if ( argc == 3 )
    {
        fs::path links_path( argv[2] );
        links_name = links_path.filename().string();
        links_file.open( links_path );
        if ( !links_file )
        {
            std::cerr << "Could not open links output file: " << argv[3] << std::endl;
            return 1;
        }
    }
    else no_links = true;

    const string library_name = find_lib_name(initial_path);

    char run_date[128];
    std::time_t tod;
    std::time( &tod );
    std::strftime( run_date, sizeof(run_date),
        "%X UTC, %A %d %B %Y", std::gmtime( &tod ) );

    report 
        << "<html>\n"
        << "<head>\n"
        << "<title>Boost Library Status Automatic Test</title>\n"
        << "</head>\n"
        << "<body bgcolor=\"#ffffff\" text=\"#000000\">\n"
        << "<table border=\"0\">\n"
        << "<h1>Library Status: " + library_name + "</h1>\n"
        << "<b>Run Date:</b> "
        << run_date
        << "\n<br>"
        ;

    report << "</td>\n</table>\n<br>\n";

    if ( !no_links )
    {
        links_file
            << "<html>\n"
            << "<head>\n"
            << "<title>Boost Library Status Error Log</title>\n"
            << "</head>\n"
            << "<body bgcolor=\"#ffffff\" text=\"#000000\">\n"
            << "<table border=\"0\">\n"
            << "<h1>Library Status: " + library_name + "</h1>\n"
            << "<b>Run Date:</b> "
            << run_date
            << "\n<br></table>\n<br>\n"
            ;
    }

    // detect whether in a a directory which looks like
    // bin/<library name>/test
    // or just
    // bin
    fs::path library_test_directory = find_lib_test_dir(locate_root);
    // if libs exists, drop down a couple of levels
    if(fs::is_directory( library_test_directory / "libs")){
        library_test_directory /= "libs";
        library_test_directory /= library_name;
    }

    do_table(library_test_directory, library_name);

    report << "</body>\n"
        "</html>\n"
        ;

    if ( !no_links )
    {
        links_file
            << "</body>\n"
            "</html>\n"
            ;
    }
    return 0;
}