diff options
-rw-r--r-- | chrome/tools/build/win/dependencies.py | 6 | ||||
-rw-r--r-- | chrome/tools/build/win/sln_deps.py | 60 |
2 files changed, 50 insertions, 16 deletions
diff --git a/chrome/tools/build/win/dependencies.py b/chrome/tools/build/win/dependencies.py index 0ae3b8e..66b2cc7 100644 --- a/chrome/tools/build/win/dependencies.py +++ b/chrome/tools/build/win/dependencies.py @@ -97,13 +97,13 @@ def RunDumpbin(binary_file): if line == "Image has the following dependencies:": if current_section != START: raise Error("Internal parsing error.") - current_section = DEPENDENCIES_HEADER; + current_section = DEPENDENCIES_HEADER elif line == "Image has the following delay load dependencies:": if current_section != DEPENDENCIES: raise Error("Internal parsing error.") - current_section = DELAY_LOAD_HEADER; + current_section = DELAY_LOAD_HEADER elif line == "Summary": - current_section = SUMMARY_HEADER; + current_section = SUMMARY_HEADER elif current_section == DEPENDENCIES: # Got a dependent dependents.append(line) diff --git a/chrome/tools/build/win/sln_deps.py b/chrome/tools/build/win/sln_deps.py index a029240..0898a1e 100644 --- a/chrome/tools/build/win/sln_deps.py +++ b/chrome/tools/build/win/sln_deps.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/python # Copyright 2008, Google Inc. # All rights reserved. # @@ -28,7 +28,10 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import sys +import copy +import optparse + +__version__ = "1.0" # Constants used by Visual Studio. UNKNOWN_GUID = "{00000000-0000-0000-0000-000000000000}" @@ -47,14 +50,13 @@ class Project: return self.name -def main(filename, project_to_scan): - project_to_scan = project_to_scan.lower() +def ScanSlnFile(filename): + """Scan a Visual Studio .sln and extract the project dependencies.""" try: sln = open(filename, "r") except IOError: sys.stderr.write("Unable to open " + filename + " for reading.\n") return 1 - projects = {} project = None while 1: @@ -83,6 +85,26 @@ def main(filename, project_to_scan): # We are done parsing. sln.close() + return projects + + +def main(filename, project_to_scan, reverse): + """Displays the project's dependencies.""" + project_to_scan = project_to_scan.lower() + + projects = ScanSlnFile(filename) + + if reverse: + # Inverse the dependencies map so they are displayed in the reverse order. + # First, create a copy of the map. + projects_reversed = copy.deepcopy(projects) + for project_reversed in projects_reversed.itervalues(): + project_reversed.deps = [] + # Then, assign reverse dependencies. + for project in projects.itervalues(): + for dep in project.deps: + projects_reversed[dep].deps.append(project.guid) + projects = projects_reversed # Print the results. for project in projects.itervalues(): @@ -97,14 +119,26 @@ def main(filename, project_to_scan): if __name__ == '__main__': - if len(sys.argv) != 2 and len(sys.argv) != 3: - print """Usage: sln_deps.py <SOLUTIONNAME>.sln [project] - to display the dependencies of a project in human readable form. + usage = "usage: %prog [options] solution [project]" + + description = ("Display the dependencies of a project in human readable" + " form. [project] is optional. If omited, all projects are" + " listed.") - [project] is optional. If omited, all projects are listed.""" - sys.exit(1) + option_parser = optparse.OptionParser(usage = usage, + version="%prog " + __version__, + description = description) + option_parser.add_option("-r", + "--reverse", + dest="reverse", + action="store_true", + default=False, + help="Display the reverse dependencies") + options, args = option_parser.parse_args() + if len(args) != 1 and len(args) != 2: + option_parser.error("incorrect number of arguments") project_to_scan = "" - if len(sys.argv) == 3: - project_to_scan = sys.argv[2] - sys.exit(main(sys.argv[1], project_to_scan)) + if len(args) == 2: + project_to_scan = args[1] + main(args[0], project_to_scan, options.reverse) |