diff options
Diffstat (limited to 'utils/llvm-build/llvmbuild/componentinfo.py')
-rw-r--r-- | utils/llvm-build/llvmbuild/componentinfo.py | 93 |
1 files changed, 50 insertions, 43 deletions
diff --git a/utils/llvm-build/llvmbuild/componentinfo.py b/utils/llvm-build/llvmbuild/componentinfo.py index e684ac2b7d21c..eda3a48811d64 100644 --- a/utils/llvm-build/llvmbuild/componentinfo.py +++ b/utils/llvm-build/llvmbuild/componentinfo.py @@ -2,11 +2,14 @@ Descriptor objects for entities that are part of the LLVM project. """ -import ConfigParser -import StringIO +from __future__ import absolute_import +try: + import configparser +except: + import ConfigParser as configparser import sys -from util import * +from llvmbuild.util import * class ParseError(Exception): pass @@ -29,7 +32,7 @@ class ComponentInfo(object): def __init__(self, subpath, name, dependencies, parent): if not subpath.startswith('/'): - raise ValueError,"invalid subpath: %r" % subpath + raise ValueError("invalid subpath: %r" % subpath) self.subpath = subpath self.name = name self.dependencies = list(dependencies) @@ -100,11 +103,11 @@ class GroupComponentInfo(ComponentInfo): 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() + return """\ +type = %s +name = %s +parent = %s +""" % (self.type_name, self.name, self.parent) class LibraryComponentInfo(ComponentInfo): type_name = 'Library' @@ -152,21 +155,22 @@ class LibraryComponentInfo(ComponentInfo): 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 + result = """\ +type = %s +name = %s +parent = %s +""" % (self.type_name, self.name, self.parent) if self.library_name is not None: - print >>result, 'library_name = %s' % self.library_name + result += 'library_name = %s\n' % self.library_name if self.required_libraries: - print >>result, 'required_libraries = %s' % ' '.join( + result += 'required_libraries = %s\n' % ' '.join( self.required_libraries) if self.add_to_library_groups: - print >>result, 'add_to_library_groups = %s' % ' '.join( + result += 'add_to_library_groups = %s\n' % ' '.join( self.add_to_library_groups) if not self.installed: - print >>result, 'installed = 0' - return result.getvalue() + result += 'installed = 0\n' + return result def get_library_name(self): return self.library_name or self.name @@ -237,17 +241,18 @@ class LibraryGroupComponentInfo(ComponentInfo): 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 + result = """\ +type = %s +name = %s +parent = %s +""" % (self.type_name, self.name, self.parent) if self.required_libraries and not self._is_special_group: - print >>result, 'required_libraries = %s' % ' '.join( + result += 'required_libraries = %s\n' % ' '.join( self.required_libraries) if self.add_to_library_groups: - print >>result, 'add_to_library_groups = %s' % ' '.join( + result += 'add_to_library_groups = %s\n' % ' '.join( self.add_to_library_groups) - return result.getvalue() + return result def get_llvmconfig_component_name(self): return self.name.lower() @@ -309,21 +314,22 @@ class TargetGroupComponentInfo(ComponentInfo): 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 + result = """\ +type = %s +name = %s +parent = %s +""" % (self.type_name, self.name, self.parent) if self.required_libraries: - print >>result, 'required_libraries = %s' % ' '.join( + result += 'required_libraries = %s\n' % ' '.join( self.required_libraries) if self.add_to_library_groups: - print >>result, 'add_to_library_groups = %s' % ' '.join( + result += 'add_to_library_groups = %s\n' % ' '.join( self.add_to_library_groups) for bool_key in ('has_asmparser', 'has_asmprinter', 'has_disassembler', 'has_jit'): if getattr(self, bool_key): - print >>result, '%s = 1' % (bool_key,) - return result.getvalue() + result += '%s = 1\n' % (bool_key,) + return result def get_llvmconfig_component_name(self): return self.name.lower() @@ -352,13 +358,13 @@ class ToolComponentInfo(ComponentInfo): 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() + return """\ +type = %s +name = %s +parent = %s +required_libraries = %s +""" % (self.type_name, self.name, self.parent, + ' '.join(self.required_libraries)) class BuildToolComponentInfo(ToolComponentInfo): type_name = 'BuildTool' @@ -418,7 +424,7 @@ _component_type_map = dict( TargetGroupComponentInfo, OptionalLibraryComponentInfo)) def load_from_path(path, subpath): # Load the LLVMBuild.txt file as an .ini format file. - parser = ConfigParser.RawConfigParser() + parser = configparser.RawConfigParser() parser.read(path) # Extract the common section. @@ -459,8 +465,9 @@ def _read_components_from_parser(parser, path, subpath): section, path, "unable to instantiate: %r" % type_name) import traceback traceback.print_exc() - raise SystemExit, 1 - except ParseError,e: + raise SystemExit(1) + except ParseError: + e = sys.exc_info()[1] fatal("unable to load component %r in %r: %s" % ( section, path, e.message)) |