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 32use strict; 33use warnings; 34 35use File::Find; 36use File::Temp (); 37use File::Spec; 38use FindBin; 39use lib $FindBin::Bin; 40use webkitdirs; 41 42use constant NOTAVERSION => "-1"; 43 44my $sourceDir = sourceDir(); 45my $file = "WebKitSupportLibrary"; 46my $zipFile = "$file.zip"; 47my $zipDirectory = toUnixPath($ENV{'WEBKITSUPPORTLIBRARIESZIPDIR'}) || $sourceDir; 48my $pathToZip = File::Spec->catfile($zipDirectory, $zipFile); 49my $webkitLibrariesDir = toUnixPath($ENV{'WEBKITLIBRARIESDIR'}) || "$sourceDir/WebKitLibraries/win"; 50my $versionFile = $file . "Version"; 51my $pathToVersionFile = File::Spec->catfile($webkitLibrariesDir, $versionFile); 52my $tmpRelativeDir = File::Temp::tempdir("webkitlibsXXXXXXX", TMPDIR => 1, CLEANUP => 1); 53my $tmpAbsDir = File::Spec->rel2abs($tmpRelativeDir); 54my $versionFileURL = "http://developer.apple.com/opensource/internet/$versionFile"; 55 56my $extractedVersion = extractedVersion(); 57 58# Check whether the extracted library is up-to-date. If it is, we don't have anything to do. 59my $expectedVersion = downloadExpectedVersionNumber(); 60if ($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. 66my $zipFileVersion = zipFileVersion(); 67dieAndInstructToDownload("$zipFile could not be found in $zipDirectory.") if $zipFileVersion eq NOTAVERSION; 68dieAndInstructToDownload("$zipFile is out-of-date.") if $expectedVersion ne NOTAVERSION && $zipFileVersion ne $expectedVersion; 69if ($zipFileVersion eq $extractedVersion) { 70 print "Falling back to existing version of $file.\n"; 71 exit; 72} 73 74my $result = system "unzip", "-q", "-d", $tmpAbsDir, $pathToZip; 75die "Couldn't unzip $zipFile." if $result; 76 77print "\nInstalling $file...\n"; 78 79sub 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 92File::Find::find(\&wanted, "$tmpAbsDir/$file"); 93 94print "The $file has been sucessfully installed in\n $webkitLibrariesDir\n"; 95exit; 96 97sub toUnixPath 98{ 99 my $path = shift; 100 return unless $path; 101 chomp($path = `cygpath -u '$path'`); 102 return $path; 103} 104 105sub extractedVersion 106{ 107 if (open VERSION, "<", $pathToVersionFile) { 108 chomp(my $extractedVersion = <VERSION>); 109 close VERSION; 110 return $extractedVersion; 111 } 112 return NOTAVERSION; 113} 114 115sub downloadExpectedVersionNumber 116{ 117 chomp(my $expectedVersion = `curl -s $versionFileURL`); 118 return WEXITSTATUS($?) ? NOTAVERSION : $expectedVersion; 119} 120 121sub zipFileVersion 122{ 123 return NOTAVERSION unless -f $pathToZip; 124 chomp(my $zipFileVersion = `unzip -p "$pathToZip" $file/win/$versionFile`); 125 return $zipFileVersion; 126} 127 128sub dieAndInstructToDownload 129{ 130 my $message = shift; 131 132 die <<EOF; 133 134=============================================================================== 135$message 136Please download $zipFile from: 137 138 http://developer.apple.com/opensource/internet/webkit_sptlib_agree.html 139 140and place it in: 141 142 $sourceDir 143 144Then run build-webkit again. 145=============================================================================== 146 147EOF 148 149} 150