[Tools 2/2] winetest: Add proper command line options.

Francois Gouget fgouget at codeweavers.com
Mon Jun 12 04:41:40 CDT 2017


This makes it possible to specify the workdir or which report or
build directory to work on. The latter make it possible to manually
update the generated files for the reports.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---

The priority order is the --workdir option if specified on the command 
line, $workdir as set in the configuration file, and finally the current 
directory if it looks ok.
This means this patch should work whether one defines the work directory 
in winetest.conf or not. Also this obviously does not touch the CGI 
scripts so there is no impact on Apache.


 winetest/build-errors |  75 +++++++++++++++++++++++++++++++-
 winetest/build-index  |  80 +++++++++++++++++++++++++++++++++-
 winetest/dissect      |  96 +++++++++++++++++++++++++++++++++++++---
 winetest/gather       | 118 ++++++++++++++++++++++++++++++++++++++++++++------
 4 files changed, 347 insertions(+), 22 deletions(-)

diff --git a/winetest/build-errors b/winetest/build-errors
index 2d25ae3f..1462da67 100755
--- a/winetest/build-errors
+++ b/winetest/build-errors
@@ -60,11 +60,84 @@ sub long_date($)
 
 
 #
-# Generate a table of the errors encountered during processing
+# Command line processing
 #
 
+my $usage;
+
+sub check_opt_val($$)
+{
+    my ($option, $val) = @_;
+
+    if (defined $val)
+    {
+        error("$option can only be specified once\n");
+        $usage = 2; # but continue processing this option
+    }
+    if (!@ARGV)
+    {
+        error("missing value for $option\n");
+        $usage = 2;
+        return undef;
+    }
+    return shift @ARGV;
+}
+
+while (@ARGV)
+{
+    my $arg = shift @ARGV;
+    if ($arg eq "--workdir")
+    {
+        $workdir = check_opt_val($arg, $workdir);
+    }
+    elsif ($arg eq "--help")
+    {
+        $usage = 0;
+    }
+    else
+    {
+        error("unknown argument '$arg'\n");
+        $usage = 2;
+    }
+}
+if (!defined $usage)
+{
+    if (!defined $workdir)
+    {
+        require Cwd;
+        $workdir = Cwd::cwd();
+    }
+    if (!-f "$workdir/report.css")
+    {
+        error("'$workdir' is not a valid work directory\n");
+        $usage = 2;
+    }
+}
+if (defined $usage)
+{
+    if ($usage)
+    {
+        error("try '$name0 --help' for more information\n");
+        exit $usage;
+    }
+    print "Usage: $name0 [--workdir DIR] [--help]\n";
+    print "\n";
+    print "Updates the list of rejected reports.\n";
+    print "\n";
+    print "Where:\n";
+    print "  --workdir DIR   Specifies the directory containing the winetest website\n";
+    print "                  files.\n";
+    print "  --help          Shows this usage message.\n";
+    exit 0;
+}
+
 chdir($workdir) or die "could not chdir to the work directory: $!";
 
+
+#
+# Generate a table of the errors encountered during processing
+#
+
 my @errors;
 
 opendir DIR, "queue" or die "cannot open 'queue'";
