[llvm-commits] [llvm] r143625 - /llvm/trunk/utils/llvm-build/llvmbuild/main.py

Daniel Dunbar daniel at zuster.org
Thu Nov 3 10:56:18 PDT 2011


Author: ddunbar
Date: Thu Nov  3 12:56:18 2011
New Revision: 143625

URL: http://llvm.org/viewvc/llvm-project?rev=143625&view=rev
Log:
llvm-build: Add --print-tree command line option.

Modified:
    llvm/trunk/utils/llvm-build/llvmbuild/main.py

Modified: llvm/trunk/utils/llvm-build/llvmbuild/main.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/llvm-build/llvmbuild/main.py?rev=143625&r1=143624&r2=143625&view=diff
==============================================================================
--- llvm/trunk/utils/llvm-build/llvmbuild/main.py (original)
+++ llvm/trunk/utils/llvm-build/llvmbuild/main.py Thu Nov  3 12:56:18 2011
@@ -54,11 +54,12 @@
                         ci.name, ci.subpath, existing.subpath))
             self.component_info_map[ci.name] = ci
 
-        # Add the root component, which does not go in any list.
+        # Add the root component.
         if '$ROOT' in self.component_info_map:
             fatal("project is not allowed to define $ROOT component")
         self.component_info_map['$ROOT'] = componentinfo.GroupComponentInfo(
             '/', '$ROOT', None)
+        self.component_infos.append(self.component_info_map['$ROOT'])
 
         # Topologically order the component information according to their
         # component references.
@@ -80,11 +81,12 @@
             components_to_visit.remove(ci)
 
             # Validate the parent reference, which we treat specially.
-            parent = self.component_info_map.get(ci.parent)
-            if parent is None:
-                fatal("component %r has invalid reference %r (via %r)" % (
-                        ci.name, ci.parent, 'parent'))
-            ci.set_parent_instance(parent)
+            if ci.parent is not None:
+                parent = self.component_info_map.get(ci.parent)
+                if parent is None:
+                    fatal("component %r has invalid reference %r (via %r)" % (
+                            ci.name, ci.parent, 'parent'))
+                ci.set_parent_instance(parent)
 
             for relation,referent_name in ci.get_component_references():
                 # Validate that the reference is ok.
@@ -113,12 +115,26 @@
         while components_to_visit:
             visit_component_info(iter(components_to_visit).next(), [], set())
 
+        # Canonicalize children lists.
+        for c in self.ordered_component_infos:
+            c.children.sort(key = lambda c: c.name)
+
+    def print_tree(self):
+        def visit(node, depth = 0):
+            print '%s%-40s (%s)' % ('  '*depth, node.name, node.type_name)
+            for c in node.children:
+                visit(c, depth + 1)
+        visit(self.component_info_map['$ROOT'])
+
 def main():
     from optparse import OptionParser, OptionGroup
     parser = OptionParser("usage: %prog [options]")
     parser.add_option("", "--source-root", dest="source_root", metavar="PATH",
                       help="Path to the LLVM source (inferred if not given)",
                       action="store", default=None)
+    parser.add_option("", "--print-tree", dest="print_tree",
+                      help="Print out the project component tree [%default]",
+                      action="store_true", default=False)
     parser.add_option(
         "", "--llvmbuild-source-root", dest="llvmbuild_source_root",
         help="If given, an alternate path to search for LLVMBuild.txt files",
@@ -145,5 +161,9 @@
     project_info = LLVMProjectInfo.load_from_path(
         source_root, llvmbuild_source_root)
 
+    # Print the component tree, if requested.
+    if opts.print_tree:
+        project_info.print_tree()
+
 if __name__=='__main__':
     main()





More information about the llvm-commits mailing list