2011-04-27 Tony Chang <tony@chromium.org>
authortony@chromium.org <tony@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Apr 2011 18:58:07 +0000 (18:58 +0000)
committertony@chromium.org <tony@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Apr 2011 18:58:07 +0000 (18:58 +0000)
        Reviewed by Ojan Vafai.

        [chromium] add a build target to make a zip file with the inspector debug files
        https://bugs.webkit.org/show_bug.cgi?id=56656

        * WebKit.gyp: Add target
        * scripts/concatenate_css_files.py: Pass in a string of html rather
            than a filename
        * scripts/concatenate_js_files.py: Same as above
        * scripts/generate_devtools_html.py: Refactor main into a helper function
        * scripts/generate_devtools_zip.py: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@85071 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/WebKit.gyp
Source/WebKit/chromium/scripts/concatenate_css_files.py
Source/WebKit/chromium/scripts/concatenate_js_files.py
Source/WebKit/chromium/scripts/generate_devtools_html.py
Source/WebKit/chromium/scripts/generate_devtools_zip.py [new file with mode: 0644]

index 6f3eadeba020758a6e04b8625993f650eb36c1fe..45fc089385a08f632e1c350889abaf7ad751834a 100644 (file)
@@ -1,3 +1,17 @@
+2011-04-27  Tony Chang  <tony@chromium.org>
+
+        Reviewed by Ojan Vafai.
+
+        [chromium] add a build target to make a zip file with the inspector debug files
+        https://bugs.webkit.org/show_bug.cgi?id=56656
+
+        * WebKit.gyp: Add target
+        * scripts/concatenate_css_files.py: Pass in a string of html rather
+            than a filename
+        * scripts/concatenate_js_files.py: Same as above
+        * scripts/generate_devtools_html.py: Refactor main into a helper function
+        * scripts/generate_devtools_zip.py: Added.
+
 2011-04-27  Mihai Parparita  <mihaip@chromium.org>
 
         Reviewed by Eric Seidel.
index ed7729ab107ce6a9f02016f55bd6dc100ebcc3d0..b5880eef0b5d75566177b2bf1ef368df8bc9a94b 100644 (file)
                 'action': ['python', '<@(_script_name)', '<@(_input_pages)', '--images', '<@(_search_path)', '--output', '<@(_outputs)'],
             }],
         },
