Title: [229932] trunk/Source/WebInspectorUI
Revision
229932
Author
bb...@apple.com
Date
2018-03-23 16:35:03 -0700 (Fri, 23 Mar 2018)

Log Message

Web Inspector: add WebKitAdditions hooks for WebInspectorUI
https://bugs.webkit.org/show_bug.cgi?id=183940
<rdar://problem/38796310>

Reviewed by Timothy Hatcher.

* Scripts/combine-resources.pl:
(debugLog): Added. Leave in the logging I used to debug this.

(concatenateIncludedFilesMatchingPattern):
(stripIncludedFilesMatchingPattern):
(concatenateFiles): Deleted.
This function tried to do too many things. Split it into
two functions, one for stripping includes and one for concatenating
files referenced by includes.

Lastly, add a negative lookahead clause for 'WebKitAdditions' so includes
containing that string are not combined when no input directory is passed
to the script.

* Scripts/copy-user-interface-resources.pl:
WebKitAdditions is computed either from BUILT_PRODUCTS_DIR or SDKROOT,
depending on the build style. Just try them in order and use the first
one that exists. WebInspectorUI files are in their own directory, so
we can assume there are files to process if that directory exists.

Copy Main.html to derived sources before doing any processing on it.
This makes all combining phases have the same --input-html argument.

(debugLog): Added. Leave in the logging I used to debug this.

(combineOrStripResourcesForWebKitAdditions):
(stripResourcesForWebKitAdditions):
(combineResourcesForWebKitAdditions):
Determine if WebKitAdditions exists and whether there are any
resources for WebInspectorUI present that need to be processed.

* UserInterface/Main.html:
Add stub .js and .css WebKitAdditions files. We can add more later
if it makes sense but this is good enough to validate the build machinery.

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (229931 => 229932)


--- trunk/Source/WebInspectorUI/ChangeLog	2018-03-23 23:28:05 UTC (rev 229931)
+++ trunk/Source/WebInspectorUI/ChangeLog	2018-03-23 23:35:03 UTC (rev 229932)
@@ -1,3 +1,46 @@
+2018-03-23  Brian Burg  <bb...@apple.com>
+
+        Web Inspector: add WebKitAdditions hooks for WebInspectorUI
+        https://bugs.webkit.org/show_bug.cgi?id=183940
+        <rdar://problem/38796310>
+
+        Reviewed by Timothy Hatcher.
+
+        * Scripts/combine-resources.pl:
+        (debugLog): Added. Leave in the logging I used to debug this.
+
+        (concatenateIncludedFilesMatchingPattern):
+        (stripIncludedFilesMatchingPattern):
+        (concatenateFiles): Deleted.
+        This function tried to do too many things. Split it into
+        two functions, one for stripping includes and one for concatenating
+        files referenced by includes.
+
+        Lastly, add a negative lookahead clause for 'WebKitAdditions' so includes
+        containing that string are not combined when no input directory is passed
+        to the script.
+
+        * Scripts/copy-user-interface-resources.pl:
+        WebKitAdditions is computed either from BUILT_PRODUCTS_DIR or SDKROOT,
+        depending on the build style. Just try them in order and use the first
+        one that exists. WebInspectorUI files are in their own directory, so
+        we can assume there are files to process if that directory exists.
+
+        Copy Main.html to derived sources before doing any processing on it.
+        This makes all combining phases have the same --input-html argument.
+
+        (debugLog): Added. Leave in the logging I used to debug this.
+
+        (combineOrStripResourcesForWebKitAdditions):
+        (stripResourcesForWebKitAdditions):
+        (combineResourcesForWebKitAdditions):
+        Determine if WebKitAdditions exists and whether there are any
+        resources for WebInspectorUI present that need to be processed.
+
+        * UserInterface/Main.html:
+        Add stub .js and .css WebKitAdditions files. We can add more later
+        if it makes sense but this is good enough to validate the build machinery.
+
 2018-03-23  Nikita Vasilyev  <nvasil...@apple.com>
 
         Web Inspector: Styles Redesign: flashing when switching between nodes

Modified: trunk/Source/WebInspectorUI/Scripts/combine-resources.pl (229931 => 229932)


