1#!/usr/bin/perl -w 2 3# Copyright (C) 2007 Apple Inc. All rights reserved. 4# Copyright (C) 2007 Eric Seidel <eric@webkit.org> 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 16# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 19# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 23# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 27use strict; 28use File::Spec; 29use FindBin; 30use Getopt::Long qw(:config pass_through); 31use lib $FindBin::Bin; 32use webkitdirs; 33use POSIX; 34 35# determine configuration, but default to "Release" instead of last-used configuration to match run-sunspider 36setConfiguration("Release"); 37setConfiguration(); 38my $configuration = configuration(); 39 40my $root; 41my $showHelp = 0; 42my $ubench = 0; 43my $v8 = 0; 44 45my $programName = basename($0); 46my $usage = <<EOF; 47Usage: $programName [options] FILE FILE 48 --help Show this help message 49 --root Path to root tools build 50 --ubench Compare microbenchmark results 51 --v8 Compare the V8 benchmark results 52EOF 53 54GetOptions('root=s' => sub { my ($argName, $value); setConfigurationProductDir(Cwd::abs_path($value)); }, 55 'ubench' => \$ubench, 56 'v8' => \$v8, 57 'help' => \$showHelp); 58 59if ($showHelp) { 60 print STDERR $usage; 61 exit 1; 62} 63 64@ARGV = map { File::Spec->rel2abs($_) } @ARGV; 65 66sub buildJSC 67{ 68 if (!defined($root)){ 69 chdirWebKit(); 70 my $buildResult = system "WebKitTools/Scripts/build-jsc", "--" . $configuration; 71 if ($buildResult) { 72 print STDERR "Compiling jsc failed!\n"; 73 exit WEXITSTATUS($buildResult); 74 } 75 } 76} 77 78sub setupEnvironmentForExecution($) 79{ 80 my ($productDir) = @_; 81 print "Starting sunspider-compare-results with DYLD_FRAMEWORK_PATH set to point to built JavaScriptCore in $productDir.\n"; 82 $ENV{DYLD_FRAMEWORK_PATH} = $productDir; 83 # FIXME: Other platforms may wish to augment this method to use LD_LIBRARY_PATH, etc. 84} 85 86sub pathToBuiltJSC($) 87{ 88 my ($productDir) = @_; 89 my $jscName = "jsc"; 90 $jscName .= "_debug" if (isCygwin() && ($configuration eq "Debug")); 91 return "$productDir/$jscName"; 92} 93 94sub pathToSystemJSC() 95{ 96 my $path = "/System/Library/Frameworks/JavaScriptCore.framework/Resources/jsc"; 97 if (-f $path) { 98 return $path; 99 } 100 return undef; 101} 102 103sub pathToJSC() 104{ 105 my $path = pathToSystemJSC(); 106 return $path if defined $path; 107 108 buildJSC(); 109 110 my $productDir = productDir(); 111 # FIXME: This hack should be pushed down into productDir() 112 $productDir .= "/JavaScriptCore" if (isQt() or isGtk()); 113 114 setupEnvironmentForExecution($productDir); 115 return pathToBuiltJSC($productDir); 116} 117 118my $jscPath = pathToJSC(); 119chdirWebKit(); 120chdir("SunSpider"); 121 122my @args = ("--shell", $jscPath); 123# This code could be removed if we chose to pass extra args to sunspider instead of Xcode 124push @args, "--ubench" if $ubench; 125push @args, "--v8" if $v8; 126 127exec "./sunspider-compare-results", @args, @ARGV; 128