mitz@apple.com | 24e143e | 2012-05-07 01:41:09 +0000 | [diff] [blame] | 1 | #!/usr/bin/perl -w |
| 2 | |
dbates@webkit.org | f56e08c | 2016-03-25 16:05:22 +0000 | [diff] [blame] | 3 | # Copyright (C) 2005-2016 Apple Inc. All rights reserved. |
mitz@apple.com | 24e143e | 2012-05-07 01:41:09 +0000 | [diff] [blame] | 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 | # |
| 15 | # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 16 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 17 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 18 | # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 19 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 20 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 21 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 22 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 24 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | |
| 26 | use strict; |
fpizlo@apple.com | 895703e | 2014-02-08 02:11:22 +0000 | [diff] [blame] | 27 | use File::Spec; |
mitz@apple.com | 24e143e | 2012-05-07 01:41:09 +0000 | [diff] [blame] | 28 | use FindBin; |
fpizlo@apple.com | 2d77183 | 2014-01-31 00:41:51 +0000 | [diff] [blame] | 29 | use Getopt::Long qw(:config pass_through); |
mitz@apple.com | 24e143e | 2012-05-07 01:41:09 +0000 | [diff] [blame] | 30 | use lib $FindBin::Bin; |
| 31 | use webkitdirs; |
| 32 | |
fpizlo@apple.com | 2d77183 | 2014-01-31 00:41:51 +0000 | [diff] [blame] | 33 | my $showHelp = 0; |
fpizlo@apple.com | d7630ae | 2014-01-31 21:26:26 +0000 | [diff] [blame] | 34 | my $wksi = 0; |
commit-queue@webkit.org | 64b96328 | 2014-08-08 19:20:19 +0000 | [diff] [blame] | 35 | my $clean = 0; |
fpizlo@apple.com | 895703e | 2014-02-08 02:11:22 +0000 | [diff] [blame] | 36 | my $useFullLibPaths = 0; |
mrowe@apple.com | e0e5cea | 2014-05-03 01:15:47 +0000 | [diff] [blame] | 37 | my $osxVersion; |
fpizlo@apple.com | 03d945b | 2014-02-12 04:06:42 +0000 | [diff] [blame] | 38 | my $force = 0; |
fpizlo@apple.com | 2d77183 | 2014-01-31 00:41:51 +0000 | [diff] [blame] | 39 | |
dbates@webkit.org | f56e08c | 2016-03-25 16:05:22 +0000 | [diff] [blame] | 40 | determineXcodeSDK(); |
commit-queue@webkit.org | 1a7076e | 2016-03-02 01:43:03 +0000 | [diff] [blame] | 41 | |
fpizlo@apple.com | 2d77183 | 2014-01-31 00:41:51 +0000 | [diff] [blame] | 42 | my $programName = basename($0); |
| 43 | my $usage = <<EOF; |
| 44 | Usage: $programName [options] |
| 45 | --help Show this help message |
fpizlo@apple.com | d7630ae | 2014-01-31 21:26:26 +0000 | [diff] [blame] | 46 | --[no-]wksi Toggle copying WebKitSystemInterface drops (default: $wksi) |
commit-queue@webkit.org | 64b96328 | 2014-08-08 19:20:19 +0000 | [diff] [blame] | 47 | --clean Clean the libraries (default: $clean) |
fpizlo@apple.com | 895703e | 2014-02-08 02:11:22 +0000 | [diff] [blame] | 48 | --[no-]use-full-lib-paths Toggle using full library paths |
dbates@webkit.org | fda2d73 | 2014-12-20 00:15:15 +0000 | [diff] [blame] | 49 | --sdk=<sdk> Use a specific Xcode SDK |
| 50 | --device Use the current iphoneos.internal SDK (iOS only) |
| 51 | --simulator Use the current iphonesimulator SDK (iOS only) |
mrowe@apple.com | e0e5cea | 2014-05-03 01:15:47 +0000 | [diff] [blame] | 52 | --osx-version=<version> Set the OS X version to use when deciding what to copy. |
fpizlo@apple.com | 03d945b | 2014-02-12 04:06:42 +0000 | [diff] [blame] | 53 | --[no-]force Toggle forcing the copy - i.e. ignoring timestamps (default: $force) |
fpizlo@apple.com | 2d77183 | 2014-01-31 00:41:51 +0000 | [diff] [blame] | 54 | EOF |
| 55 | |
| 56 | GetOptions( |
| 57 | 'help' => \$showHelp, |
fpizlo@apple.com | d7630ae | 2014-01-31 21:26:26 +0000 | [diff] [blame] | 58 | 'wksi!' => \$wksi, |
commit-queue@webkit.org | 64b96328 | 2014-08-08 19:20:19 +0000 | [diff] [blame] | 59 | 'clean' => \$clean, |
fpizlo@apple.com | 03d945b | 2014-02-12 04:06:42 +0000 | [diff] [blame] | 60 | 'use-full-lib-paths!' => \$useFullLibPaths, |
mrowe@apple.com | e0e5cea | 2014-05-03 01:15:47 +0000 | [diff] [blame] | 61 | 'osx-version=s' => \$osxVersion, |
fpizlo@apple.com | 03d945b | 2014-02-12 04:06:42 +0000 | [diff] [blame] | 62 | 'force!' => \$force |
fpizlo@apple.com | 2d77183 | 2014-01-31 00:41:51 +0000 | [diff] [blame] | 63 | ); |
| 64 | |
| 65 | if ($showHelp) { |
| 66 | print STDERR $usage; |
| 67 | exit 1; |
| 68 | } |
| 69 | |
mitz@apple.com | fedfb31 | 2012-05-09 07:46:28 +0000 | [diff] [blame] | 70 | my $productDir = shift @ARGV; |
fpizlo@apple.com | 895703e | 2014-02-08 02:11:22 +0000 | [diff] [blame] | 71 | if ($productDir) { |
| 72 | $productDir = File::Spec->rel2abs($productDir); |
| 73 | } else { |
ddkilzer@apple.com | 7c175aa | 2014-05-07 05:18:07 +0000 | [diff] [blame] | 74 | $productDir = $ENV{BUILT_PRODUCTS_DIR} || productDir(); |
fpizlo@apple.com | 895703e | 2014-02-08 02:11:22 +0000 | [diff] [blame] | 75 | } |
mitz@apple.com | 24e143e | 2012-05-07 01:41:09 +0000 | [diff] [blame] | 76 | |
bfulgham@apple.com | 6d17b50 | 2015-10-30 17:05:58 +0000 | [diff] [blame] | 77 | if (!isIOSWebKit() && !$osxVersion &&!isAnyWindows()) { |
mrowe@apple.com | e0e5cea | 2014-05-03 01:15:47 +0000 | [diff] [blame] | 78 | $osxVersion = `sw_vers -productVersion | cut -d. -f-2`; |
| 79 | chomp($osxVersion); |
| 80 | } |
| 81 | |
mitz@apple.com | 24e143e | 2012-05-07 01:41:09 +0000 | [diff] [blame] | 82 | chdirWebKit(); |
| 83 | |
dbates@webkit.org | fda2d73 | 2014-12-20 00:15:15 +0000 | [diff] [blame] | 84 | sub executeRanlib($) |
| 85 | { |
| 86 | my ($library) = @_; |
| 87 | my @args; |
| 88 | push @args, ("-sdk", xcodeSDK()) if xcodeSDK(); |
| 89 | push @args, "ranlib"; |
| 90 | push @args, "-no_warning_for_no_symbols" if isIOSWebKit(); |
| 91 | system("xcrun", @args, $library) == 0 or die; |
fpizlo@apple.com | 54c843a | 2014-03-14 22:39:06 +0000 | [diff] [blame] | 92 | } |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 93 | |
| 94 | sub unpackIfNecessary |
| 95 | { |
| 96 | my ($targetDir, $sampleFile, $package, $hasLibraries) = @_; |
fpizlo@apple.com | 03d945b | 2014-02-12 04:06:42 +0000 | [diff] [blame] | 97 | if ($force || !-e $sampleFile || -M $sampleFile > -M $package) { |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 98 | print "Unpacking $package into $targetDir\n"; |
| 99 | (system("tar -C $targetDir -xmf $package") == 0) or die; |
| 100 | if ($hasLibraries) { |
| 101 | foreach my $library (`tar -tf $package`) { |
| 102 | chomp $library; |
| 103 | print " Ranlib $library\n"; |
dbates@webkit.org | fda2d73 | 2014-12-20 00:15:15 +0000 | [diff] [blame] | 104 | executeRanlib($targetDir . "/" . $library); |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 105 | } |
| 106 | } |
oliver@apple.com | f0c513f | 2013-07-25 03:58:53 +0000 | [diff] [blame] | 107 | return 1; |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 108 | } |
oliver@apple.com | f0c513f | 2013-07-25 03:58:53 +0000 | [diff] [blame] | 109 | return 0; |
mitz@apple.com | 24e143e | 2012-05-07 01:41:09 +0000 | [diff] [blame] | 110 | } |
| 111 | |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 112 | sub dittoHeaders |
| 113 | { |
| 114 | my ($srcHeader, $header) = @_; |
fpizlo@apple.com | 03d945b | 2014-02-12 04:06:42 +0000 | [diff] [blame] | 115 | if ($force || !-e $header || -M $header > -M $srcHeader) { |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 116 | print "Updating $header\n"; |
| 117 | (system("ditto", $srcHeader, $header) == 0) or die; |
| 118 | } |
| 119 | } |
| 120 | |
dbates@webkit.org | 25812f4 | 2015-10-08 23:34:08 +0000 | [diff] [blame] | 121 | if ($clean) { |
| 122 | print "Cleaning.\n"; |
| 123 | (system("rm", "-rf", File::Spec->catfile($productDir, "usr", "local", "include", "WebKitSystemInterface.h")) == 0) or die; |
dbates@webkit.org | 25812f4 | 2015-10-08 23:34:08 +0000 | [diff] [blame] | 124 | unlink glob "$productDir/libWebKitSystemInterface*" or die if glob "$productDir/libWebKitSystemInterface*"; |
| 125 | unlink glob "$productDir/usr/local/lib/libWebKitSystemInterface*" or die if glob "$productDir/usr/local/lib/libWebKitSystemInterface*"; |
dbates@webkit.org | 25812f4 | 2015-10-08 23:34:08 +0000 | [diff] [blame] | 126 | unlink glob "$productDir/libLTO*" or die if glob "$productDir/libLTO*"; |
| 127 | } |
| 128 | |
fpizlo@apple.com | d7630ae | 2014-01-31 21:26:26 +0000 | [diff] [blame] | 129 | if ($wksi) { |
fpizlo@apple.com | 42a73a9 | 2014-02-05 21:44:26 +0000 | [diff] [blame] | 130 | (system("mkdir", "-p", "$productDir/usr/local/include") == 0) or die; |
fpizlo@apple.com | 895703e | 2014-02-08 02:11:22 +0000 | [diff] [blame] | 131 | |
| 132 | my $libraryDir = $useFullLibPaths ? "$productDir/usr/local/lib" : $productDir; |
| 133 | (system("mkdir", "-p", $libraryDir) == 0) or die; |
fpizlo@apple.com | 42a73a9 | 2014-02-05 21:44:26 +0000 | [diff] [blame] | 134 | |
dbates@webkit.org | 8261c7e | 2014-12-20 00:17:37 +0000 | [diff] [blame] | 135 | my @librariesToCopy; |
| 136 | if (isIOSWebKit()) { |
| 137 | push(@librariesToCopy, ( |
dbates@webkit.org | dab6480 | 2016-08-16 22:20:05 +0000 | [diff] [blame] | 138 | "libWebKitSystemInterfaceIOSDevice9.a", |
| 139 | "libWebKitSystemInterfaceIOSSimulator9.a", |
dbates@webkit.org | 06e8191 | 2016-09-07 19:28:01 +0000 | [diff] [blame] | 140 | "libWebKitSystemInterfaceIOSDevice10.a", |
| 141 | "libWebKitSystemInterfaceIOSSimulator10.a", |
dbates@webkit.org | 8261c7e | 2014-12-20 00:17:37 +0000 | [diff] [blame] | 142 | )); |
| 143 | } else { |
| 144 | push(@librariesToCopy, ( |
lforschler@apple.com | 3676a92 | 2015-08-13 23:26:57 +0000 | [diff] [blame] | 145 | "libWebKitSystemInterfaceYosemite.a", |
lforschler@apple.com | 8f5cf6c | 2016-06-14 16:40:47 +0000 | [diff] [blame] | 146 | "libWebKitSystemInterfaceElCapitan.a", |
| 147 | "libWebKitSystemInterfaceOSX10.12.a" |
dbates@webkit.org | 8261c7e | 2014-12-20 00:17:37 +0000 | [diff] [blame] | 148 | )); |
| 149 | } |
| 150 | |
dbates@webkit.org | fda2d73 | 2014-12-20 00:15:15 +0000 | [diff] [blame] | 151 | foreach my $libraryName (@librariesToCopy) { |
| 152 | my $sourceLibrary = "WebKitLibraries/" . $libraryName; |
| 153 | my $targetLibrary = "$libraryDir/" . $libraryName; |
| 154 | if ($force || !-e $targetLibrary || -M $targetLibrary > -M $sourceLibrary) { |
| 155 | print "Updating $targetLibrary\n"; |
| 156 | (system("ditto", $sourceLibrary, $targetLibrary) == 0) or die; |
| 157 | executeRanlib($targetLibrary); |
fpizlo@apple.com | d7630ae | 2014-01-31 21:26:26 +0000 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | |
| 161 | dittoHeaders("WebKitLibraries/WebKitSystemInterface.h", "$productDir/usr/local/include/WebKitSystemInterface.h"); |
| 162 | } |
| 163 | |
dbates@webkit.org | 25812f4 | 2015-10-08 23:34:08 +0000 | [diff] [blame] | 164 | sub fileContains |
| 165 | { |
| 166 | my ($filename, $string) = @_; |
| 167 | open my $fileHandle, '<', $filename or die; |
| 168 | while (<$fileHandle>) { |
| 169 | return 1 if /^$string$/; |
dbates@webkit.org | 8261c7e | 2014-12-20 00:17:37 +0000 | [diff] [blame] | 170 | } |
dbates@webkit.org | 25812f4 | 2015-10-08 23:34:08 +0000 | [diff] [blame] | 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | sub isContentOfFileEqualToString($$) |
| 175 | { |
| 176 | my ($filename, $string) = @_; |
| 177 | open my $fileHandle, '<', $filename or die; |
| 178 | binmode $fileHandle; |
| 179 | my $contents = <$fileHandle>; |
| 180 | return $contents eq $string; |
| 181 | } |
| 182 | |