+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.
'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',
# 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
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':
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')
# 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
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':
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')
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
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:
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()
--- /dev/null
+#!/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))