[CherryPick] Input Method upversion
[framework/web/webkit-efl.git] / Tools / Scripts / update-webkit-support-libs
1 #!/usr/bin/perl -w
2
3 # Copyright (C) 2005, 2006, 2007 Apple Computer, Inc.  All rights reserved.
4 # Copyright (C) Research In Motion Limited 2010. All rights reserved.
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 #
10 # 1.  Redistributions of source code must retain the above copyright
11 #     notice, this list of conditions and the following disclaimer. 
12 # 2.  Redistributions in binary form must reproduce the above copyright
13 #     notice, this list of conditions and the following disclaimer in the
14 #     documentation and/or other materials provided with the distribution. 
15 # 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
16 #     its contributors may be used to endorse or promote products derived
17 #     from this software without specific prior written permission. 
18 #
19 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 # Updates a development environment to the new WebKitSupportLibrary
31
32 use strict;
33 use warnings;
34
35 use File::Find;
36 use File::Temp ();
37 use File::Spec;
38 use FindBin;
39 use lib $FindBin::Bin;
40 use webkitdirs;
41
42 use constant NOTAVERSION => "-1";
43
44 my $sourceDir = sourceDir();
45 my $file = "WebKitSupportLibrary";
46 my $zipFile = "$file.zip"; 
47 my $zipDirectory = toUnixPath($ENV{'WEBKITSUPPORTLIBRARIESZIPDIR'}) || $sourceDir;
48 my $pathToZip = File::Spec->catfile($zipDirectory, $zipFile);
49 my $webkitLibrariesDir = toUnixPath($ENV{'WEBKITLIBRARIESDIR'}) || "$sourceDir/WebKitLibraries/win";
50 my $versionFile = $file . "Version";
51 my $pathToVersionFile = File::Spec->catfile($webkitLibrariesDir, $versionFile);
52 my $tmpRelativeDir = File::Temp::tempdir("webkitlibsXXXXXXX", TMPDIR => 1, CLEANUP => 1);
53 my $tmpAbsDir = File::Spec->rel2abs($tmpRelativeDir);
54 my $versionFileURL = "https://developer.apple.com/opensource/internet/$versionFile";
55
56 my $extractedVersion = extractedVersion();
57
58 # Check whether the extracted library is up-to-date. If it is, we don't have anything to do.
59 my $expectedVersion = downloadExpectedVersionNumber();
60 if ($extractedVersion ne NOTAVERSION && $extractedVersion eq $expectedVersion) {
61     print "$file is up-to-date.\n";
62     exit;
63 }
64
65 # Check whether the downloaded library is up-to-date. If it isn't, the user needs to download it.
66 my $zipFileVersion = zipFileVersion();
67 dieAndInstructToDownload("$zipFile could not be found in $zipDirectory.") if $zipFileVersion eq NOTAVERSION;
68 dieAndInstructToDownload("$zipFile is out-of-date.") if $expectedVersion ne NOTAVERSION && $zipFileVersion ne $expectedVersion;
69 if ($zipFileVersion eq $extractedVersion) {
70     print "Falling back to existing version of $file.\n";
71     exit;
72 }
73
74 my $result = system "unzip", "-q", "-d", $tmpAbsDir, $pathToZip;
75 die "Couldn't unzip $zipFile." if $result;
76
77 print "\nInstalling $file...\n";
78
79 sub wanted
80 {
81     my $relativeName = File::Spec->abs2rel($File::Find::name, "$tmpAbsDir/$file/win");
82     my $destination = "$webkitLibrariesDir/$relativeName";
83
84     if (-d $_) {
85         mkdir $destination;
86         return;
87     }
88
89     system "cp", $_, $destination;
90 }
91
92 File::Find::find(\&wanted, "$tmpAbsDir/$file");
93
94 print "The $file has been sucessfully installed in\n $webkitLibrariesDir\n";
95 exit;
96
97 sub toUnixPath
98 {
99     my $path = shift;
100     return unless $path;
101     chomp($path = `cygpath -u '$path'`);
102     return $path;
103 }
104
105 sub extractedVersion
106 {
107     if (open VERSION, "<", $pathToVersionFile) {
108         chomp(my $extractedVersion = <VERSION>);
109         close VERSION;
110         return $extractedVersion;
111     }
112     return NOTAVERSION;
113 }
114
115 sub downloadExpectedVersionNumber
116 {
117     chomp(my $expectedVersion = `curl -s --sslv3 -k $versionFileURL`);
118     return WEXITSTATUS($?) ? NOTAVERSION : $expectedVersion;
119 }
120
121 sub zipFileVersion
122 {
123     return NOTAVERSION unless -f $pathToZip;
124     chomp(my $zipFileVersion = `unzip -p "$pathToZip" $file/win/$versionFile`);
125     return $zipFileVersion;
126 }
127
128 sub dieAndInstructToDownload
129 {
130     my $message = shift;
131
132     die <<EOF;
133
134 ===============================================================================
135 $message
136 Please download $zipFile from:
137
138     https://developer.apple.com/opensource/internet/webkit_sptlib_agree.html
139
140 and place it in:
141
142     $sourceDir
143
144 Then run build-webkit again.
145 ===============================================================================
146
147 EOF
148
149 }