diff --git a/winetest/build-index b/winetest/build-index
index fb949b15..2c1cbafa 100755
--- a/winetest/build-index
+++ b/winetest/build-index
@@ -110,11 +110,89 @@ my @groups = (\%w95, \%w98, \%me, \%nt3, \%nt4, \%w2k, \%xp, \%w2k3, \%vista, \%
 
 
 #
-# Grab the build list and archive the old results
+# Command line processing
 #
 
+my $usage;
+
+sub check_opt_val($$)
+{
+    my ($option, $val) = @_;
+
+    if (defined $val)
+    {
+        error("$option can only be specified once\n");
+        $usage = 2; # but continue processing this option
+    }
+    if (!@ARGV)
+    {
+        error("missing value for $option\n");
+        $usage = 2;
+        return undef;
+    }
+    return shift @ARGV;
+}
+
+while (@ARGV)
+{
+    my $arg = shift @ARGV;
+    if ($arg eq "--workdir")
+    {
+        $workdir = check_opt_val($arg, $workdir);
+    }
+    elsif ($arg eq "--help")
+    {
+        $usage = 0;
+    }
+    else
+    {
+        error("unknown argument '$arg'\n");
+        $usage = 2;
+    }
+}
+if (!defined $usage)
+{
+    if (!defined $workdir)
+    {
+        require Cwd;
+        $workdir = Cwd::cwd();
+    }
+    elsif ($workdir !~ m%^/%)
+    {
+        require Cwd;
+        $workdir = Cwd::cwd() . "/$workdir";
+    }
+    if (!-f "$workdir/report.css")
+    {
+        error("'$workdir' is not a valid work directory\n");
+        $usage = 2;
+    }
+}
+if (defined $usage)
+{
+    if ($usage)
+    {
+        error("try '$name0 --help' for more information\n");
+        exit $usage;
+    }
+    print "Usage: $name0 [--workdir DIR] [--help]\n";
+    print "\n";
+    print "Processes the build summaries to generate the global index.\n";
+    print "\n";
+    print "Where:\n";
+    print "  --workdir DIR   Specifies the directory containing the winetest website\n";
+    print "                  files.\n";
+    print "  --help          Shows this usage message.\n";
+    exit 0;
+}
+
 chdir($workdir) or die "could not chdir to the work directory: $!";
 
+
+#
+# Grab the build list and archive the old results
+#
+
 my @builds;
 my @too_old;
 
diff --git a/winetest/dissect b/winetest/dissect
index ae8a0e5c..4901e972 100755
--- a/winetest/dissect
+++ b/winetest/dissect
@@ -105,16 +105,98 @@ sub short_date($)
 # Command line processing
 #
 
+my ($update, $report, $usage);
+
+sub check_opt_val($$)
+{
+    my ($option, $val) = @_;
+
+    if (defined $val)
+    {
+        error("$option can only be specified once\n");
+        $usage = 2; # but continue processing this option
+    }
+    if (!@ARGV)
+    {
+        error("missing value for $option\n");
+        $usage = 2;
+        return undef;
+    }
+    return shift @ARGV;
+}
+
+while (@ARGV)
+{
+    my $arg = shift @ARGV;
+    if ($arg eq "--workdir")
+    {
+        $workdir = check_opt_val($arg, $workdir);
+    }
+    elsif ($arg eq "--update")
+    {
+        $report = check_opt_val($arg, $report);
+        $update = 1;
+    }
+    elsif ($arg eq "--help")
+    {
+        $usage = 0;
+    }
+    else
+    {
+        error("unknown argument '$arg'\n");
+        $usage = 2;
+    }
+}
+if (!defined $usage)
+{
+    if (!defined $workdir)
+    {
+        require Cwd;
+        $workdir = Cwd::cwd();
+    }
+    elsif ($workdir !~ m%^/%)
+    {
+        require Cwd;
+        $workdir = Cwd::cwd() . "/$workdir";
+    }
+    if (!-f "$workdir/report.css")
+    {
+        error("'$workdir' is not a valid work directory\n");
+        $usage = 2;
+    }
+    if (defined $report and !-f $report)
+    {
+        error("the '$report' report is not valid\n");
+        $usage = 2;
+    }
+}
+if (defined $usage)
+{
+    if ($usage)
+    {
+        error("try '$name0 --help' for more information\n");
+        exit $usage;
+    }
+    print "Usage: $name0 [--workdir DIR] [--update REPORT] [--help]\n";
+    print "\n";
+    print "Processes a test report to generate the corresponding HTML files.\n";
+    print "\n";
+    print "Where:\n";
+    print "  --workdir DIR   Specifies the directory containing the winetest website\n";
+    print "                  files.\n";
+    print "  --update REPORT Updates the HTML files of the specified test report. Note that\n";
+    print "                  it must have already been moved into place.\n";
+    print "  --help          Shows this usage message.\n";
+    exit 0;
+}
+
 chdir($workdir) or die "could not chdir to the work directory: $!";
 
-my ($update, $report);
-if (defined $ARGV[0] and $ARGV[0] eq "--update") {
-    $report = $ARGV[1];
-    $update = 1;
-} else {
-    ($report, undef) = glob "queue/rep*/report";
+if (!defined $report)
+{
+    ($report, undef) = glob "$workdir/queue/rep*/report";
+    exit 2 if (!defined $report or !-f $report);
 }
-exit 2 unless (defined $report && -f $report);
 
 my $tmpdir = $report;
 $tmpdir =~ s|^(.+)/report$|$1|;
diff --git a/winetest/gather b/winetest/gather
index fe1dfb42..907b2050 100755
--- a/winetest/gather
+++ b/winetest/gather
@@ -172,16 +172,108 @@ my %idmap = (95=>\%w95, 98=>\%w98, me=>\%me, nt3=>\%nt3, nt4=>\%nt4, 2000=>\%w2k
 
 
 #
-# Pick a build to work on
+# Command line processing
 #
 
+my ($update, $builddir, $usage);
+
+sub check_opt_val($$)
+{
+    my ($option, $val) = @_;
+
+    if (defined $val)
+    {
+        error("$option can only be specified once\n");
+        $usage = 2; # but continue processing this option
+    }
+    if (!@ARGV)
+    {
+        error("missing value for $option\n");
+        $usage = 2;
+        return undef;
+    }
+    return shift @ARGV;
+}
+
+while (@ARGV)
+{
+    my $arg = shift @ARGV;
+    if ($arg eq "--workdir")
+    {
+        $workdir = check_opt_val($arg, $workdir);
+    }
+    elsif ($arg eq "--update")
+    {
+        $builddir = check_opt_val($arg, $builddir);
+        $update = 1;
+    }
+    elsif ($arg eq "--help")
+    {
+        $usage = 0;
+    }
+    else
+    {
+        error("unknown argument '$arg'\n");
+        $usage = 1;
+    }
+}
+if (!defined $usage)
+{
+
+    if (!defined $workdir)
+    {
+        require Cwd;
+        $workdir = Cwd::cwd();
+    }
+    elsif ($workdir !~ m%^/%)
+    {
+        require Cwd;
+        $workdir = Cwd::cwd() . "/$workdir";
+    }
+    if (!-f "$workdir/report.css")
+    {
+        error("'$workdir' is not a valid work directory\n");
+        $usage = 2;
+    }
+    if (defined $builddir and !-f "$builddir/summary.txt")
+    {
+        error("the '$builddir' build directory is not valid\n");
+        $usage = 1;
+    }
+}
+if (defined $usage)
+{
+    if ($usage)
+    {
+        error("try '$name0 --help' for more information\n");
+        exit $usage;
+    }
+    print "Usage: $name0 [--workdir DIR] [--update BUILDDIR] [--help]\n";
+    print "\n";
+    print "Processes a build's report summaries to create the build's index files.\n";
+    print "\n";
+    print "Where:\n";
+    print "  --workdir DIR     Specifies the directory containing the winetest website\n";
+    print "                    files.\n";
+    print "  --update BUILDDIR Updates the HTML files of the specified build directory.\n";
+    print "  --help          Shows this usage message.\n";
+    exit 0;
+}
 
 chdir($workdir) or die "could not chdir to the work directory: $!";
 
-my ($outdated,undef) = glob "data/*/outdated";
-exit 2 unless defined $outdated;
-(my $build = $outdated) =~ s|^data/(.*)/outdated$|$1|;
-(my $release = $build) =~ s/^(\d+).*$/$1/;
+if (!defined $builddir)
+{
+    ($builddir, undef) = glob "data/*/outdated";
+    exit 2 if (!defined $builddir);
+    $builddir =~ s~/outdated$~~;
+}
+if ($builddir !~ s~^(?:\Q$workdir\E/+)?data/+([0-9a-f]{40})/?$~data/$1~)
+{
+    error("the '$builddir' build directory is not valid\n");
+    exit 1;
+}
+my $build = $1;
 my ($date, $_subject) = get_build_info($build);
 
 
@@ -190,8 +282,8 @@ my ($date, $_subject) = get_build_info($build);
 #
 
 my %alltests;                   # union of test names
-foreach my $file (glob "data/$build/*/summary.txt") {
-    (my $dir = $file) =~ s|^data/\Q$build\E/(.*?)/summary.txt$|$1|;
+foreach my $file (glob "$builddir/*/summary.txt") {
+    (my $dir = $file) =~ s|^$builddir/(.*?)/summary.txt$|$1|;
     (my $id, my @tag) = split /_/, $dir;
     my $group = $idmap{$id};
     if (!defined $group) {
@@ -560,7 +652,7 @@ sub singletest($$$) {
     {
         my $report = $group->{reports} ? $group->{reports}->[0] : $group;
         $prefix = "$testname | $report->{tag}";
-        if (-r "data/$build/$report->{dir}/$testname.html")
+        if (-r "$builddir/$report->{dir}/$testname.html")
         {
             $href = "$report->{dir}/$testname.html";
         }
@@ -653,7 +745,7 @@ sub write_build_index_and_summary($)
         $filename = "index.html";
     }
 
-    my $idx_file = "data/$build/$filename";
+    my $idx_file = "$builddir/$filename";
     if (!open OUT, ">", "$idx_file.new") {
         error("could not open '$idx_file.new' for writing: $!\n");
         return;
@@ -762,7 +854,7 @@ sub write_totals($)
 {
     my ($reports)=@_;
 
-    my $filename = "data/$build/total.txt";
+    my $filename = "$builddir/total.txt";
     if (!open TOTAL, ">", "$filename.new")
     {
         error("could not open '$filename.new' for writing: $!\n");
@@ -796,7 +888,7 @@ sub write_totals($)
 # Actually generate the build's files
 #
 
-my $filename = "data/$build/summary.txt";
+my $filename = "$builddir/summary.txt";
 if (!open SUMMARY, ">", "$filename.new")
 {
   error("could not open '$filename.new' for writing: $!\n");
@@ -821,8 +913,8 @@ if (!rename "$filename.new", "$filename")
 write_totals(\@groups);
 
 DONE:
-if (!unlink $outdated and !$!{ENOENT})
+if (!unlink "$builddir/outdated" and !$!{ENOENT})
 {
-    error("unable to unlink '$outdated': $!\n");
+    error("unable to unlink '$builddir/outdated': $!\n");
     exit 3;
 }
-- 
2.11.0



More information about the wine-patches mailing list