diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebInspectorUI/Scripts | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebInspectorUI/Scripts')
8 files changed, 854 insertions, 0 deletions
diff --git a/Source/WebInspectorUI/Scripts/combine-resources.pl b/Source/WebInspectorUI/Scripts/combine-resources.pl new file mode 100755 index 000000000..6d2cf4404 --- /dev/null +++ b/Source/WebInspectorUI/Scripts/combine-resources.pl @@ -0,0 +1,116 @@ +#!/usr/bin/perl -w + +# Copyright (C) 2015 Apple Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. + +use strict; +use Getopt::Long; +use File::Basename; +use File::Path; + +our $inputDirectory; +our $outputDirectory; +our $outputScriptName; +our $outputStylesheetName; +our $derivedSourcesDirectory; +our $htmlDirectory; +our $htmlFile; +our $strip; + +GetOptions('output-dir=s' => \$outputDirectory, + 'output-script-name=s' => \$outputScriptName, + 'output-style-name=s' => \$outputStylesheetName, + 'derived-sources-dir=s' => \$derivedSourcesDirectory, + 'input-dir=s' => \$inputDirectory, + 'input-html-dir=s' => \$htmlDirectory, + 'input-html=s' => \$htmlFile, + 'strip' => \$strip); + +unless (defined $htmlFile and defined $derivedSourcesDirectory and defined $outputDirectory and (defined $strip or defined $outputScriptName or defined $outputStylesheetName)) { + print "Usage: $0 --input-html <path> --derived-sources-dir <path> --output-dir <path> [--output-script-name <name>] [--output-style-name <name>] [--strip]\n"; + exit; +} + +$htmlDirectory = dirname($htmlFile) unless $htmlDirectory; + +our $htmlContents; + +{ + local $/; + open HTML, $htmlFile or die; + $htmlContents = <HTML>; + close HTML; +} + +$htmlContents =~ m/<head>(.*)<\/head>/si; +our $headContents = $1; + +mkpath $outputDirectory; + +sub concatenateFiles($$$) +{ + my $filename = shift; + my $tagExpression = shift; + my $concatenatedTag = shift; + my $fileCount = 0; + + open OUT, ">", "$outputDirectory/$filename" or die "Can't open $outputDirectory/$filename: $!"; + + while ($headContents =~ m/$tagExpression/gi) { + local $/; + open IN, "$htmlDirectory/$1" or open IN, "$derivedSourcesDirectory/$1" or die "Can't open $htmlDirectory/$1: $!"; + print OUT "\n" if $fileCount++; + print OUT "/* $1 */\n\n"; + print OUT <IN>; + close IN; + } + + close OUT; + + # Don't use \s so we can control the newlines we consume. + my $replacementExpression = "([\t ]*)" . $tagExpression . "[\t ]*\n+"; + + if (defined $strip) { + # Just strip all occurrences of the pattern. + $headContents =~ s/$replacementExpression//gi; + } else { + # Replace the first occurrence with a token so we can inject the concatenated tag in the same place + # as the first file that got consolidated. This makes sure we preserve some order if there are other + # items in the head that we didn't consolidate. + $headContents =~ s/$replacementExpression/$1%CONCATENATED%\n/i; + $headContents =~ s/$replacementExpression//gi; + $headContents =~ s/%CONCATENATED%/$concatenatedTag/; + } +} + +my $inputDirectoryPattern = "(?!External\/)(?!Workers\/)[^\"]*"; +$inputDirectoryPattern = $inputDirectory . "\/[^\"]*" if $inputDirectory; + +concatenateFiles($outputStylesheetName, "<link rel=\"stylesheet\" href=\"($inputDirectoryPattern)\">", "<link rel=\"stylesheet\" href=\"$outputStylesheetName\">") if defined $outputStylesheetName; +concatenateFiles($outputScriptName, "<script src=\"($inputDirectoryPattern)\"><\/script>", "<script src=\"$outputScriptName\"></script>") if defined $outputScriptName; + +$htmlContents =~ s/<head>.*<\/head>/<head>$headContents<\/head>/si; + +open HTML, ">", "$outputDirectory/" . basename($htmlFile) or die "Can't open $outputDirectory/" . basename($htmlFile) . ": $!"; +print HTML $htmlContents; +close HTML; diff --git a/Source/WebInspectorUI/Scripts/copy-user-interface-resources-dryrun.rb b/Source/WebInspectorUI/Scripts/copy-user-interface-resources-dryrun.rb new file mode 100755 index 000000000..22f9cb60e --- /dev/null +++ b/Source/WebInspectorUI/Scripts/copy-user-interface-resources-dryrun.rb @@ -0,0 +1,68 @@ +#!/usr/bin/ruby + +# Copyright (C) 2015 Apple Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. + +require 'fileutils' +require 'tmpdir' + +if ARGV.size != 1 || ARGV[0].include?("-h") + puts "usage: #{File.basename $0} <output-directory>" + exit 1 +end + +JAVASCRIPTCORE_PATH = File.expand_path File.join(File.dirname(__FILE__), "..", "..", "JavaScriptCore") +WEB_INSPECTOR_PATH = File.expand_path File.join(File.dirname(__FILE__), "..") +COPY_USER_INTERFACE_RESOURCES_PATH = File.join WEB_INSPECTOR_PATH, "Scripts", "copy-user-interface-resources.pl" + +# This script simulates processing user interface resources located in SRCROOT. +# It places processed files in the specified output directory. This is most similar +# to an isolated OBJROOT since it includes DerivedSources. It doesn't place files +# into their DSTROOT locations, such as inside of WebInspectorUI.framework. +$output_directory = File.expand_path ARGV[0] +$start_directory = FileUtils.pwd + +Dir.mktmpdir do |tmpdir| + + # Create the output directory if needed. + FileUtils.mkdir_p $output_directory + + # Create empty derived sources expected to exist. + FileUtils.touch(File.join(tmpdir, 'InspectorBackendCommands.js')) + + # Setup the environment and run. + ENV["DERIVED_SOURCES_DIR"] = tmpdir + # Stage some scripts expected to be in various framework PrivateHeaders. + ENV["JAVASCRIPTCORE_PRIVATE_HEADERS_DIR"] = tmpdir + FileUtils.cp(File.join(JAVASCRIPTCORE_PATH, "Scripts", "cssmin.py"), tmpdir) + FileUtils.cp(File.join(JAVASCRIPTCORE_PATH, "Scripts", "jsmin.py"), tmpdir) + ENV["SRCROOT"] = WEB_INSPECTOR_PATH + ENV["TARGET_BUILD_DIR"] = $output_directory + ENV["UNLOCALIZED_RESOURCES_FOLDER_PATH"] = "" + ENV["COMBINE_INSPECTOR_RESOURCES"] = "YES" + ENV["COMBINE_TEST_RESOURCES"] = "YES" + ENV["FORCE_TOOL_INSTALL"] = "NO" + FileUtils.cd $start_directory + system(COPY_USER_INTERFACE_RESOURCES_PATH) or raise "Failed to process user interface resources." + +end diff --git a/Source/WebInspectorUI/Scripts/copy-user-interface-resources.pl b/Source/WebInspectorUI/Scripts/copy-user-interface-resources.pl new file mode 100755 index 000000000..b632a5aa8 --- /dev/null +++ b/Source/WebInspectorUI/Scripts/copy-user-interface-resources.pl @@ -0,0 +1,347 @@ +#!/usr/bin/perl -w + +# Copyright (C) 2015 Apple Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. + +use English; +use File::Copy qw(copy); +use File::Path qw(make_path remove_tree); +use File::Spec; + +my $useDirCopy = 0; + +# Not all systems (e.g., OS X) include File::Copy::Recursive. Only +# use it if we have it installed. +eval "use File::Copy::Recursive"; +unless ($@) { + $useDirCopy = 1; + File::Copy::Recursive->import(); +} + +sub ditto($$) +{ + my ($source, $destination) = @_; + + if ($useDirCopy) { + File::Copy::Recursive::dircopy($source, $destination) or die "Unable to copy directory $source to $destination: $!"; + } elsif ($^O eq 'darwin') { + system('ditto', $source, $destination); + } else { + die "Please install the PEP module File::Copy::Recursive"; + } +} + +sub seedFile($$) +{ + my ($targetFile, $seedText) = @_; + + if (open(TARGET_FILE, '>', $targetFile)) { + print TARGET_FILE $seedText; + close(TARGET_FILE); + } +} + +sub appendFile($$) +{ + my ($targetFile, $srcFile) = @_; + + open(SRC_FILE, '<', $srcFile) or die "Unable to open $srcFile: $!"; + my @srcText = <SRC_FILE>; + close(SRC_FILE); + open(TARGET_FILE, '>>', $targetFile) or die "Unable to open $targetFile: $!"; + print TARGET_FILE @srcText; + close(TARGET_FILE); +} + +sub readLicenseFile($) +{ + my ($licenseFilePath) = @_; + + open(LICENSE_FILE, '<', $licenseFilePath) or die "Unable to open $licenseFilePath: $!"; + + my $license = "/*\n"; + $license .= ' * ' . $_ while <LICENSE_FILE>; + $license .= " */\n"; + + close(LICENSE_FILE); + + return $license; +} + +my $inspectorLicense = <<'EOF'; +/* + * Copyright (C) 2007-2016 Apple Inc. All rights reserved. + * Copyright (C) 2008 Matt Lilek. All rights reserved. + * Copyright (C) 2008-2009 Anthony Ricaud <rik@webkit.org> + * Copyright (C) 2009-2010 Joseph Pecoraro. All rights reserved. + * Copyright (C) 2009-2011 Google Inc. All rights reserved. + * Copyright (C) 2009 280 North Inc. All Rights Reserved. + * Copyright (C) 2010 Nikita Vasilyev. All rights reserved. + * Copyright (C) 2011 Brian Grinstead All rights reserved. + * Copyright (C) 2013 Matt Holden <jftholden@yahoo.com> + * Copyright (C) 2013 Samsung Electronics. All rights reserved. + * Copyright (C) 2013 Seokju Kwon (seokju.kwon@gmail.com) + * Copyright (C) 2013 Adobe Systems Inc. All rights reserved. + * Copyright (C) 2013-2015 University of Washington. All rights reserved. + * Copyright (C) 2014-2015 Saam Barati <saambarati1@gmail.com> + * Copyright (C) 2014 Antoine Quint + * Copyright (C) 2015 Tobias Reiss <tobi+webkit@basecode.de> + * Copyright (C) 2015-2016 Devin Rousso <dcrousso+webkit@gmail.com>. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ +EOF + +my $perl = $^X; +my $python = ($OSNAME =~ /cygwin/) ? "/usr/bin/python" : "python"; +my $derivedSourcesDir = $ENV{'DERIVED_SOURCES_DIR'}; +my $scriptsRoot = File::Spec->catdir($ENV{'SRCROOT'}, 'Scripts'); +my $sharedScriptsRoot = File::Spec->catdir($ENV{'JAVASCRIPTCORE_PRIVATE_HEADERS_DIR'}); +my $uiRoot = File::Spec->catdir($ENV{'SRCROOT'}, 'UserInterface'); +my $targetResourcePath = File::Spec->catdir($ENV{'TARGET_BUILD_DIR'}, $ENV{'UNLOCALIZED_RESOURCES_FOLDER_PATH'}); +my $protocolDir = File::Spec->catdir($targetResourcePath, 'Protocol'); +my $workersDir = File::Spec->catdir($targetResourcePath, 'Workers'); +my $codeMirrorPath = File::Spec->catdir($uiRoot, 'External', 'CodeMirror'); +my $esprimaPath = File::Spec->catdir($uiRoot, 'External', 'Esprima'); +my $eslintPath = File::Spec->catdir($uiRoot, 'External', 'ESLint'); + +my $codeMirrorLicense = readLicenseFile(File::Spec->catfile($codeMirrorPath, 'LICENSE')); +my $esprimaLicense = readLicenseFile(File::Spec->catfile($esprimaPath, 'LICENSE')); +my $eslintLicense = readLicenseFile(File::Spec->catfile($eslintPath, 'LICENSE')); +make_path($protocolDir, $targetResourcePath); + +# Copy over dynamically loaded files from other frameworks, even if we aren't combining resources. +copy(File::Spec->catfile($ENV{'JAVASCRIPTCORE_PRIVATE_HEADERS_DIR'}, 'InspectorBackendCommands.js'), File::Spec->catfile($protocolDir, 'InspectorBackendCommands.js')) or die "Copy of InspectorBackendCommands.js failed: $!"; + +my $forceToolInstall = defined $ENV{'FORCE_TOOL_INSTALL'} && ($ENV{'FORCE_TOOL_INSTALL'} eq 'YES'); +my $shouldCombineMain = defined $ENV{'COMBINE_INSPECTOR_RESOURCES'} && ($ENV{'COMBINE_INSPECTOR_RESOURCES'} eq 'YES'); +my $shouldCombineTest = defined $ENV{'COMBINE_TEST_RESOURCES'} && ($ENV{'COMBINE_TEST_RESOURCES'} eq 'YES'); +my $combineResourcesCmd = File::Spec->catfile($scriptsRoot, 'combine-resources.pl'); + +if ($forceToolInstall) { + # Copy all files over individually to ensure we have Test.html / Test.js and files included from Test.html. + # We may then proceed to include combined & optimized resources which will output mostly to different paths + # but overwrite Main.html / Main.js with optimized versions. + ditto($uiRoot, $targetResourcePath); + + # Also force combining test resources for tool installs. + $shouldCombineTest = 1; +} + +if ($shouldCombineMain) { + # Remove Debug JavaScript and CSS files in Production builds. + system($perl, $combineResourcesCmd, + '--input-dir', 'Debug', + '--input-html', File::Spec->catfile($uiRoot, 'Main.html'), + '--input-html-dir', $uiRoot, + '--derived-sources-dir', $derivedSourcesDir, + '--output-dir', $derivedSourcesDir, + '--output-script-name', 'Debug.js', + '--output-style-name', 'Debug.css', + '--strip'); + + # Combine the JavaScript and CSS files in Production builds into single files (Main.js and Main.css). + my $derivedSourcesMainHTML = File::Spec->catfile($derivedSourcesDir, 'Main.html'); + system($perl, $combineResourcesCmd, + '--input-html', $derivedSourcesMainHTML, + '--input-html-dir', $uiRoot, + '--derived-sources-dir', $derivedSourcesDir, + '--output-dir', $derivedSourcesDir, + '--output-script-name', 'Main.js', + '--output-style-name', 'Main.css'); + + # Combine the CodeMirror JavaScript and CSS files in Production builds into single files (CodeMirror.js and CodeMirror.css). + system($perl, $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'); + + # Combine the Esprima JavaScript files in Production builds into a single file (Esprima.js). + system($perl, $combineResourcesCmd, + '--input-dir', 'External/Esprima', + '--input-html', $derivedSourcesMainHTML, + '--input-html-dir', $uiRoot, + '--derived-sources-dir', $derivedSourcesDir, + '--output-dir', $derivedSourcesDir, + '--output-script-name', 'Esprima.js'); + + # Combine the ESLint JavaScript files in Production builds into a single file (ESLint.js). + system($perl, $combineResourcesCmd, + '--input-dir', 'External/ESLint', + '--input-html', $derivedSourcesMainHTML, + '--input-html-dir', $uiRoot, + '--derived-sources-dir', $derivedSourcesDir, + '--output-dir', $derivedSourcesDir, + '--output-script-name', 'ESLint.js'); + + # Remove console.assert calls from the Main.js file. + my $derivedSourcesMainJS = File::Spec->catfile($derivedSourcesDir, 'Main.js'); + system($perl, File::Spec->catfile($scriptsRoot, 'remove-console-asserts.pl'), + '--input-script', $derivedSourcesMainJS, + '--output-script', $derivedSourcesMainJS); + + # Fix Image URLs in the Main.css file by removing the "../". + my $derivedSourcesMainCSS = File::Spec->catfile($derivedSourcesDir, 'Main.css'); + if (open(INPUT_MAIN, '<', $derivedSourcesMainCSS)) { + local $/; + my $cssContents = <INPUT_MAIN>; + close(INPUT_MAIN); + open(OUTPUT_MAIN, '>', $derivedSourcesMainCSS); + $cssContents =~ s/\.\.\/Images/Images/g; + print OUTPUT_MAIN $cssContents; + close(OUTPUT_MAIN); + } + + # Export the license into Main.js. + my $targetMainJS = File::Spec->catfile($targetResourcePath, 'Main.js'); + seedFile($targetMainJS, $inspectorLicense); + + my $targetMainCSS = File::Spec->catfile($targetResourcePath, 'Main.css'); + seedFile($targetMainCSS, $inspectorLicense); + + # Export the license into CodeMirror.js and CodeMirror.css. + my $targetCodeMirrorJS = File::Spec->catfile($targetResourcePath, 'CodeMirror.js'); + seedFile($targetCodeMirrorJS, $codeMirrorLicense); + + my $targetCodeMirrorCSS = File::Spec->catfile($targetResourcePath, 'CodeMirror.css'); + seedFile($targetCodeMirrorCSS, $codeMirrorLicense); + + # Export the license into Esprima.js. + my $targetEsprimaJS = File::Spec->catfile($targetResourcePath, 'Esprima.js'); + seedFile($targetEsprimaJS, $esprimaLicense); + + # Export the license into ESLint.js. + my $targetESLintJS = File::Spec->catfile($targetResourcePath, 'ESLint.js'); + seedFile($targetESLintJS, $eslintLicense); + + # Minify the Main.js and Main.css files, with Main.js appending to the license that was exported above. + my $jsMinScript = File::Spec->catfile($sharedScriptsRoot, 'jsmin.py'); + my $cssMinScript = File::Spec->catfile($sharedScriptsRoot, 'cssmin.py'); + system(qq("$python" "$jsMinScript" < "$derivedSourcesMainJS" >> "$targetMainJS")) and die "Failed to minify $derivedSourcesMainJS: $!"; + system(qq("$python" "$cssMinScript" < "$derivedSourcesMainCSS" >> "$targetMainCSS")) and die "Failed to minify $derivedSourcesMainCSS: $!"; + + # Minify the CodeMirror.js and CodeMirror.css files, appending to the license that was exported above. + my $derivedSourcesCodeMirrorJS = File::Spec->catfile($derivedSourcesDir, 'CodeMirror.js'); + my $derivedSourcesCodeMirrorCSS = File::Spec->catfile($derivedSourcesDir, 'CodeMirror.css'); + system(qq("$python" "$jsMinScript" < "$derivedSourcesCodeMirrorJS" >> "$targetCodeMirrorJS")) and die "Failed to minify $derivedSourcesCodeMirrorJS: $!"; + system(qq("$python" "$cssMinScript" < "$derivedSourcesCodeMirrorCSS" >> "$targetCodeMirrorCSS")) and die "Failed to minify $derivedSourcesCodeMirrorCSS: $!"; + + # Minify the Esprima.js file, appending to the license that was exported above. + my $derivedSourcesEsprimaJS = File::Spec->catfile($derivedSourcesDir, 'Esprima.js'); + system(qq("$python" "$jsMinScript" < "$derivedSourcesEsprimaJS" >> "$targetEsprimaJS")) and die "Failed to minify $derivedSourcesEsprimaJS: $!"; + + # Minify the ESLint.js file, appending to the license that was exported above. + my $derivedSourcesESLintJS = File::Spec->catfile($derivedSourcesDir, 'ESLint.js'); + system(qq("$python" "$jsMinScript" < "$derivedSourcesESLintJS" >> "$targetESLintJS")) and die "Failed to minify $derivedSourcesESLintJS: $!"; + + # Copy over Main.html and the Images directory. + copy($derivedSourcesMainHTML, File::Spec->catfile($targetResourcePath, 'Main.html')); + + ditto(File::Spec->catdir($uiRoot, 'Images'), File::Spec->catdir($targetResourcePath, 'Images')); + + # Remove Images/gtk on Mac and Windows builds. + remove_tree(File::Spec->catdir($targetResourcePath, 'Images', 'gtk')) if defined $ENV{'MAC_OS_X_VERSION_MAJOR'} or defined $ENV{'OFFICIAL_BUILD'}; + + # Remove ESLint until needed: <https://webkit.org/b/136515> Web Inspector: JavaScript source text editor should have a linter + unlink $targetESLintJS; + + # Copy the Protocol/Legacy and Workers directories. + ditto(File::Spec->catfile($uiRoot, 'Protocol', 'Legacy'), File::Spec->catfile($protocolDir, 'Legacy')); + ditto(File::Spec->catfile($uiRoot, 'Workers'), $workersDir); + + # Remove console.assert calls from the Worker js files. + system($perl, File::Spec->catfile($scriptsRoot, 'remove-console-asserts.pl'), + '--input-directory', $workersDir); + + # Fix import references in Workers directories. This rewrites "../../External/script.js" import paths to their new locations. + system($perl, File::Spec->catfile($scriptsRoot, 'fix-worker-imports-for-optimized-builds.pl'), + '--input-directory', $workersDir) and die "Failed to update Worker imports for optimized builds."; +} else { + # Keep the files separate for engineering builds. + ditto($uiRoot, $targetResourcePath); +} + +if ($shouldCombineTest) { + # Combine the JavaScript files for testing into a single file (TestCombined.js). + system($perl, $combineResourcesCmd, + '--input-html', File::Spec->catfile($uiRoot, 'Test.html'), + '--derived-sources-dir', $derivedSourcesDir, + '--output-dir', $derivedSourcesDir, + '--output-script-name', 'TestCombined.js', + '--output-style-name', 'TestCombined.css'); + + my $derivedSourcesTestHTML = File::Spec->catfile($derivedSourcesDir, 'Test.html'); + my $derivedSourcesTestJS = File::Spec->catfile($derivedSourcesDir, 'TestCombined.js'); + # Combine the Esprima JavaScript files for testing into a single file (Esprima.js). + system($perl, $combineResourcesCmd, + '--input-dir', 'External/Esprima', + '--input-html', $derivedSourcesTestHTML, + '--input-html-dir', $uiRoot, + '--derived-sources-dir', $derivedSourcesDir, + '--output-dir', $derivedSourcesDir, + '--output-script-name', 'TestEsprima.js'); + + # Export the license into TestCombined.js. + my $targetTestJS = File::Spec->catfile($targetResourcePath, 'TestCombined.js'); + seedFile($targetTestJS, $inspectorLicense); + + # Export the license into Esprima.js. + my $targetEsprimaJS = File::Spec->catfile($targetResourcePath, 'TestEsprima.js'); + seedFile($targetEsprimaJS, $esprimaLicense); + + # Append TestCombined.js to the license that was exported above. + appendFile($targetTestJS, $derivedSourcesTestJS); + + # Append Esprima.js to the license that was exported above. + my $derivedSourcesEsprimaJS = File::Spec->catfile($derivedSourcesDir, 'TestEsprima.js'); + appendFile($targetEsprimaJS, $derivedSourcesEsprimaJS); + + # Copy over Test.html. + copy($derivedSourcesTestHTML, File::Spec->catfile($targetResourcePath, 'Test.html')); + + # Copy the Legacy directory. + ditto(File::Spec->catfile($uiRoot, 'Protocol', 'Legacy'), File::Spec->catfile($protocolDir, 'Legacy')); +} diff --git a/Source/WebInspectorUI/Scripts/fix-worker-imports-for-optimized-builds.pl b/Source/WebInspectorUI/Scripts/fix-worker-imports-for-optimized-builds.pl new file mode 100755 index 000000000..8a8d25a2c --- /dev/null +++ b/Source/WebInspectorUI/Scripts/fix-worker-imports-for-optimized-builds.pl @@ -0,0 +1,69 @@ +#!/usr/bin/perl -w + +use strict; +use Getopt::Long; +use File::Copy qw/move/; +use File::Temp qw/tempfile/; +use File::Spec; + +sub fixWorkerImportsInFile($$); +sub fixWorkerImportsInDirectory($); + +our $inputDirectory; + +GetOptions('input-directory=s' => \$inputDirectory); + +if (defined $inputDirectory) { + fixWorkerImportsInDirectory($inputDirectory); + exit; +} + +print "Usage: $0 --input-directory <path>\n"; +exit; + +sub fixWorkerImportsInFile($$) +{ + my $inputScriptFilename = shift; + my $outputScriptFilename = shift; + + open IN, $inputScriptFilename or die "Couldn't open $inputScriptFilename: $!"; + my ($out, $tempFilename) = tempfile(UNLINK => 0) or die; + + my $previousLine = ""; + while (<IN>) { + s|/External/Esprima/esprima.js|/Esprima.js|; + print $out $_; + + # Error if there is an "External/" path that we did not rewrite. + if ($_ =~ /External\//) { + my $sanitizedPath = $inputScriptFilename; + $sanitizedPath =~ s/^.*?Workers/Workers/; + print "ERROR: $sanitizedPath: Unhandled External importScript in Worker script on line $.: $_"; + exit 1; + } + } + + close $out; + close IN; + + move $tempFilename, $outputScriptFilename or die "$!"; +} + +sub fixWorkerImportsInDirectory($) +{ + my $inputDirectory = shift; + + opendir(DIR, $inputDirectory) || die "$!"; + my @files = grep { !/^\.{1,2}$/ } readdir (DIR); + closedir(DIR); + + foreach my $file (@files) { + next if $file eq '.' or $file eq '..'; + my $path = File::Spec->catdir($inputDirectory, $file); + if (-d $path) { + fixWorkerImportsInDirectory($path); + } elsif ($file =~ /\.js$/) { + fixWorkerImportsInFile($path, $path); + } + } +} diff --git a/Source/WebInspectorUI/Scripts/remove-console-asserts-dryrun.rb b/Source/WebInspectorUI/Scripts/remove-console-asserts-dryrun.rb new file mode 100755 index 000000000..3ecff58ce --- /dev/null +++ b/Source/WebInspectorUI/Scripts/remove-console-asserts-dryrun.rb @@ -0,0 +1,23 @@ +#!/usr/bin/ruby + +require "find" + +$verbose = ARGV.include?("--verbose"); +$remove_console_asserts_path = File.expand_path File.join(File.dirname(__FILE__), "remove-console-asserts.pl") +$web_inspector_user_interface_path = File.expand_path File.join(File.dirname(__FILE__), "..", "UserInterface") + +Find.find($web_inspector_user_interface_path) do |path| + # Skip directories, External, Images, and non-js. + next if File.directory?(path) + next if path =~ /\/(External|Images)\// + next if path !~ /\.js$/ + + # Run remove-console-asserts on each file. + puts "Checking: #{path} ..." if $verbose + output = %x{ perl '#{$remove_console_asserts_path}' --input-script '#{path}' --output-script /dev/null } + if !output.empty? + puts "#{File.basename(path)}:" + puts output + puts + end +end diff --git a/Source/WebInspectorUI/Scripts/remove-console-asserts.pl b/Source/WebInspectorUI/Scripts/remove-console-asserts.pl new file mode 100755 index 000000000..6d011b8a9 --- /dev/null +++ b/Source/WebInspectorUI/Scripts/remove-console-asserts.pl @@ -0,0 +1,88 @@ +#!/usr/bin/perl -w + +use strict; +use Getopt::Long; +use File::Copy qw/move/; +use File::Temp qw/tempfile/; +use File::Spec; + +sub removeConsoleAssertsInFile($$); +sub removeConsoleAssertsInDirectory($); + +our $inputDirectory; +our $inputScriptFilename; +our $outputScriptFilename; + +GetOptions('input-directory=s' => \$inputDirectory, + 'input-script=s' => \$inputScriptFilename, + 'output-script=s' => \$outputScriptFilename); + +if (defined $inputScriptFilename and defined $outputScriptFilename) { + removeConsoleAssertsInFile($inputScriptFilename, $outputScriptFilename); + exit; +} + +if (defined $inputDirectory) { + removeConsoleAssertsInDirectory($inputDirectory); + exit; +} + +print "Usage: $0 --input-script <path> --output-script <path>\n"; +print "Usage: $0 --input-directory <path>\n"; +exit; + +sub removeConsoleAssertsInFile($$) +{ + my $inputScriptFilename = shift; + my $outputScriptFilename = shift; + + open IN, $inputScriptFilename or die "Couldn't open $inputScriptFilename: $!"; + my ($out, $tempFilename) = tempfile(UNLINK => 0) or die; + + my $previousLine = ""; + while (<IN>) { + # Warn about console.assert in control flow statement without braces. Can change logic when stripped. + if (/console\.assert/) { + if ($previousLine =~ /^\s*(for|if|else|while|do)\b/ && $previousLine !~ /\{\s*$/) { + print "WARNING: console.assert inside control flow statement without braces on line: $.: $_"; + } + } + + s/\s*console\.assert\(.*\);\s*//g; + print $out $_; + $previousLine = $_ if $_ !~ /^\s*$/; + + # If console.assert is still on the line, either we missed a semicolon or it is multi-line. These did not get stripped. + if ($_ =~ /\s*console\.assert\(/) { + if ($_ =~ /\)\s*$/) { + print "WARNING: console.assert missing trailing semicolon on line $.: $_" ; + } else { + print "WARNING: Multi-line console.assert on line $.: $_" ; + } + } + } + + close $out; + close IN; + + move $tempFilename, $outputScriptFilename or die "$!"; +} + +sub removeConsoleAssertsInDirectory($) +{ + my $inputDirectory = shift; + + opendir(DIR, $inputDirectory) || die "$!"; + my @files = grep { !/^\.{1,2}$/ } readdir (DIR); + closedir(DIR); + + foreach my $file (@files) { + next if $file eq '.' or $file eq '..'; + my $path = File::Spec->catdir($inputDirectory, $file); + if (-d $path) { + removeConsoleAssertsInDirectory($path); + } elsif ($file =~ /\.js$/) { + removeConsoleAssertsInFile($path, $path); + } + } +} diff --git a/Source/WebInspectorUI/Scripts/update-LegacyInspectorBackendCommands.rb b/Source/WebInspectorUI/Scripts/update-LegacyInspectorBackendCommands.rb new file mode 100755 index 000000000..21d306e2c --- /dev/null +++ b/Source/WebInspectorUI/Scripts/update-LegacyInspectorBackendCommands.rb @@ -0,0 +1,74 @@ +#!/usr/bin/ruby + +require 'fileutils' +require 'tmpdir' + +if ARGV.size != 0 + puts "usage: #{File.basename $0}" + exit 1 +end + +WEB_INSPECTOR_PATH = File.expand_path File.join(File.dirname(__FILE__), "..") +JAVASCRIPTCORE_PATH = File.expand_path File.join(File.dirname(__FILE__), "..", "..", "JavaScriptCore") + +$code_generator_path = File.join JAVASCRIPTCORE_PATH, "inspector", "scripts", "generate-inspector-protocol-bindings.py" +$versions_directory_path = File.join WEB_INSPECTOR_PATH, "Versions" +$web_inspector_protocol_legacy_path = File.join WEB_INSPECTOR_PATH, "UserInterface", "Protocol", "Legacy" + +class Task + def initialize(input_json_path, output_directory_path) + @input_json_path = input_json_path + @output_directory_path = output_directory_path + end + + def run + output_filename = "InspectorBackendCommands.js" + display_input = File.basename @input_json_path + display_output = File.join @output_directory_path.gsub(/^.*?\/UserInterface/, "UserInterface"), output_filename + puts "#{display_input} -> #{display_output}" + + Dir.mktmpdir do |tmpdir| + dependency = @dependency_json_path ? "'#{@dependency_json_path}'" : "" + cmd = "#{$code_generator_path} --force --outputDir '#{tmpdir}' --framework JavaScriptCore '#{@input_json_path}' #{dependency}" + %x{ #{cmd} } + if $?.exitstatus != 0 + puts "ERROR: Error Code (#{$?.exitstatus}) Evaluating: #{cmd}" + exit 1 + end + + generated_path = File.join tmpdir, output_filename + if !File.exists?(generated_path) + puts "ERROR: Generated file does not exist at expected path." + exit 1 + end + + FileUtils.mkdir_p @output_directory_path + FileUtils.cp generated_path, @output_directory_path + end + end +end + +def all_tasks + tasks = [] + + had_error = false + Dir.glob(File.join($versions_directory_path, "*.json")).each do |version_path| + match = File.basename(version_path).match(/^Inspector\-(.*?)\-([^-]+?)\.json$/) + if match + output_path = File.join $web_inspector_protocol_legacy_path, match[2] + tasks << Task.new(version_path, output_path) + else + puts "ERROR: Version file (#{version_path}) did not match the template Inspector-<ANYTHING>-<VERSION>.js" + had_error = true + end + end + exit 1 if had_error + + tasks +end + +def main + all_tasks.each { |task| task.run } +end + +main diff --git a/Source/WebInspectorUI/Scripts/update-codemirror-resources.rb b/Source/WebInspectorUI/Scripts/update-codemirror-resources.rb new file mode 100755 index 000000000..2f158aaf9 --- /dev/null +++ b/Source/WebInspectorUI/Scripts/update-codemirror-resources.rb @@ -0,0 +1,69 @@ +#!/usr/bin/ruby + +require 'fileutils' + +if ARGV.size != 1 + puts "usage: #{File.basename $0} <codemirror-repo-path>" + exit 1 +end + +def verify_code_mirror_repository_path(path) + if !File.directory? path + puts "ERROR: Provided CodeMirror path is not a directory." + exit 1 + end + + Dir.chdir(path) do + results = `git config --list | grep 'codemirror/CodeMirror\.git'` + if $?.exitstatus != 0 || results.split("\n").empty? + puts "ERROR: Provided CodeMirror path does not appear to be a CodeMirror checkout." + exit 1 + end + end +end + +code_mirror_repository_path = File.expand_path ARGV[0] +verify_code_mirror_repository_path code_mirror_repository_path + +web_inspector_user_interface_path = File.expand_path File.join(File.dirname(__FILE__), "../UserInterface") +web_inspector_code_mirror_resources_path = File.join web_inspector_user_interface_path, "/External/CodeMirror" + +CODE_MIRROR_FILES_TO_COPY = %w( + LICENSE + addon/comment/comment.js + addon/display/placeholder.js + addon/edit/closebrackets.js + addon/edit/matchbrackets.js + addon/mode/overlay.js + addon/runmode/runmode.js + addon/search/searchcursor.js + addon/selection/mark-selection.js + keymap/sublime.js + lib/codemirror.css + lib/codemirror.js + mode/clojure/clojure.js + mode/coffeescript/coffeescript.js + mode/css/css.js + mode/htmlmixed/htmlmixed.js + mode/javascript/javascript.js + mode/livescript/livescript.js + mode/sass/sass.js + mode/sql/sql.js + mode/xml/xml.js +) + +all_success = true + +CODE_MIRROR_FILES_TO_COPY.each do |subpath| + from_path = File.join code_mirror_repository_path, subpath + to_path = File.join web_inspector_code_mirror_resources_path, File.basename(subpath) + begin + puts "Copying #{File.basename(subpath)}..." + FileUtils.cp from_path, to_path + rescue Exception => e + puts "WARNING: #{e}" + all_success = false + end +end + +exit all_success ? 0 : 1 |