aboutsummaryrefslogtreecommitdiffstats
path: root/utils/llvm-build
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2011-11-03 17:56:21 +0000
committerDaniel Dunbar <daniel@zuster.org>2011-11-03 17:56:21 +0000
commit43120df44b629cc1ef0b587007bec5c31fb799a1 (patch)
tree0ea54a02345aab81bf4e42dae19b3b13c3d0c4f6 /utils/llvm-build
parent00b4b4f5cb95b5984174ac8086dcf878e2fa24e4 (diff)
downloadexternal_llvm-43120df44b629cc1ef0b587007bec5c31fb799a1.zip
external_llvm-43120df44b629cc1ef0b587007bec5c31fb799a1.tar.gz
external_llvm-43120df44b629cc1ef0b587007bec5c31fb799a1.tar.bz2
llvm-build: Add --write-llvmbuild option, which writes out the component tree.
- Useful for migrating or auto-upgrading the format schema. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@143626 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/llvm-build')
-rw-r--r--utils/llvm-build/llvmbuild/componentinfo.py50
-rw-r--r--utils/llvm-build/llvmbuild/main.py46
2 files changed, 95 insertions, 1 deletions
diff --git a/utils/llvm-build/llvmbuild/componentinfo.py b/utils/llvm-build/llvmbuild/componentinfo.py
index 30ec23b..3ea8001 100644
--- a/utils/llvm-build/llvmbuild/componentinfo.py
+++ b/utils/llvm-build/llvmbuild/componentinfo.py
@@ -3,6 +3,7 @@ Descriptor objects for entities that are part of the LLVM project.
"""
import ConfigParser
+import StringIO
import sys
from util import *
@@ -57,6 +58,9 @@ class ComponentInfo(object):
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 @@ class GroupComponentInfo(ComponentInfo):
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 @@ class LibraryComponentInfo(ComponentInfo):
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 @@ class LibraryGroupComponentInfo(ComponentInfo):
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 @@ class ToolComponentInfo(ComponentInfo):
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'
diff --git a/utils/llvm-build/llvmbuild/main.py b/utils/llvm-build/llvmbuild/main.py
index 7d9098e..16d8168 100644
--- a/utils/llvm-build/llvmbuild/main.py
+++ b/utils/llvm-build/llvmbuild/main.py
@@ -126,6 +126,44 @@ class LLVMProjectInfo(object):
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 @@ def main():
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 @@ def main():
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()