3 use File::Copy qw(copy);
4 use File::Path qw(make_path);
9 # Not all systems (e.g., OS X) include File::Copy::Recursive. Only
10 # use it if we have it installed.
11 eval "use File::Copy::Recursive";
14 File::Copy::Recursive->import();
19 my ($source, $destination) = @_;
22 File::Copy::Recursive::dircopy($source, $destination) or die "Unable to copy directory $source to $destination: $!";
23 } elsif ($^O eq 'darwin') {
24 system('ditto', $source, $destination);
26 die "Please install the PEP module File::Copy::Recursive";
32 my ($targetFile, $seedText) = @_;
34 if (open(TARGET_FILE, '>', $targetFile)) {
35 print TARGET_FILE $seedText;
40 my $LICENSE = <<'EOF';
42 * Copyright (C) 2007-2014 Apple Inc. All rights reserved.
43 * Copyright (C) 2009-2011 Google Inc. All rights reserved.
44 * Copyright (C) 2009-2010 Joseph Pecoraro. All rights reserved.
45 * Copyright (C) 2008 Matt Lilek. All rights reserved.
46 * Copyright (C) 2008-2009 Anthony Ricaud <rik@webkit.org>
47 * Copyright (C) 2009 280 North Inc. All Rights Reserved.
48 * Copyright (C) 2010 Nikita Vasilyev. All rights reserved.
49 * Copyright (C) 2011 Brian Grinstead All rights reserved.
50 * Copyright (C) 2013 Matt Holden <jftholden@yahoo.com>
51 * Copyright (C) 2013 Samsung Electronics. All rights reserved.
52 * Copyright (C) 2013 Seokju Kwon (seokju.kwon@gmail.com)
53 * Copyright (C) 2013 Adobe Systems Inc. All rights reserved.
54 * Copyright (C) 2013 University of Washington. All rights reserved.
56 * Redistribution and use in source and binary forms, with or without
57 * modification, are permitted provided that the following conditions
59 * 1. Redistributions of source code must retain the above copyright
60 * notice, this list of conditions and the following disclaimer.
61 * 2. Redistributions in binary form must reproduce the above copyright
62 * notice, this list of conditions and the following disclaimer in the
63 * documentation and/or other materials provided with the distribution.
65 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
66 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
67 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
68 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
69 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
70 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
71 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
72 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
73 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
74 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
75 * THE POSSIBILITY OF SUCH DAMAGE.
79 my $derivedSourcesDir = $ENV{'DERIVED_SOURCES_DIR'};
80 my $scriptsRoot = File::Spec->catdir($ENV{'SRCROOT'}, 'Scripts');
81 my $uiRoot = File::Spec->catdir($ENV{'SRCROOT'}, 'UserInterface');
82 my $targetResourcePath = File::Spec->catdir($ENV{'TARGET_BUILD_DIR'}, $ENV{'UNLOCALIZED_RESOURCES_FOLDER_PATH'});
83 my $protocolDir = File::Spec->catdir($targetResourcePath, 'Protocol');
84 my $codeMirrorPath = File::Spec->catdir($uiRoot, 'External', 'CodeMirror');
86 my $codeMirrorLicenseFile = File::Spec->catfile($codeMirrorPath, 'LICENSE');
87 open(CMLFILE, '<', $codeMirrorLicenseFile) or die "Unable to open $codeMirrorLicenseFile: $!";
88 my $CODE_MIRROR_LICENSE = "/*\n";
90 $CODE_MIRROR_LICENSE .= ' * ' . $_;
93 $CODE_MIRROR_LICENSE .= " */\n";
95 make_path($protocolDir, $targetResourcePath);
97 # Copy over dynamically loaded files from other frameworks, even if we aren't combining resources.
98 copy(File::Spec->catfile($ENV{'JAVASCRIPTCORE_PRIVATE_HEADERS_DIR'}, 'InspectorJSBackendCommands.js'), File::Spec->catfile($protocolDir, 'InspectorJSBackendCommands.js')) or die "Copy of InspectorJSBackendCommands.js failed: $!";
99 copy(File::Spec->catfile($ENV{'WEBCORE_PRIVATE_HEADERS_DIR'}, 'InspectorWebBackendCommands.js'), File::Spec->catfile($protocolDir, 'InspectorWebBackendCommands.js')) or die "Copy of InspectorWebBackendCommands.js failed: $!";
101 if (defined $ENV{'COMBINE_INSPECTOR_RESOURCES'} && ($ENV{'COMBINE_INSPECTOR_RESOURCES'} eq 'YES')) {
102 my $combineResourcesCmd = File::Spec->catfile($scriptsRoot, 'combine-resources.pl');
104 # Combine the JavaScript and CSS files in Production builds into single files (Main.js and Main.css).
105 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');
107 # Combine the CodeMirror JavaScript and CSS files in Production builds into single files (CodeMirror.js and CodeMirror.css).
108 my $derivedSourcesMainHTML = File::Spec->catfile($derivedSourcesDir, 'Main.html');
109 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');
111 # Remove console.assert calls from the Main.js file.
112 my $derivedSourcesMainJS = File::Spec->catfile($derivedSourcesDir, 'Main.js');
113 system(File::Spec->catfile($scriptsRoot, 'remove-console-asserts.pl'), '--input-script', $derivedSourcesMainJS, '--output-script', $derivedSourcesMainJS);
115 # Fix Image URLs in the Main.css file by removing the "../".
116 my $derivedSourcesMainCSS = File::Spec->catfile($derivedSourcesDir, 'Main.css');
117 if (open(INPUT_MAIN, '<', $derivedSourcesMainCSS)) {
119 my $cssContents = <INPUT_MAIN>;
121 open(OUTPUT_MAIN, '>', $derivedSourcesMainCSS);
122 $cssContents =~ s/\.\.\/Images/Images/g;
123 print OUTPUT_MAIN $cssContents;
127 # Export the license into Main.js.
128 my $targetMainJS = File::Spec->catfile($targetResourcePath, 'Main.js');
129 seedFile($targetMainJS, $LICENSE);
131 my $targetMainCSS = File::Spec->catfile($targetResourcePath, 'Main.css');
132 seedFile($targetMainCSS, $LICENSE);
134 # Export the license into CodeMirror.js and CodeMirror.css.
135 my $targetCodeMirrorJS = File::Spec->catfile($targetResourcePath, 'CodeMirror.js');
136 seedFile($targetCodeMirrorJS, $LICENSE);
138 my $targetCodeMirrorCSS = File::Spec->catfile($targetResourcePath, 'CodeMirror.css');
139 seedFile($targetCodeMirrorCSS, $LICENSE);
141 # Minify the Main.js and Main.css files, with Main.js appending to the license that was exported above.
142 my $jsMinScript = File::Spec->catfile($scriptsRoot, 'jsmin.py');
143 my $cssMinScript = File::Spec->catfile($scriptsRoot, 'cssmin.py');
144 system(qq(python "$jsMinScript" < "$derivedSourcesMainJS" >> "$targetMainJS")) and die "Failed to minify $derivedSourcesMainJS: $!";
145 system(qq(python "$cssMinScript" < "$derivedSourcesMainCSS" >> "$targetMainCSS")) and die "Failed to minify $derivedSourcesMainCSS: $!";
147 # Minify the CodeMirror.js and CodeMirror.css files, appending to the license that was exported above.
148 my $derivedSouressCodeMirrorJS = File::Spec->catfile($derivedSourcesDir, 'CodeMirror.js');
149 my $derivedSourcesCodeMirrorCSS = File::Spec->catfile($derivedSourcesDir, 'CodeMirror.css');
150 system(qq(python "$jsMinScript" < "$derivedSouressCodeMirrorJS" >> "$targetCodeMirrorJS")) and die "Failed to minify $derivedSouressCodeMirrorJS: $!";
151 system(qq(python "$cssMinScript" < "$derivedSourcesCodeMirrorCSS" >> "$targetCodeMirrorCSS")) and die "Failed to minify $derivedSourcesCodeMirrorCSS: $!";
153 # Copy over Main.html and the Images directory.
154 copy($derivedSourcesMainHTML, File::Spec->catfile($targetResourcePath, 'Main.html'));
156 ditto(File::Spec->catdir($uiRoot, 'Images'), File::Spec->catdir($targetResourcePath, 'Images'));
158 # Copy the Legacy directory.
159 ditto(File::Spec->catfile($uiRoot, 'Protocol', 'Legacy'), File::Spec->catfile($protocolDir, 'Legacy'));
161 # Keep the files separate for engineering builds.
162 ditto($uiRoot, $targetResourcePath);