--- trunk/Source/WebInspectorUI/Scripts/combine-resources.pl	2018-03-23 23:28:05 UTC (rev 229931)
+++ trunk/Source/WebInspectorUI/Scripts/combine-resources.pl	2018-03-23 23:35:03 UTC (rev 229932)
@@ -1,6 +1,6 @@
 #!/usr/bin/env perl
 
-# Copyright (C) 2015 Apple Inc. All rights reserved.
+# Copyright (C) 2015-2018 Apple Inc. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -37,6 +37,7 @@
 our $htmlDirectory;
 our $htmlFile;
 our $strip;
+our $verbose;
 
 GetOptions('output-dir=s' => \$outputDirectory,
            'output-script-name=s' => \$outputScriptName,
@@ -45,6 +46,7 @@
            'input-dir=s' => \$inputDirectory,
            'input-html-dir=s' => \$htmlDirectory,
            'input-html=s' => \$htmlFile,
+           'verbose' => \$verbose,
            'strip' => \$strip);
 
 unless (defined $htmlFile and defined $derivedSourcesDirectory and defined $outputDirectory and (defined $strip or defined $outputScriptName or defined $outputStylesheetName)) {
@@ -52,6 +54,12 @@
     exit;
 }
 
+sub debugLog($)
+{
+    my $logString = shift;
+    print "-- $logString\n" if $verbose;
+}
+
 $htmlDirectory = dirname($htmlFile) unless $htmlDirectory;
 
 our $htmlContents;
@@ -58,7 +66,7 @@
 
 {
     local $/;
-    open HTML, $htmlFile or die;
+    open HTML, $htmlFile or die "Could not open $htmlFile";
     $htmlContents = <HTML>;
     close HTML;
 }
@@ -68,7 +76,7 @@
 
 mkpath $outputDirectory;
 
