1 #!/usr/bin/env python 2 # Copyright (c) 2010 Google Inc. All rights reserved. 3 # 4 # Redistribution and use in source and binary forms, with or without 5 # modification, are permitted provided that the following conditions are 6 # met: 7 # 8 # * Redistributions of source code must retain the above copyright 9 # notice, this list of conditions and the following disclaimer. 10 # * Redistributions in binary form must reproduce the above 11 # copyright notice, this list of conditions and the following disclaimer 12 # in the documentation and/or other materials provided with the 13 # distribution. 14 # * Neither the name of Google Inc. nor the names of its 15 # contributors may be used to endorse or promote products derived from 16 # this software without specific prior written permission. 17 # 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 # 30 # This is a very simple script designed to crawl the build directory 31 # for visual studio express build logs and print them to stdout. 32 33 from __future__ import with_statement 34 35 import codecs 36 import os 37 import re 38 39 from webkitpy.common.checkout import scm 40 from webkitpy.common.system.executive import Executive 41 from webkitpy.thirdparty import BeautifulSoup 42 43 44 class PrintVisualStudioExpressLogs(object): 45 def __init__(self): 46 self._executive = Executive() 47 48 def _find_buildlogs(self, build_directory): 49 build_log_paths = [] 50 for dirpath, dirnames, filenames in os.walk(build_directory): 51 for file_name in filenames: 52 if file_name == "BuildLog.htm": 53 file_path = os.path.join(dirpath, file_name) 54 build_log_paths.append(file_path) 55 return build_log_paths 56 57 def _build_order(self): 58 """Returns a list of project names in the order in which they are built.""" 59 script_path = os.path.join(self._scripts_directory(), "print-msvc-project-dependencies") 60 sln_path = os.path.join(scm.find_checkout_root(), "WebKit", "win", "WebKit.vcproj", "WebKit.sln") 61 lines = self._executive.run_command([script_path, sln_path]).splitlines() 62 order = [line.strip() for line in lines if line.find("Folder") == -1] 63 order.reverse() 64 return order 65 66 def _sort_buildlogs(self, log_paths): 67 build_order = self._build_order() 68 def sort_key(log_path): 69 project_name = os.path.basename(os.path.dirname(os.path.dirname(log_path))) 70 try: 71 index = build_order.index(project_name) 72 except ValueError: 73 # If the project isn't in the list, sort it after all items that 74 # are in the list. 75 index = len(build_order) 76 # Sort first by build order, then by project name 77 return (index, project_name) 78 return sorted(log_paths, key=sort_key) 79 80 def _obj_directory(self): 81 build_directory_script_path = os.path.join(self._scripts_directory(), "webkit-build-directory") 82 # FIXME: ports/webkit.py should provide the build directory in a nice API. 83 # NOTE: The windows VSE build does not seem to use different directories 84 # for Debug and Release. 85 build_directory = self._executive.run_command([build_directory_script_path, "--top-level"]).rstrip() 86 return os.path.join(build_directory, "obj") 87 88 def _scripts_directory(self): 89 return os.path.dirname(__file__) 90 91 def _relevant_text(self, log): 92 soup = BeautifulSoup.BeautifulSoup(log) 93 # The Output Window table is where the useful output starts in the build log. 94 output_window_table = soup.find(text=re.compile("Output Window")).findParent("table") 95 result = [] 96 for table in [output_window_table] + output_window_table.findNextSiblings("table"): 97 result.extend([text.replace(" ", "") for text in table.findAll(text=True)]) 98 result.append("\n") 99 return "".join(result) 100 101 def main(self): 102 build_log_paths = self._sort_buildlogs(self._find_buildlogs(self._obj_directory())) 103 104 print "Found %s Visual Studio Express Build Logs:\n%s" % (len(build_log_paths), "\n".join(build_log_paths)) 105 106 for build_log_path in build_log_paths: 107 print "%s:\n" % build_log_path 108 with codecs.open(build_log_path, "r", "utf-16") as build_log: 109 print self._relevant_text(build_log) 110 111 112 if __name__ == '__main__': 113 PrintVisualStudioExpressLogs().main() 114