[llvm-commits] [llvm] r143626 - in /llvm/trunk/utils/llvm-build/llvmbuild: componentinfo.py main.py

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


Author: ddunbar
Date: Thu Nov  3 12:56:21 2011
New Revision: 143626

URL: http://llvm.org/viewvc/llvm-project?rev=143626&view=rev
Log:
llvm-build: Add --write-llvmbuild option, which writes out the component tree.
 - Useful for migrating or auto-upgrading the format schema.

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

Modified: llvm/trunk/utils/llvm-build/llvmbuild/componentinfo.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/llvm-build/llvmbuild/componentinfo.py?rev=143626&r1=143625&r2=143626&view=diff
==============================================================================
--- llvm/trunk/utils/llvm-build/llvmbuild/componentinfo.py (original)
+++ llvm/trunk/utils/llvm-build/llvmbuild/componentinfo.py Thu Nov  3 12:56:21 2011
@@ -3,6 +3,7 @@
 """
 
 import ConfigParser
+import StringIO
 import sys
 
 from util import *
@@ -57,6 +58,9 @@
         for r in self.dependencies:
             yield ('dependency', r)
 
+    def get_llvmbuild_fragment(self):
+        abstract
+
 class GroupComponentInfo(ComponentInfo):
     """
     Group components have no semantics as far as the build system are concerned,
@@ -73,13 +77,20 @@
     def __init__(self, subpath, name, parent):
         ComponentInfo.__init__(self, subpath, name, [], parent)
 
+    def get_llvmbuild_fragment(self):
+        result = StringIO.StringIO()
+        print >>result, 'type = %s' % self.type_name
+        print >>result, 'name = %s' % self.name
+        print >>result, 'parent = %s' % self.parent
+        return result.getvalue()
+
 class LibraryComponentInfo(ComponentInfo):
     type_name = 'Library'
 
     @staticmethod
     def parse(subpath, items):
         kwargs = ComponentInfo.parse_items(items)
-        kwargs['library_name'] = items.get_optional_string('name')
+        kwargs['library_name'] = items.get_optional_string('library_name')
         kwargs['required_libraries'] = items.get_list('required_libraries')
         kwargs['add_to_library_groups'] = items.get_list(
             'add_to_library_groups')
@@ -109,6 +120,21 @@
         for r in self.add_to_library_groups:
             yield ('library group', r)
 
+    def get_llvmbuild_fragment(self):
+        result = StringIO.StringIO()
+        print >>result, 'type = %s' % self.type_name
+        print >>result, 'name = %s' % self.name
+        print >>result, 'parent = %s' % self.parent
+        if self.library_name is not None:
+            print >>result, 'library_name = %s' % self.library_name
+        if self.required_libraries:
+            print >>result, 'required_libraries = %s' % ' '.join(
+                self.required_libraries)
+        if self.add_to_library_groups:
+            print >>result, 'add_to_library_groups = %s' % ' '.join(
+                self.add_to_library_groups)
+        return result.getvalue()
+
 class LibraryGroupComponentInfo(ComponentInfo):
     type_name = 'LibraryGroup'
 
@@ -140,6 +166,19 @@
         for r in self.add_to_library_groups:
             yield ('library group', r)
 
+    def get_llvmbuild_fragment(self):
+        result = StringIO.StringIO()
+        print >>result, 'type = %s' % self.type_name
+        print >>result, 'name = %s' % self.name
+        print >>result, 'parent = %s' % self.parent
+        if self.required_libraries:
+            print >>result, 'required_libraries = %s' % ' '.join(
+                self.required_libraries)
+        if self.add_to_library_groups:
+            print >>result, 'add_to_library_groups = %s' % ' '.join(
+                self.add_to_library_groups)
+        return result.getvalue()
+
 class ToolComponentInfo(ComponentInfo):
     type_name = 'Tool'
 
@@ -163,6 +202,15 @@
         for r in self.required_libraries:
             yield ('required library', r)
 
+    def get_llvmbuild_fragment(self):
+        result = StringIO.StringIO()
+        print >>result, 'type = %s' % self.type_name
+        print >>result, 'name = %s' % self.name
+        print >>result, 'parent = %s' % self.parent
+        print >>result, 'required_libraries = %s' % ' '.join(
+            self.required_libraries)
+        return result.getvalue()
+
 class BuildToolComponentInfo(ToolComponentInfo):
     type_name = 'BuildTool'
 

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=143626&r1=143625&r2=143626&view=diff
==============================================================================
--- llvm/trunk/utils/llvm-build/llvmbuild/main.py (original)
+++ llvm/trunk/utils/llvm-build/llvmbuild/main.py Thu Nov  3 12:56:21 2011
@@ -126,6 +126,44 @@
                 visit(c, depth + 1)
         visit(self.component_info_map['$ROOT'])
 
+    def write_components(self, output_path):
+        # Organize all the components by the directory their LLVMBuild file
+        # should go in.
+        info_basedir = {}
+        for ci in self.component_infos:
+            # Ignore the $ROOT component.
+            if ci.parent is None:
+                continue
+
+            info_basedir[ci.subpath] = info_basedir.get(ci.subpath, []) + [ci]
+
+        # Generate the build files.
+        for subpath, infos in info_basedir.items():
+            # Order the components by name to have a canonical ordering.
+            infos.sort(key = lambda ci: ci.name)
+
+            # Format the components into llvmbuild fragments.
+            fragments = filter(None, [ci.get_llvmbuild_fragment()
+                                      for ci in infos])
+            if not fragments:
+                continue
+
+            assert subpath.startswith('/')
+            directory_path = os.path.join(output_path, subpath[1:])
+
+            # Create the directory if it does not already exist.
+            if not os.path.exists(directory_path):
+                os.makedirs(directory_path)
+
+            # Create the LLVMBuild file.
+            file_path = os.path.join(directory_path, 'LLVMBuild.txt')
+            f = open(file_path, "w")
+            for i,fragment in enumerate(fragments):
+                print >>f, '[component_%d]' % i
+                f.write(fragment)
+                print >>f
+            f.close()
+
 def main():
     from optparse import OptionParser, OptionGroup
     parser = OptionParser("usage: %prog [options]")
@@ -135,6 +173,9 @@
     parser.add_option("", "--print-tree", dest="print_tree",
                       help="Print out the project component tree [%default]",
                       action="store_true", default=False)
+    parser.add_option("", "--write-llvmbuild", dest="write_llvmbuild",
+                      help="Write out the LLVMBuild.txt files to PATH",
+                      action="store", default=None, metavar="PATH")
     parser.add_option(
         "", "--llvmbuild-source-root", dest="llvmbuild_source_root",
         help="If given, an alternate path to search for LLVMBuild.txt files",
@@ -165,5 +206,10 @@
     if opts.print_tree:
         project_info.print_tree()
 
+    # Write out the components, if requested. This is useful for auto-upgrading
+    # the schema.
+    if opts.write_llvmbuild:
+        project_info.write_components(opts.write_llvmbuild)
+
 if __name__=='__main__':
     main()





More information about the llvm-commits mailing list