bfulgham@apple.com | 1c18cab | 2014-04-08 21:29:09 +0000 | [diff] [blame] | 1 | #!/usr/bin/perl -w |
| 2 | |
bfulgham@apple.com | ad191ac | 2014-05-12 22:19:35 +0000 | [diff] [blame] | 3 | use English; |
bfulgham@apple.com | 1c18cab | 2014-04-08 21:29:09 +0000 | [diff] [blame] | 4 | use File::Copy qw(copy); |
timothy@apple.com | afad3b0 | 2014-09-23 21:08:36 +0000 | [diff] [blame^] | 5 | use File::Path qw(make_path remove_tree); |
bfulgham@apple.com | 1c18cab | 2014-04-08 21:29:09 +0000 | [diff] [blame] | 6 | use File::Spec; |
| 7 | |
| 8 | my $useDirCopy = 0; |
| 9 | |
| 10 | # Not all systems (e.g., OS X) include File::Copy::Recursive. Only |
| 11 | # use it if we have it installed. |
| 12 | eval "use File::Copy::Recursive"; |
| 13 | unless ($@) { |
| 14 | $useDirCopy = 1; |
| 15 | File::Copy::Recursive->import(); |
| 16 | } |
| 17 | |
| 18 | sub ditto($$) |
| 19 | { |
| 20 | my ($source, $destination) = @_; |
| 21 | |
| 22 | if ($useDirCopy) { |
| 23 | File::Copy::Recursive::dircopy($source, $destination) or die "Unable to copy directory $source to $destination: $!"; |
| 24 | } elsif ($^O eq 'darwin') { |
| 25 | system('ditto', $source, $destination); |
| 26 | } else { |
| 27 | die "Please install the PEP module File::Copy::Recursive"; |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | sub seedFile($$) |
| 32 | { |
| 33 | my ($targetFile, $seedText) = @_; |
| 34 | |
| 35 | if (open(TARGET_FILE, '>', $targetFile)) { |
| 36 | print TARGET_FILE $seedText; |
| 37 | close(TARGET_FILE); |
| 38 | } |
| 39 | } |
| 40 | |
timothy@apple.com | 338dc7f | 2014-08-08 06:48:52 +0000 | [diff] [blame] | 41 | sub readLicenseFile($) |
| 42 | { |
| 43 | my ($licenseFilePath) = @_; |
| 44 | |
| 45 | open(LICENSE_FILE, '<', $licenseFilePath) or die "Unable to open $licenseFilePath: $!"; |
| 46 | |
| 47 | my $license = "/*\n"; |
| 48 | $license .= ' * ' . $_ while <LICENSE_FILE>; |
| 49 | $license .= " */\n"; |
| 50 | |
| 51 | close(LICENSE_FILE); |
| 52 | |
| 53 | return $license; |
| 54 | } |
| 55 | |
| 56 | my $inspectorLicense = <<'EOF'; |
bfulgham@apple.com | 1c18cab | 2014-04-08 21:29:09 +0000 | [diff] [blame] | 57 | /* |
| 58 | * Copyright (C) 2007-2014 Apple Inc. All rights reserved. |
bfulgham@apple.com | 1c18cab | 2014-04-08 21:29:09 +0000 | [diff] [blame] | 59 | * Copyright (C) 2008 Matt Lilek. All rights reserved. |
| 60 | * Copyright (C) 2008-2009 Anthony Ricaud <rik@webkit.org> |
timothy@apple.com | 338dc7f | 2014-08-08 06:48:52 +0000 | [diff] [blame] | 61 | * Copyright (C) 2009-2010 Joseph Pecoraro. All rights reserved. |
| 62 | * Copyright (C) 2009-2011 Google Inc. All rights reserved. |
bfulgham@apple.com | 1c18cab | 2014-04-08 21:29:09 +0000 | [diff] [blame] | 63 | * Copyright (C) 2009 280 North Inc. All Rights Reserved. |
| 64 | * Copyright (C) 2010 Nikita Vasilyev. All rights reserved. |
| 65 | * Copyright (C) 2011 Brian Grinstead All rights reserved. |
| 66 | * Copyright (C) 2013 Matt Holden <jftholden@yahoo.com> |
| 67 | * Copyright (C) 2013 Samsung Electronics. All rights reserved. |
| 68 | * Copyright (C) 2013 Seokju Kwon (seokju.kwon@gmail.com) |
| 69 | * Copyright (C) 2013 Adobe Systems Inc. All rights reserved. |
timothy@apple.com | 338dc7f | 2014-08-08 06:48:52 +0000 | [diff] [blame] | 70 | * Copyright (C) 2013-2014 University of Washington. All rights reserved. |
bfulgham@apple.com | 1c18cab | 2014-04-08 21:29:09 +0000 | [diff] [blame] | 71 | * |
| 72 | * Redistribution and use in source and binary forms, with or without |
| 73 | * modification, are permitted provided that the following conditions |
| 74 | * are met: |
| 75 | * 1. Redistributions of source code must retain the above copyright |
| 76 | * notice, this list of conditions and the following disclaimer. |
| 77 | * 2. Redistributions in binary form must reproduce the above copyright |
| 78 | * notice, this list of conditions and the following disclaimer in the |
| 79 | * documentation and/or other materials provided with the distribution. |
| 80 | * |
| 81 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 82 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 83 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 84 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 85 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 86 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 87 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 88 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 89 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 90 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 91 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 92 | */ |
| 93 | EOF |
| 94 | |
bfulgham@apple.com | ad191ac | 2014-05-12 22:19:35 +0000 | [diff] [blame] | 95 | my $python = ($OSNAME =~ /cygwin/) ? "/usr/bin/python" : "python"; |
bfulgham@apple.com | 1c18cab | 2014-04-08 21:29:09 +0000 | [diff] [blame] | 96 | my $derivedSourcesDir = $ENV{'DERIVED_SOURCES_DIR'}; |
| 97 | my $scriptsRoot = File::Spec->catdir($ENV{'SRCROOT'}, 'Scripts'); |
| 98 | my $uiRoot = File::Spec->catdir($ENV{'SRCROOT'}, 'UserInterface'); |
| 99 | my $targetResourcePath = File::Spec->catdir($ENV{'TARGET_BUILD_DIR'}, $ENV{'UNLOCALIZED_RESOURCES_FOLDER_PATH'}); |
| 100 | my $protocolDir = File::Spec->catdir($targetResourcePath, 'Protocol'); |
| 101 | my $codeMirrorPath = File::Spec->catdir($uiRoot, 'External', 'CodeMirror'); |
timothy@apple.com | 338dc7f | 2014-08-08 06:48:52 +0000 | [diff] [blame] | 102 | my $esprimaPath = File::Spec->catdir($uiRoot, 'External', 'Esprima'); |
bfulgham@apple.com | 1c18cab | 2014-04-08 21:29:09 +0000 | [diff] [blame] | 103 | |
timothy@apple.com | 338dc7f | 2014-08-08 06:48:52 +0000 | [diff] [blame] | 104 | my $codeMirrorLicense = readLicenseFile(File::Spec->catfile($codeMirrorPath, 'LICENSE')); |
| 105 | my $esprimaMirrorLicense = readLicenseFile(File::Spec->catfile($esprimaPath, 'LICENSE')); |
bfulgham@apple.com | 1c18cab | 2014-04-08 21:29:09 +0000 | [diff] [blame] | 106 | |
| 107 | make_path($protocolDir, $targetResourcePath); |
| 108 | |
| 109 | # Copy over dynamically loaded files from other frameworks, even if we aren't combining resources. |
| 110 | copy(File::Spec->catfile($ENV{'JAVASCRIPTCORE_PRIVATE_HEADERS_DIR'}, 'InspectorJSBackendCommands.js'), File::Spec->catfile($protocolDir, 'InspectorJSBackendCommands.js')) or die "Copy of InspectorJSBackendCommands.js failed: $!"; |
| 111 | copy(File::Spec->catfile($ENV{'WEBCORE_PRIVATE_HEADERS_DIR'}, 'InspectorWebBackendCommands.js'), File::Spec->catfile($protocolDir, 'InspectorWebBackendCommands.js')) or die "Copy of InspectorWebBackendCommands.js failed: $!"; |
| 112 | |
| 113 | if (defined $ENV{'COMBINE_INSPECTOR_RESOURCES'} && ($ENV{'COMBINE_INSPECTOR_RESOURCES'} eq 'YES')) { |
| 114 | my $combineResourcesCmd = File::Spec->catfile($scriptsRoot, 'combine-resources.pl'); |
| 115 | |
| 116 | # Combine the JavaScript and CSS files in Production builds into single files (Main.js and Main.css). |
| 117 | system($combineResourcesCmd, '--input-html', File::Spec->catfile($uiRoot, 'Main.html'), '--derived-sources-dir', $derivedSourcesDir, '--output-dir', $derivedSourcesDir, '--output-script-name', 'Main.js', '--output-style-name', 'Main.css'); |
| 118 | |
| 119 | # Combine the CodeMirror JavaScript and CSS files in Production builds into single files (CodeMirror.js and CodeMirror.css). |
| 120 | my $derivedSourcesMainHTML = File::Spec->catfile($derivedSourcesDir, 'Main.html'); |
| 121 | system($combineResourcesCmd, '--input-dir', 'External/CodeMirror', '--input-html', $derivedSourcesMainHTML, '--input-html-dir', $uiRoot, '--derived-sources-dir', $derivedSourcesDir, '--output-dir', $derivedSourcesDir, '--output-script-name', 'CodeMirror.js', '--output-style-name', 'CodeMirror.css'); |
| 122 | |
timothy@apple.com | 338dc7f | 2014-08-08 06:48:52 +0000 | [diff] [blame] | 123 | # Combine the Esprima JavaScript files in Production builds into a single file (Esprima.js). |
| 124 | system($combineResourcesCmd, '--input-dir', 'External/Esprima', '--input-html', $derivedSourcesMainHTML, '--input-html-dir', $uiRoot, '--derived-sources-dir', $derivedSourcesDir, '--output-dir', $derivedSourcesDir, '--output-script-name', 'Esprima.js'); |
| 125 | |
bfulgham@apple.com | 1c18cab | 2014-04-08 21:29:09 +0000 | [diff] [blame] | 126 | # Remove console.assert calls from the Main.js file. |
| 127 | my $derivedSourcesMainJS = File::Spec->catfile($derivedSourcesDir, 'Main.js'); |
| 128 | system(File::Spec->catfile($scriptsRoot, 'remove-console-asserts.pl'), '--input-script', $derivedSourcesMainJS, '--output-script', $derivedSourcesMainJS); |
| 129 | |
| 130 | # Fix Image URLs in the Main.css file by removing the "../". |
| 131 | my $derivedSourcesMainCSS = File::Spec->catfile($derivedSourcesDir, 'Main.css'); |
| 132 | if (open(INPUT_MAIN, '<', $derivedSourcesMainCSS)) { |
| 133 | local $/; |
| 134 | my $cssContents = <INPUT_MAIN>; |
| 135 | close(INPUT_MAIN); |
| 136 | open(OUTPUT_MAIN, '>', $derivedSourcesMainCSS); |
| 137 | $cssContents =~ s/\.\.\/Images/Images/g; |
| 138 | print OUTPUT_MAIN $cssContents; |
| 139 | close(OUTPUT_MAIN); |
| 140 | } |
| 141 | |
| 142 | # Export the license into Main.js. |
| 143 | my $targetMainJS = File::Spec->catfile($targetResourcePath, 'Main.js'); |
timothy@apple.com | 338dc7f | 2014-08-08 06:48:52 +0000 | [diff] [blame] | 144 | seedFile($targetMainJS, $inspectorLicense); |
bfulgham@apple.com | 1c18cab | 2014-04-08 21:29:09 +0000 | [diff] [blame] | 145 | |
| 146 | my $targetMainCSS = File::Spec->catfile($targetResourcePath, 'Main.css'); |
timothy@apple.com | 338dc7f | 2014-08-08 06:48:52 +0000 | [diff] [blame] | 147 | seedFile($targetMainCSS, $inspectorLicense); |
bfulgham@apple.com | 1c18cab | 2014-04-08 21:29:09 +0000 | [diff] [blame] | 148 | |
| 149 | # Export the license into CodeMirror.js and CodeMirror.css. |
| 150 | my $targetCodeMirrorJS = File::Spec->catfile($targetResourcePath, 'CodeMirror.js'); |
timothy@apple.com | 338dc7f | 2014-08-08 06:48:52 +0000 | [diff] [blame] | 151 | seedFile($targetCodeMirrorJS, $codeMirrorLicense); |
bfulgham@apple.com | 1c18cab | 2014-04-08 21:29:09 +0000 | [diff] [blame] | 152 | |
| 153 | my $targetCodeMirrorCSS = File::Spec->catfile($targetResourcePath, 'CodeMirror.css'); |
timothy@apple.com | 338dc7f | 2014-08-08 06:48:52 +0000 | [diff] [blame] | 154 | seedFile($targetCodeMirrorCSS, $codeMirrorLicense); |
| 155 | |
| 156 | # Export the license into Esprima.js. |
| 157 | my $targetEsprimaJS = File::Spec->catfile($targetResourcePath, 'Esprima.js'); |
| 158 | seedFile($targetEsprimaJS, $esprimaMirrorLicense); |
bfulgham@apple.com | 1c18cab | 2014-04-08 21:29:09 +0000 | [diff] [blame] | 159 | |
| 160 | # Minify the Main.js and Main.css files, with Main.js appending to the license that was exported above. |
| 161 | my $jsMinScript = File::Spec->catfile($scriptsRoot, 'jsmin.py'); |
| 162 | my $cssMinScript = File::Spec->catfile($scriptsRoot, 'cssmin.py'); |
bfulgham@apple.com | ad191ac | 2014-05-12 22:19:35 +0000 | [diff] [blame] | 163 | system(qq("$python" "$jsMinScript" < "$derivedSourcesMainJS" >> "$targetMainJS")) and die "Failed to minify $derivedSourcesMainJS: $!"; |
| 164 | system(qq("$python" "$cssMinScript" < "$derivedSourcesMainCSS" >> "$targetMainCSS")) and die "Failed to minify $derivedSourcesMainCSS: $!"; |
bfulgham@apple.com | 1c18cab | 2014-04-08 21:29:09 +0000 | [diff] [blame] | 165 | |
| 166 | # Minify the CodeMirror.js and CodeMirror.css files, appending to the license that was exported above. |
| 167 | my $derivedSouressCodeMirrorJS = File::Spec->catfile($derivedSourcesDir, 'CodeMirror.js'); |
| 168 | my $derivedSourcesCodeMirrorCSS = File::Spec->catfile($derivedSourcesDir, 'CodeMirror.css'); |
bfulgham@apple.com | ad191ac | 2014-05-12 22:19:35 +0000 | [diff] [blame] | 169 | system(qq("$python" "$jsMinScript" < "$derivedSouressCodeMirrorJS" >> "$targetCodeMirrorJS")) and die "Failed to minify $derivedSouressCodeMirrorJS: $!"; |
| 170 | system(qq("$python" "$cssMinScript" < "$derivedSourcesCodeMirrorCSS" >> "$targetCodeMirrorCSS")) and die "Failed to minify $derivedSourcesCodeMirrorCSS: $!"; |
bfulgham@apple.com | 1c18cab | 2014-04-08 21:29:09 +0000 | [diff] [blame] | 171 | |
timothy@apple.com | 338dc7f | 2014-08-08 06:48:52 +0000 | [diff] [blame] | 172 | # Minify the Esprima.js file, appending to the license that was exported above. |
| 173 | my $derivedSouressEsprimaJS = File::Spec->catfile($derivedSourcesDir, 'Esprima.js'); |
| 174 | system(qq("$python" "$jsMinScript" < "$derivedSouressEsprimaJS" >> "$targetEsprimaJS")) and die "Failed to minify $derivedSouressEsprimaJS: $!"; |
| 175 | |
bfulgham@apple.com | 1c18cab | 2014-04-08 21:29:09 +0000 | [diff] [blame] | 176 | # Copy over Main.html and the Images directory. |
| 177 | copy($derivedSourcesMainHTML, File::Spec->catfile($targetResourcePath, 'Main.html')); |
| 178 | |
| 179 | ditto(File::Spec->catdir($uiRoot, 'Images'), File::Spec->catdir($targetResourcePath, 'Images')); |
| 180 | |
timothy@apple.com | afad3b0 | 2014-09-23 21:08:36 +0000 | [diff] [blame^] | 181 | # Remove Images/Legacy on modern systems (OS X 10.10 Yosemite and greater or Windows). |
| 182 | remove_tree(File::Spec->catdir($targetResourcePath, 'Images', 'Legacy')) if (defined $ENV{'MAC_OS_X_VERSION_MAJOR'} && $ENV{'MAC_OS_X_VERSION_MAJOR'} ge 101000) or defined $ENV{'OFFICIAL_BUILD'}; |
| 183 | |
| 184 | # Remove Images/gtk on Mac and Windows builds. |
| 185 | remove_tree(File::Spec->catdir($targetResourcePath, 'Images', 'gtk')) if defined $ENV{'MAC_OS_X_VERSION_MAJOR'} or defined $ENV{'OFFICIAL_BUILD'}; |
| 186 | |
bfulgham@apple.com | 1c18cab | 2014-04-08 21:29:09 +0000 | [diff] [blame] | 187 | # Copy the Legacy directory. |
| 188 | ditto(File::Spec->catfile($uiRoot, 'Protocol', 'Legacy'), File::Spec->catfile($protocolDir, 'Legacy')); |
| 189 | } else { |
| 190 | # Keep the files separate for engineering builds. |
| 191 | ditto($uiRoot, $targetResourcePath); |
| 192 | } |