3 # Copyright (C) 2005, 2006, 2007 Apple Computer, Inc. All rights reserved.
4 # Copyright (C) 2011 Carl Lobo. All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
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.
30 # Updates a development environment to the new WebKitAuxiliaryLibrary
39 use HTTP::Date qw(str2time);
41 use lib $FindBin::Bin;
47 update-webkit-dependancy <URL with the dependancy zip file> <*prefix dir inside zip without filename>
49 * If filename is requirements.zip and the contents of the zipfile are "requirements/x" then prefix = "."
50 * If filename is xyz.zip and the contents of the zipfile are xyz/abc/x" then prefix = "abc"
51 * x is lib or include or bin.
55 sub lastModifiedToUnixTime($);
56 sub getLibraryName($);
58 # Time in seconds that the new zip file must be newer than the old for us to
59 # consider them to be different. If the difference in modification time is less
60 # than this threshold, we assume that the files are the same. We need this
61 # because the zip file is served from a set of mirrors with slightly different
62 # Last-Modified times.
63 my $newnessThreshold = 30;
66 my $prefixInZip = shift;
67 my $sourceDir = sourceDir();
68 my $file = getLibraryName($libsURL);
69 my $zipFile = "$file.zip";
70 my $webkitLibrariesDir = toUnixPath($ENV{'WEBKITLIBRARIESDIR'}) || "$sourceDir/WebKitLibraries/win";
71 my $tmpRelativeDir = File::Temp::tempdir("webkitlibsXXXXXXX", TMPDIR => 1, CLEANUP => 1);
72 my $tmpAbsDir = File::Spec->rel2abs($tmpRelativeDir);
74 print "Checking Last-Modified date of $zipFile...\n";
76 my $result = system "curl -s -I -k --sslv3 $libsURL | grep Last-Modified > \"$tmpAbsDir/$file.headers\"";
78 if (WEXITSTATUS($result)) {
80 #Note: Neither GitHub nor DropBox emit the Last-Modified HTTP header, so fall back to a file
81 #containing the necessary information if we do not receive the information in our initial query.
82 my $headerURL = $libsURL;
83 $headerURL =~ s/\.zip$/\.headers/;
85 $result = system "curl -k --sslv3 -o \"$tmpAbsDir/$file.headers\" $headerURL";
87 if (WEXITSTATUS($result)) {
88 print STDERR "Couldn't check Last-Modified date of new $zipFile.\n";
89 print STDERR "Please ensure that $libsURL is reachable.\n";
91 if (! -f "$webkitLibrariesDir/$file.headers") {
92 print STDERR "Unable to check Last-Modified date and no version of $file to fall back to.\n";
96 print STDERR "Falling back to existing version of $file.\n";
101 if (open NEW, "$tmpAbsDir/$file.headers") {
102 my $new = lastModifiedToUnixTime(<NEW>);
105 if (defined $new && open OLD, "$webkitLibrariesDir/$file.headers") {
106 my $old = lastModifiedToUnixTime(<OLD>);
108 if (defined $old && abs($new - $old) < $newnessThreshold) {
109 print "Current $file is up to date\n";
115 print "Downloading $zipFile...\n\n";
116 $result = system "curl -k --sslv3 -o \"$tmpAbsDir/$zipFile\" $libsURL";
117 die "Couldn't download $zipFile!" if $result;
119 $result = system "unzip", "-q", "-d", $tmpAbsDir, "$tmpAbsDir/$zipFile";
120 die "Couldn't unzip $zipFile." if $result;
122 print "\nInstalling $file...\n";
126 my $relativeName = File::Spec->abs2rel($File::Find::name, "$tmpAbsDir/$file/$prefixInZip");
127 my $destination = "$webkitLibrariesDir/$relativeName";
134 system "cp", $_, $destination;
137 File::Find::find(\&wanted, "$tmpAbsDir/$file");
139 $result = system "mv", "$tmpAbsDir/$file.headers", $webkitLibrariesDir;
140 print STDERR "Couldn't move $file.headers to $webkitLibrariesDir" . ".\n" if $result;
142 print "The $file has been sucessfully installed in\n $webkitLibrariesDir\n";
149 chomp($path = `cygpath -u '$path'`);
153 sub lastModifiedToUnixTime($)
157 $str =~ /^Last-Modified: (.*)$/ or return;
161 sub getLibraryName($)
164 $url =~ m#/([^/]+)\.zip$#;