1 #!/usr/bin/perl -w 2 3 # Copyright (C) 2011 Apple Inc. All rights reserved. 4 # 5 # Redistribution and use in source and binary forms, with or without 6 # modification, are permitted provided that the following conditions 7 # are met: 8 # 1. Redistributions of source code must retain the above copyright 9 # notice, this list of conditions and the following disclaimer. 10 # 2. Redistributions in binary form must reproduce the above copyright 11 # notice, this list of conditions and the following disclaimer in the 12 # documentation and/or other materials provided with the distribution. 13 # 14 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 15 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 18 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 24 # THE POSSIBILITY OF SUCH DAMAGE. 25 26 use strict; 27 use FindBin; 28 use File::Temp qw(tempfile); 29 use lib $FindBin::Bin; 30 use webkitdirs; 31 32 my $inputPath = ""; 33 if ($ARGV[0]) { 34 $inputPath = $ARGV[0] 35 } else { 36 # Create a temporary file for STDIN. 37 # FIXME: We can probably avoid putting this on the disk by directly piping 38 # to prettify.rb via IPC::Open2. 39 my $inputTempFileHandle; 40 ($inputTempFileHandle, $inputPath) = tempfile( 41 "inputtemp-XXXXXXXX", 42 DIR => File::Spec->tmpdir(), 43 SUFFIX => ".diff", 44 UNLINK => 0, 45 ); 46 47 while (<STDIN>) { 48 print $inputTempFileHandle $_; 49 } 50 51 close($inputTempFileHandle); 52 } 53 54 # Create a temporary file for prettified patch. 55 my ($prettydiffFileHandle, $prettydiffPath) = tempfile( 56 "prettydiff-XXXXXXXX", 57 DIR => File::Spec->tmpdir(), 58 SUFFIX => ".html", 59 UNLINK => 0, 60 ); 61 close($prettydiffFileHandle); 62 63 my $prettyPatchDir = sourceDir() . "/Websites/bugs.webkit.org/PrettyPatch/"; 64 my $prettyPatchTool = sourceDir() . "/Websites/bugs.webkit.org/PrettyPatch/prettify.rb"; 65 66 my $pathToPrettify = "ruby -I " . sourceDir() . "/Websites/bugs.webkit.org/PrettyPatch/ " . sourceDir() . "/Websites/bugs.webkit.org/PrettyPatch/prettify.rb"; 67 system "$pathToPrettify $inputPath > $prettydiffPath"; 68 69 if (isAppleMacWebKit()) { 70 system "open", $prettydiffPath; 71 } elsif (isCygwin()) { 72 system "cygstart",$prettydiffPath; 73 } elsif (isWindows()) { 74 system "start", $prettydiffPath; 75 } else { 76 print "Created prettified diff at " . $prettydiffPath . "."; 77 } 78