#!/usr/bin/perl -w
-# Copyright (C) 2007 Apple Inc. All rights reserved.
+# Copyright (C) 2007 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
GetOptions('shell=s' => \$jsShellPath,
'help' => \$showHelp);
-if (scalar @ARGV < 2 || !$jsShellPath || $showHelp) {
+if ((scalar @ARGV != 0 && scalar @ARGV != 2) || !$jsShellPath || $showHelp) {
print STDERR $usage;
exit 1;
}
my ($filename) = @_;
open FILE, "<", $filename or die;
my $foundStart = 0;
+ my $foundOutput = 0;
my $foundEnd = 0;
my $result = "";
while (<FILE>) {
if (!$foundStart) {
- if (/^[[][{]$/) {
- $foundStart = 1;
- $result .= $_;
- }
- } else {
- if (/^[}][]]$/) {
- $foundEnd = 1;
- chomp;
- $result .= $_;
- last;
- } else {
- $result .= $_;
- }
- }
+ if (/^\[\{$/) {
+ $foundStart = 1;
+ $result .= $_;
+ } elsif (/^var \w+ = \[$/) {
+ $foundOutput = 1;
+ } elsif ($foundOutput && /^\{$/) {
+ $foundOutput = 0;
+ $foundStart = 1;
+ $result = "[{\n";
+ }
+ } else {
+ if (/\];?$/) {
+ $foundEnd = 1;
+ chomp;
+ s/;$//;
+ $result .= $_;
+ last;
+ } else {
+ $result .= $_;
+ }
+ }
}
close FILE;
- die "Cound not find data in file - needs to be bracketed by [{ and }]." unless ($foundStart && $foundEnd);
+ die "Cound not find data in ${filename} - needs to start with [{" unless $foundStart;
+ die "Cound not find data in ${filename} - needs to end with }]" unless $foundEnd;
return $result;
}
close FILE;
}
-my $output = "var output1 = " . readResultsFile($ARGV[0]) . ";\n";
-$output .= "var output2 = " . readResultsFile($ARGV[1]) . ";\n";
+sub readFile($)
+{
+ my ($path) = @_;
+ open FILE, "<", $path or die;
+ my $result = <FILE>;
+ close FILE;
+ return $result;
+}
+
+sub newestFile($$)
+{
+ my ($dir, $pattern) = @_;
+
+ my $newestAge;
+ my $newestFile = "";
+ opendir DIR, $dir or die;
+ for my $file (readdir DIR) {
+ if ($file =~ $pattern) {
+ my $age = -M "$dir/$file";
+ if (!defined $newestAge || $age < $newestAge) {
+ $newestFile = $file;
+ $newestAge = $age;
+ }
+ }
+ }
+ closedir DIR;
+
+ return "$dir/$newestFile";
+}
+
+my $file1;
+my $file2;
+
+if (scalar @ARGV == 2) {
+ $file1 = $ARGV[0];
+ $file2 = $ARGV[1];
+} else {
+ $file1 = readFile("tmp/baseline-filename.txt");
+ $file2 = newestFile("tmp", qr/sunspider-results-.+\.js$/);
+}
+
+my $output = "var output1 = " . readResultsFile($file1) . ";\n";
+$output .= "var output2 = " . readResultsFile($file2) . ";\n";
dumpToFile($output, "tmp/sunspider-comparison-data.js");
-system("$jsShellPath", "-f", "tmp/sunspider-test-prefix.js", "-f", "tmp/sunspider-comparison-data.js", "-f", "resources/sunspider-compare-results.js");
+system($jsShellPath, "-f", "tmp/sunspider-test-prefix.js", "-f", "tmp/sunspider-comparison-data.js", "-f", "resources/sunspider-compare-results.js");