update-webkit-support-libs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/usr/bin/perl -w
  2. # Copyright (C) 2005, 2006, 2007 Apple Computer, Inc. All rights reserved.
  3. # Copyright (C) Research In Motion Limited 2010. 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 WebKitSupportLibrary
  29. use strict;
  30. use warnings;
  31. use File::Find;
  32. use File::Temp ();
  33. use File::Spec;
  34. use FindBin;
  35. use lib $FindBin::Bin;
  36. use webkitdirs;
  37. use constant NOTAVERSION => "-1";
  38. my $sourceDir = sourceDir();
  39. my $file = "WebKitSupportLibrary";
  40. my $zipFile = "$file.zip";
  41. my $zipDirectory = toUnixPath($ENV{'WEBKITSUPPORTLIBRARIESZIPDIR'}) || $sourceDir;
  42. my $pathToZip = File::Spec->catfile($zipDirectory, $zipFile);
  43. my $webkitLibrariesDir = toUnixPath($ENV{'WEBKIT_LIBRARIES'}) || "$sourceDir/WebKitLibraries/win";
  44. my $versionFile = $file . "Version";
  45. my $pathToVersionFile = File::Spec->catfile($webkitLibrariesDir, $versionFile);
  46. my $tmpRelativeDir = File::Temp::tempdir("webkitlibsXXXXXXX", TMPDIR => 1, CLEANUP => 1);
  47. my $tmpAbsDir = File::Spec->rel2abs($tmpRelativeDir);
  48. my $versionFileURL = "https://developer.apple.com/opensource/internet/$versionFile";
  49. my $extractedVersion = extractedVersion();
  50. # Check whether the extracted library is up-to-date. If it is, we don't have anything to do.
  51. my $expectedVersion = downloadExpectedVersionNumber();
  52. if ($extractedVersion ne NOTAVERSION && $extractedVersion eq $expectedVersion) {
  53. print "$file is up-to-date.\n";
  54. exit;
  55. }
  56. # Check whether the downloaded library is up-to-date. If it isn't, the user needs to download it.
  57. my $zipFileVersion = zipFileVersion();
  58. dieAndInstructToDownload("$zipFile could not be found in $zipDirectory.") if $zipFileVersion eq NOTAVERSION;
  59. dieAndInstructToDownload("$zipFile is out-of-date.") if $expectedVersion ne NOTAVERSION && $zipFileVersion ne $expectedVersion;
  60. if ($zipFileVersion eq $extractedVersion) {
  61. print "Falling back to existing version of $file.\n";
  62. exit;
  63. }
  64. my $result = system "unzip", "-q", "-d", $tmpAbsDir, $pathToZip;
  65. die "Couldn't unzip $zipFile." if $result;
  66. print "\nInstalling $file...\n";
  67. sub wanted
  68. {
  69. my $relativeName = File::Spec->abs2rel($File::Find::name, "$tmpAbsDir/$file/win");
  70. my $destination = "$webkitLibrariesDir/$relativeName";
  71. if (-d $_) {
  72. mkdir $destination;
  73. return;
  74. }
  75. system "cp", $_, $destination;
  76. }
  77. File::Find::find(\&wanted, "$tmpAbsDir/$file");
  78. print "The $file has been sucessfully installed in\n $webkitLibrariesDir\n";
  79. exit;
  80. sub toUnixPath
  81. {
  82. my $path = shift;
  83. return unless $path;
  84. chomp($path = `cygpath -u '$path'`);
  85. return $path;
  86. }
  87. sub extractedVersion
  88. {
  89. if (open VERSION, "<", $pathToVersionFile) {
  90. chomp(my $extractedVersion = <VERSION>);
  91. close VERSION;
  92. return $extractedVersion;
  93. }
  94. return NOTAVERSION;
  95. }
  96. sub downloadExpectedVersionNumber
  97. {
  98. chomp(my $expectedVersion = `curl -s --sslv3 -k $versionFileURL`);
  99. return WEXITSTATUS($?) ? NOTAVERSION : $expectedVersion;
  100. }
  101. sub zipFileVersion
  102. {
  103. return NOTAVERSION unless -f $pathToZip;
  104. chomp(my $zipFileVersion = `unzip -p "$pathToZip" $file/win/$versionFile`);
  105. return $zipFileVersion;
  106. }
  107. sub dieAndInstructToDownload
  108. {
  109. my $message = shift;
  110. die <<EOF;
  111. ===============================================================================
  112. $message
  113. Please download $zipFile from:
  114. https://developer.apple.com/opensource/internet/webkit_sptlib_agree.html
  115. and place it in:
  116. $sourceDir
  117. Then run build-webkit again.
  118. ===============================================================================
  119. EOF
  120. }