+        {
+            'target_name': 'generate_devtools_zip',
+            'type': 'none',
+            'dependencies': [
+                '../../WebCore/WebCore.gyp/WebCore.gyp:inspector_protocol_sources',
+            ],
+            'actions': [{
+                'action_name': 'generate_devtools_zip',
+                'script_name': 'scripts/generate_devtools_zip.py',
+                'inspector_html': '../../WebCore/inspector/front-end/inspector.html',
+                'inputs': [
+                    '<@(_script_name)',
+                    'scripts/generate_devtools_html.py',
+                    '<@(_inspector_html)',
+                    '<@(devtools_files)',
+                    '<@(webinspector_files)',
+                    '<(SHARED_INTERMEDIATE_DIR)/webcore/InspectorBackendStub.js',
+                    '<@(webinspector_image_files)',
+                    '<@(devtools_image_files)',
+                ],
+                'search_path': [
+                    '../../WebCore/inspector/front-end',
+                    'src/js',
+                    '<(SHARED_INTERMEDIATE_DIR)/webcore',
+                ],
+                'image_search_path': [
+                    '../../WebCore/inspector/front-end/Images',
+                    'src/js/Images',
+                ],
+                'outputs': ['<(PRODUCT_DIR)/devtools_frontend.zip'],
+                'action': ['python', '<@(_script_name)', '<@(_inspector_html)',
+                                     '--devtools-files', '<@(devtools_files)',
+                                     '--search-path', '<@(_search_path)',
+                                     '--image-search-path', '<@(_image_search_path)',
+                                     '--output', '<@(_outputs)'],
+            }],
+        },
         {
             'target_name': 'webkit_unit_tests',
             'type': 'executable',
index 0aa5ef30a640d6f96f01c090d17e27acdaaffb3c..6281b3f5684120233f0ae29a5e5bbd091c99e7cb 100644 (file)
@@ -32,6 +32,8 @@
 # This script concatenates in place CSS files in the order specified
 # using <link> tags in a given 'order.html' file.
 
+from __future__ import with_statement
+
 from HTMLParser import HTMLParser
 from cStringIO import StringIO
 import os.path
@@ -40,11 +42,10 @@ import sys
 
 class OrderedCSSFilesExtractor(HTMLParser):
 
-    def __init__(self, order_html_name):
+    def __init__(self, order_html):
         HTMLParser.__init__(self)
         self.ordered_css_files = []
-        order_html = open(order_html_name, 'r')
-        self.feed(order_html.read())
+        self.feed(order_html)
 
     def handle_starttag(self, tag, attrs):
         if tag == 'link':
@@ -82,7 +83,8 @@ def main(argv):
 
     output_file_name = argv.pop()
     input_order_file_name = argv[1]
-    extractor = OrderedCSSFilesExtractor(input_order_file_name)
+    with open(input_order_file_name, 'r') as order_html:
+        extractor = OrderedCSSFilesExtractor(order_html.read())
     # Unconditionally append devTools.css. It will contain concatenated files.
     extractor.ordered_css_files.append('devTools.css')
 
index 209660a10d313a6d3332392a5f3e3b0bb06c2614..0eb965267cda040656445c04035079a02c96e50a 100644 (file)
@@ -32,6 +32,8 @@
 # This script concatenates in place JS files in the order specified
 # using <script> tags in a given 'order.html' file.
 
+from __future__ import with_statement
+
 from HTMLParser import HTMLParser
 from cStringIO import StringIO
 
@@ -42,11 +44,10 @@ import sys
 
 class OrderedJSFilesExtractor(HTMLParser):
 
-    def __init__(self, order_html_name):
+    def __init__(self, order_html):
         HTMLParser.__init__(self)
         self.ordered_js_files = []
-        order_html = open(order_html_name, 'r')
-        self.feed(order_html.read())
+        self.feed(order_html)
 
     def handle_starttag(self, tag, attrs):
         if tag == 'script':
@@ -83,7 +84,8 @@ def main(argv):
 
     output_file_name = argv.pop()
     input_order_file_name = argv[1]
-    extractor = OrderedJSFilesExtractor(input_order_file_name)
+    with open(input_order_file_name, 'r') as order_html:
+        extractor = OrderedJSFilesExtractor(order_html.read())
     extractor.ordered_js_files.append('DevTools.js')
     extractor.ordered_js_files.append('Tests.js')
 
index b8eab099d8fbe2f5aae3cf2e62a52a1edb5d9198..66255a84ceb0a84c31daf2f4d15409bad7dfa980 100644 (file)
@@ -33,7 +33,7 @@ import os.path
 import sys
 
 
-def GenerateIncludeTag(resource_path):
+def generate_include_tag(resource_path):
     (dir_name, file_name) = os.path.split(resource_path)
     if (file_name.endswith('.js')):
         return '    <script type="text/javascript" src="%s"></script>\n' % file_name
@@ -43,6 +43,22 @@ def GenerateIncludeTag(resource_path):
         assert resource_path
 
 
+def write_devtools_html(inspector_file, devtools_file, debug, debug_files):
+    for line in inspector_file:
+        if not debug and '<script ' in line:
+            continue
+        if not debug and '<link ' in line:
+            continue
+        if '</head>' in line:
+            if debug:
+                for resource in debug_files:
+                    devtools_file.write(generate_include_tag(resource))
+            else:
+                devtools_file.write(generate_include_tag("devTools.css"))
+                devtools_file.write(generate_include_tag("DevTools.js"))
+        devtools_file.write(line)
+
+
 def main(argv):
 
     if len(argv) < 4:
@@ -59,19 +75,7 @@ def main(argv):
     inspector_html = open(inspector_html_name, 'r')
     devtools_html = open(devtools_html_name, 'w')
 
-    for line in inspector_html:
-        if not debug and '<script ' in line:
-            continue
-        if not debug and '<link ' in line:
-            continue
-        if '</head>' in line:
-            if debug:
-                for resource in argv[4:]:
-                    devtools_html.write(GenerateIncludeTag(resource))
-            else:
-                devtools_html.write(GenerateIncludeTag("devTools.css"))
-                devtools_html.write(GenerateIncludeTag("DevTools.js"))
-        devtools_html.write(line)
+    write_devtools_html(inspector_html, devtools_html, debug, argv[4:])
 
     devtools_html.close()
     inspector_html.close()
diff --git a/Source/WebKit/chromium/scripts/generate_devtools_zip.py b/Source/WebKit/chromium/scripts/generate_devtools_zip.py
new file mode 100644 (file)
index 0000000..736da05
--- /dev/null
@@ -0,0 +1,114 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2011 Google 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:
+#
+#         * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#         * 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.
+#         * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
+# OWNER OR 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.
+
+"""Creates a zip file containing the web inspector files for debugging.
+
+The zip file contains all the .html, .js, .css and image files used by the
+web inspector.  The js files and css files are not concatenated and are not
+minified."""
+
+from __future__ import with_statement
+
+import os
+import StringIO
+import sys
+import zipfile
+
+import concatenate_css_files
+import concatenate_js_files
+import generate_devtools_html
+
+
+class ParsedArgs:
+    def __init__(self, inspector_html, devtools_files, search_dirs,
+                 image_search_dirs, output_filename):
+        self.inspector_html = inspector_html
+        self.devtools_files = devtools_files
+        self.search_dirs = search_dirs
+        self.image_search_dirs = image_search_dirs
+        self.output_filename = output_filename
+
+
+def parse_args(argv):
+    inspector_html = argv[0]
+
+    devtools_files_position = argv.index('--devtools-files')
+    search_path_position = argv.index('--search-path')
+    image_search_path_position = argv.index('--image-search-path')
+    output_position = argv.index('--output')
+
+    devtools_files = argv[devtools_files_position + 1:search_path_position]
+    search_dirs = argv[search_path_position + 1:image_search_path_position]
+    image_search_dirs = argv[image_search_path_position + 1:output_position]
+
+    return ParsedArgs(inspector_html, devtools_files, search_dirs,
+                      image_search_dirs, argv[output_position + 1])
+
+
+def main(argv):
+    parsed_args = parse_args(argv[1:])
+
+    devtools_html = StringIO.StringIO()
+    with open(parsed_args.inspector_html, 'r') as inspector_file:
+        generate_devtools_html.write_devtools_html(
+            inspector_file, devtools_html, True, parsed_args.devtools_files)
+
+    zip = zipfile.ZipFile(parsed_args.output_filename, 'w', zipfile.ZIP_DEFLATED)
+    zip.writestr("devtools.html", devtools_html.getvalue())
+
+    css_extractor = concatenate_css_files.OrderedCSSFilesExtractor(
+        devtools_html.getvalue())
+    js_extractor = concatenate_js_files.OrderedJSFilesExtractor(
+        devtools_html.getvalue())
+
+    expander = concatenate_css_files.PathExpander(parsed_args.search_dirs)
+    files = css_extractor.ordered_css_files + js_extractor.ordered_js_files
+    for input_file_name in set(files):
+        full_path = expander.expand(input_file_name)
+        if full_path is None:
+            raise Exception('File %s referenced in %s not found on any source paths, '
+                            'check source tree for consistency' %
+                            (input_file_name, 'devtools.html'))
+        zip.write(full_path, os.path.basename(full_path))
+
+    for dirname in parsed_args.image_search_dirs:
+        for filename in os.listdir(dirname):
+            if not filename.endswith('.png') and not filename.endswith('.gif'):
+                continue
+            zip.write(os.path.join(dirname, filename),
+                      os.path.join('Images', filename))
+
+    # It would be nice to use the with statement to scope closing the archive,
+    # but that wasn't added until python 2.7.
+    zip.close()
+
+
+if '__main__' == __name__:
+    sys.exit(main(sys.argv))