3 # Copyright (C) 2011 Apple Inc. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
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.
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.
28 use File::Temp qw(tempfile);
29 use lib $FindBin::Bin;
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(
42 DIR => File::Spec->tmpdir(),
48 print $inputTempFileHandle $_;
51 close($inputTempFileHandle);
54 # Create a temporary file for prettified patch.
55 my ($prettydiffFileHandle, $prettydiffPath) = tempfile(
56 "prettydiff-XXXXXXXX",
57 DIR => File::Spec->tmpdir(),
61 close($prettydiffFileHandle);
63 my $prettyPatchDir = sourceDir() . "/Websites/bugs.webkit.org/PrettyPatch/";
64 my $prettyPatchTool = sourceDir() . "/Websites/bugs.webkit.org/PrettyPatch/prettify.rb";
66 my $pathToPrettify = "ruby -I " . sourceDir() . "/Websites/bugs.webkit.org/PrettyPatch/ " . sourceDir() . "/Websites/bugs.webkit.org/PrettyPatch/prettify.rb";
67 system "$pathToPrettify " . quotemeta($inputPath) . " > $prettydiffPath";
69 if (isAppleMacWebKit()) {
70 system "open", $prettydiffPath;
71 } elsif (isCygwin()) {
72 system "cygstart",$prettydiffPath;
73 } elsif (isWindows()) {
74 system "start", $prettydiffPath;
75 } elsif (isLinux() && `which xdg-open`) {
76 system "xdg-open", $prettydiffPath;
78 print "Created prettified diff at " . $prettydiffPath . ".";