-sub concatenateFiles($$$)
+sub concatenateIncludedFilesMatchingPattern($$$)
 {
     my $filename = shift;
     my $tagExpression = shift;
@@ -75,6 +83,8 @@
     my $concatenatedTag = shift;
     my $fileCount = 0;
 
+    debugLog("combining files for $filename with pattern $tagExpression");
+
     open OUT, ">", "$outputDirectory/$filename" or die "Can't open $outputDirectory/$filename: $!";
 
     while ($headContents =~ m/$tagExpression/gi) {
@@ -91,24 +101,33 @@
     # 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/;
-    }
+    # 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\/)[^\"]*";
+sub stripIncludedFilesMatchingPattern($)
+{
+    my $tagPattern = shift;
+
+    # Don't use \s so we can control the newlines we consume.
+    my $whitespaceConsumingTagPattern = "([\t ]*)" . $tagPattern . "[\t ]*\n+";
+    $headContents =~ s/$whitespaceConsumingTagPattern//gi;
+}
+
+my $inputDirectoryPattern = "(?!WebKitAdditions\/)(?!External\/)(?!Workers\/)[^\"]*";
 $inputDirectoryPattern = $inputDirectory . "\/[^\"]*" if $inputDirectory;
 
-concatenateFiles($outputStylesheetName, "<link rel=\"stylesheet\" href="" "<link rel=\"stylesheet\" href="" if defined $outputStylesheetName;
-concatenateFiles($outputScriptName, "<script src="" "<script src="" if defined $outputScriptName;
+if (defined($strip)) {
+    stripIncludedFilesMatchingPattern("<link rel=\"stylesheet\" href=""
+    stripIncludedFilesMatchingPattern("<script src=""
+} else {
+    concatenateIncludedFilesMatchingPattern($outputStylesheetName, "<link rel=\"stylesheet\" href="" "<link rel=\"stylesheet\" href="" if defined $outputStylesheetName;
+    concatenateIncludedFilesMatchingPattern($outputScriptName, "<script src="" "<script src="" if defined $outputScriptName;
+}
 
 $htmlContents =~ s/<head>.*<\/head>/<head>$headContents<\/head>/si;
 

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


--- trunk/Source/WebInspectorUI/Scripts/copy-user-interface-resources.pl	2018-03-23 23:28:05 UTC (rev 229931)
+++ trunk/Source/WebInspectorUI/Scripts/copy-user-interface-resources.pl	2018-03-23 23:35:03 UTC (rev 229932)
@@ -1,6 +1,6 @@
 #!/usr/bin/env perl
 
-# Copyright (C) 2015 Apple Inc. All rights reserved.
+# Copyright (C) 2015-2018 Apple Inc. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -25,10 +25,21 @@
 
 use warnings;
 use English;
+use File::Basename qw(dirname);
 use File::Copy qw(copy);
 use File::Path qw(make_path remove_tree);
 use File::Spec;
+use Getopt::Long;
 
+my $verbose = 0;
+GetOptions('verbose' => \$verbose);
+
+sub debugLog($)
+{
+    my $logString = shift;
+    print "-- $logString\n" if $verbose;
+}
+
 my $useDirCopy = 0;
 
 # Not all systems (e.g., OS X) include File::Copy::Recursive. Only
@@ -101,7 +112,7 @@
 
 my $inspectorLicense = <<'EOF';
 /*
- * Copyright (C) 2007-2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2007-2018 Apple Inc. All rights reserved.
  * Copyright (C) 2008 Matt Lilek. All rights reserved.
  * Copyright (C) 2008-2009 Anthony Ricaud <r...@webkit.org>
  * Copyright (C) 2009-2010 Joseph Pecoraro. All rights reserved.
@@ -157,6 +168,13 @@
 my $eslintPath = File::Spec->catdir($uiRoot, 'External', 'ESLint');
 my $threejsPath = File::Spec->catdir($uiRoot, 'External', 'three.js');
 
+my $webkitAdditionsDir;
+$webkitAdditionsDir = File::Spec->catdir($ENV{'BUILT_PRODUCTS_DIR'}, 'usr', 'local', 'include', 'WebKitAdditions');
+$webkitAdditionsDir = File::Spec->catdir($ENV{'SDKROOT'}, 'usr', 'local', 'include', 'WebKitAdditions') unless -d $webkitAdditionsDir;
+my $webInspectorUIAdditionsDir = File::Spec->catdir($webkitAdditionsDir, 'WebInspectorUI');
+
+debugLog("webkitAdditionsDir: $webkitAdditionsDir");
+
 my $codeMirrorLicense = readLicenseFile(File::Spec->catfile($codeMirrorPath, 'LICENSE'));
 my $esprimaLicense = readLicenseFile(File::Spec->catfile($esprimaPath, 'LICENSE'));
 my $eslintLicense = readLicenseFile(File::Spec->catfile($eslintPath, 'LICENSE'));
@@ -181,11 +199,72 @@
     $shouldCombineTest = 1;
 }
 
+if (!$shouldCombineMain) {
+    # Keep the files separate for engineering builds. Copy these before altering Main.html
+    # in other ways, such as combining for WebKitAdditions or inlining files.
+    ditto($uiRoot, $targetResourcePath);
+}
+
+# Always refer to the copy in derived sources so the order of replacements does not matter.
+make_path($derivedSourcesDir);
+my $derivedSourcesMainHTML = File::Spec->catfile($derivedSourcesDir, 'Main.html');
+copy(File::Spec->catfile($uiRoot, 'Main.html'), File::Spec->catfile($derivedSourcesDir, 'Main.html')) or die "Copy failed: $!";
+
+sub combineOrStripResourcesForWebKitAdditions() {
+    my $combineWebKitAdditions = 0;
+
+    if (-d $webInspectorUIAdditionsDir) {
+        $combineWebKitAdditions = 1;
+        debugLog("Found $webInspectorUIAdditionsDir");
+    } else {
+        debugLog("Didn't find $webInspectorUIAdditionsDir");
+    }
+
+    if ($combineWebKitAdditions) {
+        debugLog("Combining resources provided by WebKitAdditions.");
+        combineResourcesForWebKitAdditions();
+    } else {
+        debugLog("Stripping resources provided by WebKitAdditions.");
+        stripResourcesForWebKitAdditions();
+    }
+}
+
+sub stripResourcesForWebKitAdditions() {
+    system($perl, $combineResourcesCmd,
+        '--input-dir', 'WebKitAdditions',
+        '--input-html', $derivedSourcesMainHTML,
+        '--derived-sources-dir', $derivedSourcesDir,
+        '--output-dir', $derivedSourcesDir,
+        '--strip');
+}
+
+sub combineResourcesForWebKitAdditions() {
+    $rootPathForRelativeIncludes = dirname(dirname($webInspectorUIAdditionsDir));
+    system($perl, $combineResourcesCmd,
+        '--input-dir', 'WebKitAdditions',
+        '--input-html', $derivedSourcesMainHTML,
+        '--input-html-dir', $rootPathForRelativeIncludes,
+        '--derived-sources-dir', $derivedSourcesDir,
+        '--output-dir', $derivedSourcesDir,
+        '--output-script-name', 'WebKitAdditions.js',
+        '--output-style-name', 'WebKitAdditions.css');
+
+    # Export the license into WebKitAdditions files.
+    my $targetWebKitAdditionsJS = File::Spec->catfile($targetResourcePath, 'WebKitAdditions.js');
+    seedFile($targetWebKitAdditionsJS, $inspectorLicense);
+
+    my $targetWebKitAdditionsCSS = File::Spec->catfile($targetResourcePath, 'WebKitAdditions.css');
+    seedFile($targetWebKitAdditionsCSS, $inspectorLicense);
+
+    appendFile($targetWebKitAdditionsJS, File::Spec->catfile($derivedSourcesDir, 'WebKitAdditions.js'));
+    appendFile($targetWebKitAdditionsCSS, File::Spec->catfile($derivedSourcesDir, 'WebKitAdditions.css'));
+}
+
 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', $derivedSourcesMainHTML,
         '--input-html-dir', $uiRoot,
         '--derived-sources-dir', $derivedSourcesDir,
         '--output-dir', $derivedSourcesDir,
@@ -194,7 +273,6 @@
         '--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,
@@ -203,6 +281,10 @@
        '--output-script-name', 'Main.js',
        '--output-style-name', 'Main.css');
 
+    # Process WebKitAdditions.{css,js} after Main.{js,css}. Otherwise, the combined WebKitAdditions files
+    # will get slurped into Main.{js,css} because the 'WebKitAdditions' relative URL prefix will be removed.
+    combineOrStripResourcesForWebKitAdditions();
+
     # 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',
@@ -308,9 +390,7 @@
     my $derivedSourcesThreejsJS = File::Spec->catfile($derivedSourcesDir, 'Three.js');
     system(qq("$python" "$jsMinScript" < "$derivedSourcesThreejsJS" >> "$targetThreejsJS")) and die "Failed to minify $derivedSourcesThreejsJS: $!";
 
-    # Copy over Main.html and the Images directory.
-    copy($derivedSourcesMainHTML, File::Spec->catfile($targetResourcePath, 'Main.html'));
-
+    # Copy over the Images directory.
     ditto(File::Spec->catdir($uiRoot, 'Images'), File::Spec->catdir($targetResourcePath, 'Images'));
 
     # Remove ESLint until needed: <https://webkit.org/b/136515> Web Inspector: _javascript_ source text editor should have a linter
@@ -328,10 +408,17 @@
     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);
+    # Always process WebKitAdditions files because the 'WebKitAdditions' path prefix is not real,
+    # so it can't proceed as a normal load from the bundle as written. This function replaces the
+    # dummy prefix with the actual WebKitAdditions path when looking for files to inline and combine.
+    combineOrStripResourcesForWebKitAdditions();
 }
 
+# Always copy over Main.html because we may have combined WebKitAdditions files
+# without minifying anything else. We always want to combine WKA so the relevant
+# resources are copied out of Derived Sources rather than an arbitrary WKA directory.
+copy($derivedSourcesMainHTML, File::Spec->catfile($targetResourcePath, 'Main.html'));
+
 if ($shouldCombineTest) {
     # Combine the _javascript_ files for testing into a single file (TestCombined.js).
     system($perl, $combineResourcesCmd,

Modified: trunk/Source/WebInspectorUI/UserInterface/Main.html (229931 => 229932)


--- trunk/Source/WebInspectorUI/UserInterface/Main.html	2018-03-23 23:28:05 UTC (rev 229931)
+++ trunk/Source/WebInspectorUI/UserInterface/Main.html	2018-03-23 23:35:03 UTC (rev 229932)
@@ -240,6 +240,8 @@
     <link rel="stylesheet" href=""
     <link rel="stylesheet" href=""
 
+    <link rel="stylesheet" href=""
+
     <script src=""
 
     <script src=""
@@ -867,6 +869,8 @@
     <script src=""
     <script src=""
 
+    <script src=""
+
     <script>
         WI.sharedApp = new WI.AppController;
         WI.sharedApp.initialize();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to