Changeset 229932 in webkit


Ignore:
Timestamp:
Mar 23, 2018 4:35:03 PM (6 years ago)
Author:
BJ Burg
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.

Location:
trunk/Source/WebInspectorUI
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebInspectorUI/ChangeLog

    r229922 r229932  
     12018-03-23  Brian Burg  <bburg@apple.com>
     2
     3        Web Inspector: add WebKitAdditions hooks for WebInspectorUI
     4        https://bugs.webkit.org/show_bug.cgi?id=183940
     5        <rdar://problem/38796310>
     6
     7        Reviewed by Timothy Hatcher.
     8
     9        * Scripts/combine-resources.pl:
     10        (debugLog): Added. Leave in the logging I used to debug this.
     11
     12        (concatenateIncludedFilesMatchingPattern):
     13        (stripIncludedFilesMatchingPattern):
     14        (concatenateFiles): Deleted.
     15        This function tried to do too many things. Split it into
     16        two functions, one for stripping includes and one for concatenating
     17        files referenced by includes.
     18
     19        Lastly, add a negative lookahead clause for 'WebKitAdditions' so includes
     20        containing that string are not combined when no input directory is passed
     21        to the script.
     22
     23        * Scripts/copy-user-interface-resources.pl:
     24        WebKitAdditions is computed either from BUILT_PRODUCTS_DIR or SDKROOT,
     25        depending on the build style. Just try them in order and use the first
     26        one that exists. WebInspectorUI files are in their own directory, so
     27        we can assume there are files to process if that directory exists.
     28
     29        Copy Main.html to derived sources before doing any processing on it.
     30        This makes all combining phases have the same --input-html argument.
     31
     32        (debugLog): Added. Leave in the logging I used to debug this.
     33
     34        (combineOrStripResourcesForWebKitAdditions):
     35        (stripResourcesForWebKitAdditions):
     36        (combineResourcesForWebKitAdditions):
     37        Determine if WebKitAdditions exists and whether there are any
     38        resources for WebInspectorUI present that need to be processed.
     39
     40        * UserInterface/Main.html:
     41        Add stub .js and .css WebKitAdditions files. We can add more later
     42        if it makes sense but this is good enough to validate the build machinery.
     43
    1442018-03-23  Nikita Vasilyev  <nvasilyev@apple.com>
    245
  • trunk/Source/WebInspectorUI/Scripts/combine-resources.pl

    r226395 r229932  
    11#!/usr/bin/env perl
    22
    3 # Copyright (C) 2015 Apple Inc. All rights reserved.
     3# Copyright (C) 2015-2018 Apple Inc. All rights reserved.
    44#
    55# Redistribution and use in source and binary forms, with or without
     
    3838our $htmlFile;
    3939our $strip;
     40our $verbose;
    4041
    4142GetOptions('output-dir=s' => \$outputDirectory,
     
    4647           'input-html-dir=s' => \$htmlDirectory,
    4748           'input-html=s' => \$htmlFile,
     49           'verbose' => \$verbose,
    4850           'strip' => \$strip);
    4951
     
    5153    print "Usage: $0 --input-html <path> --derived-sources-dir <path> --output-dir <path> [--output-script-name <name>] [--output-style-name <name>] [--strip]\n";
    5254    exit;
     55}
     56
     57sub debugLog($)
     58{
     59    my $logString = shift;
     60    print "-- $logString\n" if $verbose;
    5361}
    5462
     
    5967{
    6068    local $/;
    61     open HTML, $htmlFile or die;
     69    open HTML, $htmlFile or die "Could not open $htmlFile";
    6270    $htmlContents = <HTML>;
    6371    close HTML;
     
    6977mkpath $outputDirectory;
    7078
    71 sub concatenateFiles($$$)
     79sub concatenateIncludedFilesMatchingPattern($$$)
    7280{
    7381    my $filename = shift;
     
    7583    my $concatenatedTag = shift;
    7684    my $fileCount = 0;
     85
     86    debugLog("combining files for $filename with pattern $tagExpression");
    7787
    7888    open OUT, ">", "$outputDirectory/$filename" or die "Can't open $outputDirectory/$filename: $!";
     
    92102    my $replacementExpression = "([\t ]*)" . $tagExpression . "[\t ]*\n+";
    93103
    94     if (defined $strip) {
    95         # Just strip all occurrences of the pattern.
    96         $headContents =~ s/$replacementExpression//gi;
    97     } else {
    98         # Replace the first occurrence with a token so we can inject the concatenated tag in the same place
    99         # as the first file that got consolidated. This makes sure we preserve some order if there are other
    100         # items in the head that we didn't consolidate.
    101         $headContents =~ s/$replacementExpression/$1%CONCATENATED%\n/i;
    102         $headContents =~ s/$replacementExpression//gi;
    103         $headContents =~ s/%CONCATENATED%/$concatenatedTag/;
    104     }
     104    # Replace the first occurrence with a token so we can inject the concatenated tag in the same place
     105    # as the first file that got consolidated. This makes sure we preserve some order if there are other
     106    # items in the head that we didn't consolidate.
     107    $headContents =~ s/$replacementExpression/$1%CONCATENATED%\n/i;
     108    $headContents =~ s/$replacementExpression//gi;
     109    $headContents =~ s/%CONCATENATED%/$concatenatedTag/;
    105110}
    106111
    107 my $inputDirectoryPattern = "(?!External\/)(?!Workers\/)[^\"]*";
     112sub stripIncludedFilesMatchingPattern($)
     113{
     114    my $tagPattern = shift;
     115
     116    # Don't use \s so we can control the newlines we consume.
     117    my $whitespaceConsumingTagPattern = "([\t ]*)" . $tagPattern . "[\t ]*\n+";
     118    $headContents =~ s/$whitespaceConsumingTagPattern//gi;
     119}
     120
     121my $inputDirectoryPattern = "(?!WebKitAdditions\/)(?!External\/)(?!Workers\/)[^\"]*";
    108122$inputDirectoryPattern = $inputDirectory . "\/[^\"]*" if $inputDirectory;
    109123
    110 concatenateFiles($outputStylesheetName, "<link rel=\"stylesheet\" href=\"($inputDirectoryPattern)\">", "<link rel=\"stylesheet\" href=\"$outputStylesheetName\">") if defined $outputStylesheetName;
    111 concatenateFiles($outputScriptName, "<script src=\"($inputDirectoryPattern)\"><\/script>", "<script src=\"$outputScriptName\"></script>") if defined $outputScriptName;
     124if (defined($strip)) {
     125    stripIncludedFilesMatchingPattern("<link rel=\"stylesheet\" href=\"($inputDirectoryPattern)\">");
     126    stripIncludedFilesMatchingPattern("<script src=\"($inputDirectoryPattern)\"><\/script>");
     127} else {
     128    concatenateIncludedFilesMatchingPattern($outputStylesheetName, "<link rel=\"stylesheet\" href=\"($inputDirectoryPattern)\">", "<link rel=\"stylesheet\" href=\"$outputStylesheetName\">") if defined $outputStylesheetName;
     129    concatenateIncludedFilesMatchingPattern($outputScriptName, "<script src=\"($inputDirectoryPattern)\"><\/script>", "<script src=\"$outputScriptName\"></script>") if defined $outputScriptName;
     130}
    112131
    113132$htmlContents =~ s/<head>.*<\/head>/<head>$headContents<\/head>/si;
  • trunk/Source/WebInspectorUI/Scripts/copy-user-interface-resources.pl

    r226395 r229932  
    11#!/usr/bin/env perl
    22
    3 # Copyright (C) 2015 Apple Inc. All rights reserved.
     3# Copyright (C) 2015-2018 Apple Inc. All rights reserved.
    44#
    55# Redistribution and use in source and binary forms, with or without
     
    2626use warnings;
    2727use English;
     28use File::Basename qw(dirname);
    2829use File::Copy qw(copy);
    2930use File::Path qw(make_path remove_tree);
    3031use File::Spec;
     32use Getopt::Long;
     33
     34my $verbose = 0;
     35GetOptions('verbose' => \$verbose);
     36
     37sub debugLog($)
     38{
     39    my $logString = shift;
     40    print "-- $logString\n" if $verbose;
     41}
    3142
    3243my $useDirCopy = 0;
     
    102113my $inspectorLicense = <<'EOF';
    103114/*
    104  * Copyright (C) 2007-2016 Apple Inc. All rights reserved.
     115 * Copyright (C) 2007-2018 Apple Inc. All rights reserved.
    105116 * Copyright (C) 2008 Matt Lilek. All rights reserved.
    106117 * Copyright (C) 2008-2009 Anthony Ricaud <rik@webkit.org>
     
    158169my $threejsPath = File::Spec->catdir($uiRoot, 'External', 'three.js');
    159170
     171my $webkitAdditionsDir;
     172$webkitAdditionsDir = File::Spec->catdir($ENV{'BUILT_PRODUCTS_DIR'}, 'usr', 'local', 'include', 'WebKitAdditions');
     173$webkitAdditionsDir = File::Spec->catdir($ENV{'SDKROOT'}, 'usr', 'local', 'include', 'WebKitAdditions') unless -d $webkitAdditionsDir;
     174my $webInspectorUIAdditionsDir = File::Spec->catdir($webkitAdditionsDir, 'WebInspectorUI');
     175
     176debugLog("webkitAdditionsDir: $webkitAdditionsDir");
     177
    160178my $codeMirrorLicense = readLicenseFile(File::Spec->catfile($codeMirrorPath, 'LICENSE'));
    161179my $esprimaLicense = readLicenseFile(File::Spec->catfile($esprimaPath, 'LICENSE'));
     
    182200}
    183201
     202if (!$shouldCombineMain) {
     203    # Keep the files separate for engineering builds. Copy these before altering Main.html
     204    # in other ways, such as combining for WebKitAdditions or inlining files.
     205    ditto($uiRoot, $targetResourcePath);
     206}
     207
     208# Always refer to the copy in derived sources so the order of replacements does not matter.
     209make_path($derivedSourcesDir);
     210my $derivedSourcesMainHTML = File::Spec->catfile($derivedSourcesDir, 'Main.html');
     211copy(File::Spec->catfile($uiRoot, 'Main.html'), File::Spec->catfile($derivedSourcesDir, 'Main.html')) or die "Copy failed: $!";
     212
     213sub combineOrStripResourcesForWebKitAdditions() {
     214    my $combineWebKitAdditions = 0;
     215
     216    if (-d $webInspectorUIAdditionsDir) {
     217        $combineWebKitAdditions = 1;
     218        debugLog("Found $webInspectorUIAdditionsDir");
     219    } else {
     220        debugLog("Didn't find $webInspectorUIAdditionsDir");
     221    }
     222
     223    if ($combineWebKitAdditions) {
     224        debugLog("Combining resources provided by WebKitAdditions.");
     225        combineResourcesForWebKitAdditions();
     226    } else {
     227        debugLog("Stripping resources provided by WebKitAdditions.");
     228        stripResourcesForWebKitAdditions();
     229    }
     230}
     231
     232sub stripResourcesForWebKitAdditions() {
     233    system($perl, $combineResourcesCmd,
     234        '--input-dir', 'WebKitAdditions',
     235        '--input-html', $derivedSourcesMainHTML,
     236        '--derived-sources-dir', $derivedSourcesDir,
     237        '--output-dir', $derivedSourcesDir,
     238        '--strip');
     239}
     240
     241sub combineResourcesForWebKitAdditions() {
     242    $rootPathForRelativeIncludes = dirname(dirname($webInspectorUIAdditionsDir));
     243    system($perl, $combineResourcesCmd,
     244        '--input-dir', 'WebKitAdditions',
     245        '--input-html', $derivedSourcesMainHTML,
     246        '--input-html-dir', $rootPathForRelativeIncludes,
     247        '--derived-sources-dir', $derivedSourcesDir,
     248        '--output-dir', $derivedSourcesDir,
     249        '--output-script-name', 'WebKitAdditions.js',
     250        '--output-style-name', 'WebKitAdditions.css');
     251
     252    # Export the license into WebKitAdditions files.
     253    my $targetWebKitAdditionsJS = File::Spec->catfile($targetResourcePath, 'WebKitAdditions.js');
     254    seedFile($targetWebKitAdditionsJS, $inspectorLicense);
     255
     256    my $targetWebKitAdditionsCSS = File::Spec->catfile($targetResourcePath, 'WebKitAdditions.css');
     257    seedFile($targetWebKitAdditionsCSS, $inspectorLicense);
     258
     259    appendFile($targetWebKitAdditionsJS, File::Spec->catfile($derivedSourcesDir, 'WebKitAdditions.js'));
     260    appendFile($targetWebKitAdditionsCSS, File::Spec->catfile($derivedSourcesDir, 'WebKitAdditions.css'));
     261}
     262
    184263if ($shouldCombineMain) {
    185264    # Remove Debug JavaScript and CSS files in Production builds.
    186265    system($perl, $combineResourcesCmd,
    187266        '--input-dir', 'Debug',
    188         '--input-html', File::Spec->catfile($uiRoot, 'Main.html'),
     267        '--input-html', $derivedSourcesMainHTML,
    189268        '--input-html-dir', $uiRoot,
    190269        '--derived-sources-dir', $derivedSourcesDir,
     
    195274
    196275    # Combine the JavaScript and CSS files in Production builds into single files (Main.js and Main.css).
    197     my $derivedSourcesMainHTML = File::Spec->catfile($derivedSourcesDir, 'Main.html');
    198276    system($perl, $combineResourcesCmd,
    199277       '--input-html', $derivedSourcesMainHTML,
     
    203281       '--output-script-name', 'Main.js',
    204282       '--output-style-name', 'Main.css');
     283
     284    # Process WebKitAdditions.{css,js} after Main.{js,css}. Otherwise, the combined WebKitAdditions files
     285    # will get slurped into Main.{js,css} because the 'WebKitAdditions' relative URL prefix will be removed.
     286    combineOrStripResourcesForWebKitAdditions();
    205287
    206288    # Combine the CodeMirror JavaScript and CSS files in Production builds into single files (CodeMirror.js and CodeMirror.css).
     
    309391    system(qq("$python" "$jsMinScript" < "$derivedSourcesThreejsJS" >> "$targetThreejsJS")) and die "Failed to minify $derivedSourcesThreejsJS: $!";
    310392
    311     # Copy over Main.html and the Images directory.
    312     copy($derivedSourcesMainHTML, File::Spec->catfile($targetResourcePath, 'Main.html'));
    313 
     393    # Copy over the Images directory.
    314394    ditto(File::Spec->catdir($uiRoot, 'Images'), File::Spec->catdir($targetResourcePath, 'Images'));
    315395
     
    329409        '--input-directory', $workersDir) and die "Failed to update Worker imports for optimized builds.";
    330410} else {
    331     # Keep the files separate for engineering builds.
    332     ditto($uiRoot, $targetResourcePath);
    333 }
     411    # Always process WebKitAdditions files because the 'WebKitAdditions' path prefix is not real,
     412    # so it can't proceed as a normal load from the bundle as written. This function replaces the
     413    # dummy prefix with the actual WebKitAdditions path when looking for files to inline and combine.
     414    combineOrStripResourcesForWebKitAdditions();
     415}
     416
     417# Always copy over Main.html because we may have combined WebKitAdditions files
     418# without minifying anything else. We always want to combine WKA so the relevant
     419# resources are copied out of Derived Sources rather than an arbitrary WKA directory.
     420copy($derivedSourcesMainHTML, File::Spec->catfile($targetResourcePath, 'Main.html'));
    334421
    335422if ($shouldCombineTest) {
  • trunk/Source/WebInspectorUI/UserInterface/Main.html

    r229443 r229932  
    241241    <link rel="stylesheet" href="Debug/DebugContentView.css">
    242242
     243    <link rel="stylesheet" href="WebKitAdditions/WebInspectorUI/WebInspectorUIAdditions.css">
     244
    243245    <script src="Debug/UncaughtExceptionReporter.js"></script>
    244246
     
    868870    <script src="Debug/DebugContentView.js"></script>
    869871
     872    <script src="WebKitAdditions/WebInspectorUI/WebInspectorUIAdditions.js"></script>
     873
    870874    <script>
    871875        WI.sharedApp = new WI.AppController;
Note: See TracChangeset for help on using the changeset viewer.