Title: [200229] trunk/Source/WebInspectorUI
Revision
200229
Author
[email protected]
Date
2016-04-28 22:23:46 -0700 (Thu, 28 Apr 2016)

Log Message

Web Inspector: FormatterWorker fails to find "External/Esprima.js" in Production builds
https://bugs.webkit.org/show_bug.cgi?id=157162
<rdar://problem/25996556>

Patch by Joseph Pecoraro <[email protected]> on 2016-04-28
Reviewed by Timothy Hatcher.

Workers have relative include paths. FormatterWorker has an includes
that looks like:

    importScripts(...[
        "../../External/Esprima/esprima.js",
        ...
    ]);

In optimized builds (Production) the esprima resources are combined
and moved out of an External directory to "Esprima.js". We need to
update the path of this include in optimized builds.

This adds a script to do some basic rewrites of paths. It will also
produce a build error if there are any other External paths that
may have been unhandled.

* Scripts/copy-user-interface-resources.pl:
Run a new script to fix up the Worker imports for new pathes.

* Scripts/fix-worker-imports-for-optimized-builds.pl: Added.
(fixWorkerImportsInFile):
(fixWorkerImportsInDirectory):
Replace "/External/Esprima/esprima.js" with "/Esprima.js" in imports.
Fatal error for any unhandled "/External" lines that were not replaced.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (200228 => 200229)


--- trunk/Source/WebInspectorUI/ChangeLog	2016-04-29 03:01:53 UTC (rev 200228)
+++ trunk/Source/WebInspectorUI/ChangeLog	2016-04-29 05:23:46 UTC (rev 200229)
@@ -1,3 +1,36 @@
+2016-04-28  Joseph Pecoraro  <[email protected]>
+
+        Web Inspector: FormatterWorker fails to find "External/Esprima.js" in Production builds
+        https://bugs.webkit.org/show_bug.cgi?id=157162
+        <rdar://problem/25996556>
+
+        Reviewed by Timothy Hatcher.
+
+        Workers have relative include paths. FormatterWorker has an includes
+        that looks like:
+
+            importScripts(...[
+                "../../External/Esprima/esprima.js",
+                ...
+            ]);
+
+        In optimized builds (Production) the esprima resources are combined
+        and moved out of an External directory to "Esprima.js". We need to
+        update the path of this include in optimized builds.
+
+        This adds a script to do some basic rewrites of paths. It will also
+        produce a build error if there are any other External paths that
+        may have been unhandled.
+
+        * Scripts/copy-user-interface-resources.pl:
+        Run a new script to fix up the Worker imports for new pathes.
+
+        * Scripts/fix-worker-imports-for-optimized-builds.pl: Added.
+        (fixWorkerImportsInFile):
+        (fixWorkerImportsInDirectory):
+        Replace "/External/Esprima/esprima.js" with "/Esprima.js" in imports.
+        Fatal error for any unhandled "/External" lines that were not replaced.
+
 2016-04-27  Joseph Pecoraro  <[email protected]>
 
         Web Inspector: Missing CSS autocompletion suggestions for -webkit-user-select

Modified: trunk/Source/WebInspectorUI/Scripts/copy-user-interface-resources.pl (200228 => 200229)


--- trunk/Source/WebInspectorUI/Scripts/copy-user-interface-resources.pl	2016-04-29 03:01:53 UTC (rev 200228)
+++ trunk/Source/WebInspectorUI/Scripts/copy-user-interface-resources.pl	2016-04-29 05:23:46 UTC (rev 200229)
@@ -245,6 +245,9 @@
 
     # Remove console.assert calls from the Worker js files.
     system(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(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);

Added: trunk/Source/WebInspectorUI/Scripts/fix-worker-imports-for-optimized-builds.pl (0 => 200229)


--- trunk/Source/WebInspectorUI/Scripts/fix-worker-imports-for-optimized-builds.pl	                        (rev 0)
+++ trunk/Source/WebInspectorUI/Scripts/fix-worker-imports-for-optimized-builds.pl	2016-04-29 05:23:46 UTC (rev 200229)
@@ -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);
+        }
+    }
+}
Property changes on: trunk/Source/WebInspectorUI/Scripts/fix-worker-imports-for-optimized-builds.pl
___________________________________________________________________

Added: svn:executable

_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to