update-webkit-dependency 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #!/usr/bin/perl -w
  2. # Copyright (C) 2005, 2006, 2007 Apple Computer, Inc. All rights reserved.
  3. # Copyright (C) 2011 Carl Lobo. 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. #
  9. # 1. Redistributions of source code must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. # notice, this list of conditions and the following disclaimer in the
  13. # documentation and/or other materials provided with the distribution.
  14. # 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  15. # its contributors may be used to endorse or promote products derived
  16. # from this software without specific prior written permission.
  17. #
  18. # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  19. # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  22. # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. # Updates a development environment to the new WebKitAuxiliaryLibrary
  29. use strict;
  30. use warnings;
  31. use File::Find;
  32. use File::Spec;
  33. use File::Temp ();
  34. use FindBin;
  35. use HTTP::Date qw(str2time);
  36. use POSIX;
  37. use lib $FindBin::Bin;
  38. use webkitdirs;
  39. if ($#ARGV != 1) {
  40. die <<EOF;
  41. Usage:
  42. update-webkit-dependancy <URL with the dependancy zip file> <*prefix dir inside zip without filename>
  43. * If filename is requirements.zip and the contents of the zipfile are "requirements/x" then prefix = "."
  44. * If filename is xyz.zip and the contents of the zipfile are xyz/abc/x" then prefix = "abc"
  45. * x is lib or include or bin.
  46. EOF
  47. }
  48. sub lastModifiedToUnixTime($);
  49. sub getLibraryName($);
  50. # Time in seconds that the new zip file must be newer than the old for us to
  51. # consider them to be different. If the difference in modification time is less
  52. # than this threshold, we assume that the files are the same. We need this
  53. # because the zip file is served from a set of mirrors with slightly different
  54. # Last-Modified times.
  55. my $newnessThreshold = 30;
  56. my $libsURL = shift;
  57. my $prefixInZip = shift;
  58. my $sourceDir = sourceDir();
  59. my $file = getLibraryName($libsURL);
  60. my $zipFile = "$file.zip";
  61. my $webkitLibrariesDir = toUnixPath($ENV{'WEBKIT_LIBRARIES'}) || "$sourceDir/WebKitLibraries/win";
  62. my $tmpRelativeDir = File::Temp::tempdir("webkitlibsXXXXXXX", TMPDIR => 1, CLEANUP => 1);
  63. my $tmpAbsDir = File::Spec->rel2abs($tmpRelativeDir);
  64. print "Checking Last-Modified date of $zipFile...\n";
  65. my $result = system "curl -s -I -k --sslv3 $libsURL | grep Last-Modified > \"$tmpAbsDir/$file.headers\"";
  66. if (WEXITSTATUS($result)) {
  67. #Note: Neither GitHub nor DropBox emit the Last-Modified HTTP header, so fall back to a file
  68. #containing the necessary information if we do not receive the information in our initial query.
  69. my $headerURL = $libsURL;
  70. $headerURL =~ s/\.zip$/\.headers/;
  71. $result = system "curl -k --sslv3 -o \"$tmpAbsDir/$file.headers\" $headerURL";
  72. if (WEXITSTATUS($result)) {
  73. print STDERR "Couldn't check Last-Modified date of new $zipFile.\n";
  74. print STDERR "Please ensure that $libsURL is reachable.\n";
  75. if (! -f "$webkitLibrariesDir/$file.headers") {
  76. print STDERR "Unable to check Last-Modified date and no version of $file to fall back to.\n";
  77. exit 1;
  78. }
  79. print STDERR "Falling back to existing version of $file.\n";
  80. exit 0;
  81. }
  82. }
  83. if (open NEW, "$tmpAbsDir/$file.headers") {
  84. my $new = lastModifiedToUnixTime(<NEW>);
  85. close NEW;
  86. if (defined $new && open OLD, "$webkitLibrariesDir/$file.headers") {
  87. my $old = lastModifiedToUnixTime(<OLD>);
  88. close OLD;
  89. if (defined $old && abs($new - $old) < $newnessThreshold) {
  90. print "Current $file is up to date\n";
  91. exit 0;
  92. }
  93. }
  94. }
  95. print "Downloading $zipFile...\n\n";
  96. $result = system "curl -k --sslv3 -o \"$tmpAbsDir/$zipFile\" $libsURL";
  97. die "Couldn't download $zipFile!" if $result;
  98. $result = system "unzip", "-q", "-d", $tmpAbsDir, "$tmpAbsDir/$zipFile";
  99. die "Couldn't unzip $zipFile." if $result;
  100. print "\nInstalling $file...\n";
  101. sub wanted
  102. {
  103. my $relativeName = File::Spec->abs2rel($File::Find::name, "$tmpAbsDir/$file/$prefixInZip");
  104. my $destination = "$webkitLibrariesDir/$relativeName";
  105. if (-d $_) {
  106. mkdir $destination;
  107. return;
  108. }
  109. system "cp", $_, $destination;
  110. }
  111. File::Find::find(\&wanted, "$tmpAbsDir/$file");
  112. $result = system "mv", "$tmpAbsDir/$file.headers", $webkitLibrariesDir;
  113. print STDERR "Couldn't move $file.headers to $webkitLibrariesDir" . ".\n" if $result;
  114. print "The $file has been sucessfully installed in\n $webkitLibrariesDir\n";
  115. exit;
  116. sub toUnixPath
  117. {
  118. my $path = shift;
  119. return unless $path;
  120. chomp($path = `cygpath -u '$path'`);
  121. return $path;
  122. }
  123. sub lastModifiedToUnixTime($)
  124. {
  125. my ($str) = @_;
  126. $str =~ /^Last-Modified: (.*)$/ or return;
  127. return str2time($1);
  128. }
  129. sub getLibraryName($)
  130. {
  131. my $url = shift;
  132. $url =~ m#/([^/]+)\.zip$#;
  133. return $1;
  134. }