summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-16 05:54:23 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-16 05:54:23 +0000
commitc60d64ec89c1a8eb5279c38c101ec710c8d931f9 (patch)
treed3762b72e8ab249de8dda80b3bc58650c624062a /chrome/common/extensions
parent3a93fe6ea75c6be28fc160098248484e8ef627bf (diff)
downloadchromium_src-c60d64ec89c1a8eb5279c38c101ec710c8d931f9.zip
chromium_src-c60d64ec89c1a8eb5279c38c101ec710c8d931f9.tar.gz
chromium_src-c60d64ec89c1a8eb5279c38c101ec710c8d931f9.tar.bz2
Speed up docs generation. This take it from about 50s to 10s on my machine.
BUG=49129 Review URL: http://codereview.chromium.org/2845043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52616 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions')
-rwxr-xr-xchrome/common/extensions/docs/build/build.py132
-rw-r--r--chrome/common/extensions/docs/build/generator.html44
2 files changed, 99 insertions, 77 deletions
diff --git a/chrome/common/extensions/docs/build/build.py b/chrome/common/extensions/docs/build/build.py
index e073a01..02259ed 100755
--- a/chrome/common/extensions/docs/build/build.py
+++ b/chrome/common/extensions/docs/build/build.py
@@ -28,8 +28,8 @@ _api_template_html = _template_dir + "/api_template.html"
_page_shell_html = _template_dir + "/page_shell.html"
_generator_html = _build_dir + "/generator.html"
-_expected_output_preamble = "<!DOCTYPE html>"
-_expected_output_postamble = "</body></html>"
+_expected_output_preamble = "#BEGIN"
+_expected_output_postamble = "#END"
# HACK! This is required because we can only depend on python 2.4 and
# the calling environment may not be setup to set the PYTHONPATH
@@ -37,62 +37,72 @@ sys.path.append(os.path.normpath(_base_dir +
"/../../../../third_party"))
import simplejson as json
-def RenderPage(name, test_shell):
+def RenderPages(names, test_shell):
"""
- Calls test_shell --layout-tests .../generator.html?<name> and writes the
- result to .../docs/<name>.html
+ Calls test_shell --layout-tests .../generator.html?<names> and writes the
+ results to .../docs/<name>.html
"""
- if not name:
- raise Exception("RenderPage called with empty name")
+ if not names:
+ raise Exception("RenderPage called with empty names param")
- generator_url = "file:" + urllib.pathname2url(_generator_html) + "?" + name
- input_file = _base_dir + "/" + name + ".html"
+ generator_url = "file:" + urllib.pathname2url(_generator_html)
+ generator_url += "?" + ",".join(names)
- # Copy page_shell to destination output and move aside original, if it exists.
- original = None
- if (os.path.isfile(input_file)):
- original = open(input_file, 'rb').read()
- os.remove(input_file)
+ # Start with a fresh copy of page shell for each file.
+ # Save the current contents so that we can look for changes later.
+ originals = {}
+ for name in names:
+ input_file = _base_dir + "/" + name + ".html"
+
+ if (os.path.isfile(input_file)):
+ originals[name] = open(input_file, 'rb').read()
+ os.remove(input_file)
+ else:
+ originals[name] = ""
- shutil.copy(_page_shell_html, input_file)
+ shutil.copy(_page_shell_html, input_file)
# Run test_shell and capture result
- p = Popen([test_shell, "--layout-tests", generator_url],
+ p = Popen(
+ [test_shell, "--layout-tests", "--time-out-ms=30000", generator_url],
stdout=PIPE)
- # The remaining output will be the content of the generated page.
- result = p.stdout.read()
-
- content_start = result.find(_expected_output_preamble)
- content_end = result.find(_expected_output_postamble)
- if (content_start < 0):
- if (result.startswith("#TEST_TIMED_OUT")):
- raise Exception("test_shell returned TEST_TIMED_OUT.\n" +
- "Their was probably a problem with generating the " +
- "page\n" +
- "Try copying template/page_shell.html to:\n" +
- input_file +
- "\nAnd open it in chrome using the file: scheme.\n" +
- "Look from javascript errors via the inspector.")
- raise Exception("test_shell returned unexpected output: " + result)
- postamble_length = len(_expected_output_postamble)
- result = result[content_start:content_end + postamble_length] + "\n"
-
- # Remove the trailing #EOF that test shell appends to the output.
- result = result.replace('#EOF', '')
-
- # Remove page_shell
- os.remove(input_file)
-
- # Remove CRs that are appearing from captured test_shell output.
- result = result.replace('\r', '')
-
- # Write output
- open(input_file, 'wb').write(result)
- if (original and result == original):
- return None
- else:
- return input_file
+ # The remaining output will be the content of the generated pages.
+ output = p.stdout.read()
+
+ # Parse out just the JSON part.
+ begin = output.find(_expected_output_preamble)
+ end = output.rfind(_expected_output_postamble)
+
+ if (begin < 0 or end < 0):
+ raise Exception ("test_shell returned invalid output:\n\n" + output)
+
+ begin += len(_expected_output_preamble)
+
+ try:
+ output_parsed = json.loads(output[begin:end])
+ except ValueError, msg:
+ raise Exception("Could not parse test_shell output as JSON. Error: " + msg +
+ "\n\nOutput was:\n" + output)
+
+ changed_files = []
+ for name in names:
+ result = output_parsed[name].encode("utf8") + '\n'
+
+ # Remove CRs that are appearing from captured test_shell output.
+ result = result.replace('\r', '')
+
+ # Remove page_shell
+ input_file = _base_dir + "/" + name + ".html"
+ os.remove(input_file)
+
+ # Write output
+ open(input_file, 'wb').write(result)
+ if (originals[name] and result != originals[name]):
+ changed_files.append(input_file)
+
+ return changed_files
+
def FindTestShell():
# This is hacky. It is used to guess the location of the test_shell
@@ -103,23 +113,23 @@ def FindTestShell():
if (sys.platform in ('cygwin', 'win32')):
home_dir = os.path.normpath(os.getenv("HOMEDRIVE") + os.getenv("HOMEPATH"))
- search_locations.append(chrome_dir + "/Debug/test_shell.exe")
search_locations.append(chrome_dir + "/Release/test_shell.exe")
+ search_locations.append(chrome_dir + "/Debug/test_shell.exe")
search_locations.append(home_dir + "/bin/test_shell/" +
"test_shell.exe")
if (sys.platform in ('linux', 'linux2')):
- search_locations.append(src_dir + "/sconsbuild/Debug/test_shell")
- search_locations.append(src_dir + "/out/Debug/test_shell")
search_locations.append(src_dir + "/sconsbuild/Release/test_shell")
search_locations.append(src_dir + "/out/Release/test_shell")
+ search_locations.append(src_dir + "/sconsbuild/Debug/test_shell")
+ search_locations.append(src_dir + "/out/Debug/test_shell")
search_locations.append(os.getenv("HOME") + "/bin/test_shell/test_shell")
if (sys.platform == 'darwin'):
search_locations.append(src_dir +
- "/xcodebuild/Debug/TestShell.app/Contents/MacOS/TestShell")
- search_locations.append(src_dir +
"/xcodebuild/Release/TestShell.app/Contents/MacOS/TestShell")
+ search_locations.append(src_dir +
+ "/xcodebuild/Debug/TestShell.app/Contents/MacOS/TestShell")
search_locations.append(os.getenv("HOME") + "/bin/test_shell/" +
"TestShell.app/Contents/MacOS/TestShell")
@@ -127,10 +137,10 @@ def FindTestShell():
if os.path.isfile(loc):
return loc
- raise Exception ("Could not find test_shell executable\n" +
- "**test_shell may need to be built**\n" +
- "Searched: \n" + "\n".join(search_locations) + "\n" +
- "To specify a path to test_shell use --test-shell-path")
+ raise Exception("Could not find test_shell executable\n" +
+ "**test_shell may need to be built**\n" +
+ "Searched: \n" + "\n".join(search_locations) + "\n" +
+ "To specify a path to test_shell use --test-shell-path")
def GetAPIModuleNames():
try:
@@ -178,11 +188,7 @@ def main():
# All pages to generate
page_names = static_names | module_names
- modified_files = []
- for page in page_names:
- modified_file = RenderPage(page, test_shell)
- if (modified_file):
- modified_files.append(modified_file)
+ modified_files = RenderPages(page_names, test_shell)
if (len(modified_files) == 0):
print "Output files match existing files. No changes made."
diff --git a/chrome/common/extensions/docs/build/generator.html b/chrome/common/extensions/docs/build/generator.html
index eedebf8..0700d49 100644
--- a/chrome/common/extensions/docs/build/generator.html
+++ b/chrome/common/extensions/docs/build/generator.html
@@ -2,8 +2,11 @@
<head>
<script>
var childFrame;
+var pages;
+var currentPage;
+var result = {};
-function generate() {
+function init() {
if (!window.layoutTestController) {
alert("window.layoutTestController not defined.");
return;
@@ -12,28 +15,41 @@ function generate() {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
- var page = window.location.search.substring(1);
- if (!page) {
- alert("please specify which page to generate via " +
- "?<page> ... ie. generator.html?tabs");
+ pages = window.location.search.substring(1).split(",");
+ if (!pages.length) {
+ alert("please specify which pages to generate via " +
+ "?<page> ... ie. generator.html?tabs,bookmarks,cookies,...");
}
childFrame = document.createElement('iframe');
- childFrame.src = "../" + page + ".html?regenerate";
childFrame.style.display = "none";
document.body.appendChild(childFrame);
+
+ next();
}
+function next() {
+ currentPage = pages.shift();
+ childFrame.src = "../" + currentPage + ".html?regenerate";
+}
+
+var count = 0;
function done() {
- var preNode = document.createElement('pre');
- var textNode = document.createTextNode(
- childFrame.contentWindow.serializePage());
- preNode.appendChild(textNode);
- document.getElementsByTagName("body")[0].appendChild(preNode);
- layoutTestController.notifyDone();
+ result[currentPage] = childFrame.contentWindow.serializePage();
+
+ if (pages.length) {
+ next();
+ } else {
+ var preNode = document.createElement("pre");
+ var textNode = document.createTextNode(
+ "#BEGIN" + JSON.stringify(result) + "#END");
+ preNode.appendChild(textNode);
+ document.getElementsByTagName("body")[0].appendChild(preNode);
+ layoutTestController.notifyDone();
+ }
}
</script>
</head>
- <body onload="generate();">
+ <body onload="init();">
</body>
-</html> \ No newline at end of file
+</html>