2011-11-04 01:56:06 +08:00
|
|
|
"""
|
|
|
|
Descriptor objects for entities that are part of the LLVM project.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import ConfigParser
|
2011-11-04 01:56:21 +08:00
|
|
|
import StringIO
|
2011-11-04 01:56:06 +08:00
|
|
|
import sys
|
|
|
|
|
2011-11-04 01:56:10 +08:00
|
|
|
from util import *
|
|
|
|
|
|
|
|
class ParseError(Exception):
|
|
|
|
pass
|
|
|
|
|
2011-11-04 01:56:06 +08:00
|
|
|
class ComponentInfo(object):
|
|
|
|
"""
|
|
|
|
Base class for component descriptions.
|
|
|
|
"""
|
|
|
|
|
|
|
|
type_name = None
|
|
|
|
|
2011-11-04 01:56:10 +08:00
|
|
|
@staticmethod
|
|
|
|
def parse_items(items, has_dependencies = True):
|
|
|
|
kwargs = {}
|
|
|
|
kwargs['name'] = items.get_string('name')
|
|
|
|
kwargs['parent'] = items.get_optional_string('parent')
|
|
|
|
if has_dependencies:
|
|
|
|
kwargs['dependencies'] = items.get_list('dependencies')
|
|
|
|
return kwargs
|
|
|
|
|
2011-11-04 01:56:06 +08:00
|
|
|
def __init__(self, subpath, name, dependencies, parent):
|
|
|
|
if not subpath.startswith('/'):
|
|
|
|
raise ValueError,"invalid subpath: %r" % subpath
|
|
|
|
self.subpath = subpath
|
|
|
|
self.name = name
|
|
|
|
self.dependencies = list(dependencies)
|
|
|
|
|
|
|
|
# The name of the parent component to logically group this component
|
|
|
|
# under.
|
|
|
|
self.parent = parent
|
|
|
|
|
2011-11-04 01:56:16 +08:00
|
|
|
# The parent instance, once loaded.
|
|
|
|
self.parent_instance = None
|
|
|
|
self.children = []
|
|
|
|
|
2011-12-13 06:45:35 +08:00
|
|
|
# The original source path.
|
|
|
|
self._source_path = None
|
|
|
|
|
2011-12-13 06:45:41 +08:00
|
|
|
# A flag to mark "special" components which have some amount of magic
|
|
|
|
# handling (generally based on command line options).
|
|
|
|
self._is_special_group = False
|
|
|
|
|
2011-11-04 01:56:16 +08:00
|
|
|
def set_parent_instance(self, parent):
|
|
|
|
assert parent.name == self.parent, "Unexpected parent!"
|
|
|
|
self.parent_instance = parent
|
|
|
|
self.parent_instance.children.append(self)
|
|
|
|
|
2011-11-04 01:56:12 +08:00
|
|
|
def get_component_references(self):
|
|
|
|
"""get_component_references() -> iter
|
|
|
|
|
|
|
|
Return an iterator over the named references to other components from
|
|
|
|
this object. Items are of the form (reference-type, component-name).
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Parent references are handled specially.
|
|
|
|
for r in self.dependencies:
|
|
|
|
yield ('dependency', r)
|
|
|
|
|
2011-11-04 01:56:21 +08:00
|
|
|
def get_llvmbuild_fragment(self):
|
|
|
|
abstract
|
|
|
|
|
2012-05-16 02:44:12 +08:00
|
|
|
def get_parent_target_group(self):
|
|
|
|
"""get_parent_target_group() -> ComponentInfo or None
|
|
|
|
|
|
|
|
Return the nearest parent target group (if any), or None if the
|
|
|
|
component is not part of any target group.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# If this is a target group, return it.
|
|
|
|
if self.type_name == 'TargetGroup':
|
|
|
|
return self
|
|
|
|
|
|
|
|
# Otherwise recurse on the parent, if any.
|
|
|
|
if self.parent_instance:
|
|
|
|
return self.parent_instance.get_parent_target_group()
|
|
|
|
|
2011-11-04 01:56:06 +08:00
|
|
|
class GroupComponentInfo(ComponentInfo):
|
|
|
|
"""
|
|
|
|
Group components have no semantics as far as the build system are concerned,
|
|
|
|
but exist to help organize other components into a logical tree structure.
|
|
|
|
"""
|
|
|
|
|
|
|
|
type_name = 'Group'
|
|
|
|
|
2011-11-04 01:56:10 +08:00
|
|
|
@staticmethod
|
|
|
|
def parse(subpath, items):
|
|
|
|
kwargs = ComponentInfo.parse_items(items, has_dependencies = False)
|
|
|
|
return GroupComponentInfo(subpath, **kwargs)
|
|
|
|
|
2011-11-04 01:56:06 +08:00
|
|
|
def __init__(self, subpath, name, parent):
|
|
|
|
ComponentInfo.__init__(self, subpath, name, [], parent)
|
|
|
|
|
2011-11-04 01:56:21 +08:00
|
|
|
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()
|
|
|
|
|
2011-11-04 01:56:06 +08:00
|
|
|
class LibraryComponentInfo(ComponentInfo):
|
|
|
|
type_name = 'Library'
|
|
|
|
|
2011-11-04 01:56:10 +08:00
|
|
|
@staticmethod
|
2012-05-08 03:38:40 +08:00
|
|
|
def parse_items(items):
|
2011-11-04 01:56:10 +08:00
|
|
|
kwargs = ComponentInfo.parse_items(items)
|
2011-11-04 01:56:21 +08:00
|
|
|
kwargs['library_name'] = items.get_optional_string('library_name')
|
2011-11-04 01:56:10 +08:00
|
|
|
kwargs['required_libraries'] = items.get_list('required_libraries')
|
|
|
|
kwargs['add_to_library_groups'] = items.get_list(
|
|
|
|
'add_to_library_groups')
|
2012-05-16 02:44:17 +08:00
|
|
|
kwargs['installed'] = items.get_optional_bool('installed', True)
|
2012-05-08 03:38:40 +08:00
|
|
|
return kwargs
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def parse(subpath, items):
|
|
|
|
kwargs = LibraryComponentInfo.parse_items(items)
|
2011-11-04 01:56:10 +08:00
|
|
|
return LibraryComponentInfo(subpath, **kwargs)
|
|
|
|
|
|
|
|
def __init__(self, subpath, name, dependencies, parent, library_name,
|
2012-05-16 02:44:17 +08:00
|
|
|
required_libraries, add_to_library_groups, installed):
|
2011-11-04 01:56:06 +08:00
|
|
|
ComponentInfo.__init__(self, subpath, name, dependencies, parent)
|
|
|
|
|
|
|
|
# If given, the name to use for the library instead of deriving it from
|
|
|
|
# the component name.
|
|
|
|
self.library_name = library_name
|
|
|
|
|
|
|
|
# The names of the library components which are required when linking
|
|
|
|
# with this component.
|
|
|
|
self.required_libraries = list(required_libraries)
|
|
|
|
|
|
|
|
# The names of the library group components this component should be
|
|
|
|
# considered part of.
|
|
|
|
self.add_to_library_groups = list(add_to_library_groups)
|
|
|
|
|
2012-05-16 02:44:17 +08:00
|
|
|
# Whether or not this library is installed.
|
|
|
|
self.installed = installed
|
|
|
|
|
2011-11-04 01:56:12 +08:00
|
|
|
def get_component_references(self):
|
|
|
|
for r in ComponentInfo.get_component_references(self):
|
|
|
|
yield r
|
|
|
|
for r in self.required_libraries:
|
|
|
|
yield ('required library', r)
|
|
|
|
for r in self.add_to_library_groups:
|
|
|
|
yield ('library group', r)
|
|
|
|
|
2011-11-04 01:56:21 +08:00
|
|
|
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)
|
2012-05-16 02:44:17 +08:00
|
|
|
if not self.installed:
|
|
|
|
print >>result, 'installed = 0'
|
2011-11-04 01:56:21 +08:00
|
|
|
return result.getvalue()
|
|
|
|
|
2011-11-04 01:56:28 +08:00
|
|
|
def get_library_name(self):
|
|
|
|
return self.library_name or self.name
|
|
|
|
|
2011-11-29 08:06:50 +08:00
|
|
|
def get_prefixed_library_name(self):
|
|
|
|
"""
|
|
|
|
get_prefixed_library_name() -> str
|
|
|
|
|
|
|
|
Return the library name prefixed by the project name. This is generally
|
|
|
|
what the library name will be on disk.
|
|
|
|
"""
|
|
|
|
|
|
|
|
basename = self.get_library_name()
|
|
|
|
|
|
|
|
# FIXME: We need to get the prefix information from an explicit project
|
|
|
|
# object, or something.
|
|
|
|
if basename in ('gtest', 'gtest_main'):
|
|
|
|
return basename
|
|
|
|
|
|
|
|
return 'LLVM%s' % basename
|
|
|
|
|
2011-11-04 01:56:28 +08:00
|
|
|
def get_llvmconfig_component_name(self):
|
|
|
|
return self.get_library_name().lower()
|
|
|
|
|
2012-05-08 03:38:40 +08:00
|
|
|
class OptionalLibraryComponentInfo(LibraryComponentInfo):
|
|
|
|
type_name = "OptionalLibrary"
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def parse(subpath, items):
|
|
|
|
kwargs = LibraryComponentInfo.parse_items(items)
|
|
|
|
return OptionalLibraryComponentInfo(subpath, **kwargs)
|
|
|
|
|
|
|
|
def __init__(self, subpath, name, dependencies, parent, library_name,
|
2012-05-16 02:44:17 +08:00
|
|
|
required_libraries, add_to_library_groups, installed):
|
2012-05-08 03:38:40 +08:00
|
|
|
LibraryComponentInfo.__init__(self, subpath, name, dependencies, parent,
|
|
|
|
library_name, required_libraries,
|
2012-05-16 02:44:17 +08:00
|
|
|
add_to_library_groups, installed)
|
2012-05-08 03:38:40 +08:00
|
|
|
|
2011-11-04 01:56:06 +08:00
|
|
|
class LibraryGroupComponentInfo(ComponentInfo):
|
|
|
|
type_name = 'LibraryGroup'
|
|
|
|
|
2011-11-04 01:56:10 +08:00
|
|
|
@staticmethod
|
|
|
|
def parse(subpath, items):
|
|
|
|
kwargs = ComponentInfo.parse_items(items, has_dependencies = False)
|
|
|
|
kwargs['required_libraries'] = items.get_list('required_libraries')
|
|
|
|
kwargs['add_to_library_groups'] = items.get_list(
|
|
|
|
'add_to_library_groups')
|
|
|
|
return LibraryGroupComponentInfo(subpath, **kwargs)
|
|
|
|
|
2011-11-04 01:56:06 +08:00
|
|
|
def __init__(self, subpath, name, parent, required_libraries = [],
|
|
|
|
add_to_library_groups = []):
|
|
|
|
ComponentInfo.__init__(self, subpath, name, [], parent)
|
|
|
|
|
|
|
|
# The names of the library components which are required when linking
|
|
|
|
# with this component.
|
|
|
|
self.required_libraries = list(required_libraries)
|
|
|
|
|
|
|
|
# The names of the library group components this component should be
|
|
|
|
# considered part of.
|
|
|
|
self.add_to_library_groups = list(add_to_library_groups)
|
|
|
|
|
2011-11-04 01:56:12 +08:00
|
|
|
def get_component_references(self):
|
|
|
|
for r in ComponentInfo.get_component_references(self):
|
|
|
|
yield r
|
|
|
|
for r in self.required_libraries:
|
|
|
|
yield ('required library', r)
|
|
|
|
for r in self.add_to_library_groups:
|
|
|
|
yield ('library group', r)
|
|
|
|
|
2011-11-04 01:56:21 +08:00
|
|
|
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
|
2011-12-13 06:45:41 +08:00
|
|
|
if self.required_libraries and not self._is_special_group:
|
2011-11-04 01:56:21 +08:00
|
|
|
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()
|
|
|
|
|
2011-11-04 01:56:28 +08:00
|
|
|
def get_llvmconfig_component_name(self):
|
|
|
|
return self.name.lower()
|
|
|
|
|
2011-11-10 08:49:51 +08:00
|
|
|
class TargetGroupComponentInfo(ComponentInfo):
|
|
|
|
type_name = 'TargetGroup'
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def parse(subpath, items):
|
|
|
|
kwargs = ComponentInfo.parse_items(items, has_dependencies = False)
|
|
|
|
kwargs['required_libraries'] = items.get_list('required_libraries')
|
|
|
|
kwargs['add_to_library_groups'] = items.get_list(
|
|
|
|
'add_to_library_groups')
|
|
|
|
kwargs['has_jit'] = items.get_optional_bool('has_jit', False)
|
2011-11-11 08:23:56 +08:00
|
|
|
kwargs['has_asmprinter'] = items.get_optional_bool('has_asmprinter',
|
|
|
|
False)
|
|
|
|
kwargs['has_asmparser'] = items.get_optional_bool('has_asmparser',
|
|
|
|
False)
|
|
|
|
kwargs['has_disassembler'] = items.get_optional_bool('has_disassembler',
|
|
|
|
False)
|
2011-11-10 08:49:51 +08:00
|
|
|
return TargetGroupComponentInfo(subpath, **kwargs)
|
|
|
|
|
|
|
|
def __init__(self, subpath, name, parent, required_libraries = [],
|
2011-11-11 08:23:56 +08:00
|
|
|
add_to_library_groups = [], has_jit = False,
|
|
|
|
has_asmprinter = False, has_asmparser = False,
|
|
|
|
has_disassembler = False):
|
2011-11-10 08:49:51 +08:00
|
|
|
ComponentInfo.__init__(self, subpath, name, [], parent)
|
|
|
|
|
|
|
|
# The names of the library components which are required when linking
|
|
|
|
# with this component.
|
|
|
|
self.required_libraries = list(required_libraries)
|
|
|
|
|
|
|
|
# The names of the library group components this component should be
|
|
|
|
# considered part of.
|
|
|
|
self.add_to_library_groups = list(add_to_library_groups)
|
|
|
|
|
|
|
|
# Whether or not this target supports the JIT.
|
|
|
|
self.has_jit = bool(has_jit)
|
|
|
|
|
2011-11-11 08:23:56 +08:00
|
|
|
# Whether or not this target defines an assembly printer.
|
|
|
|
self.has_asmprinter = bool(has_asmprinter)
|
|
|
|
|
|
|
|
# Whether or not this target defines an assembly parser.
|
|
|
|
self.has_asmparser = bool(has_asmparser)
|
|
|
|
|
|
|
|
# Whether or not this target defines an disassembler.
|
|
|
|
self.has_disassembler = bool(has_disassembler)
|
|
|
|
|
2011-11-10 08:50:07 +08:00
|
|
|
# Whether or not this target is enabled. This is set in response to
|
|
|
|
# configuration parameters.
|
|
|
|
self.enabled = False
|
|
|
|
|
2011-11-10 08:49:51 +08:00
|
|
|
def get_component_references(self):
|
|
|
|
for r in ComponentInfo.get_component_references(self):
|
|
|
|
yield r
|
|
|
|
for r in self.required_libraries:
|
|
|
|
yield ('required library', r)
|
|
|
|
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)
|
2011-11-11 08:23:56 +08:00
|
|
|
for bool_key in ('has_asmparser', 'has_asmprinter', 'has_disassembler',
|
|
|
|
'has_jit'):
|
|
|
|
if getattr(self, bool_key):
|
|
|
|
print >>result, '%s = 1' % (bool_key,)
|
2011-11-10 08:49:51 +08:00
|
|
|
return result.getvalue()
|
|
|
|
|
|
|
|
def get_llvmconfig_component_name(self):
|
|
|
|
return self.name.lower()
|
|
|
|
|
2011-11-04 01:56:06 +08:00
|
|
|
class ToolComponentInfo(ComponentInfo):
|
|
|
|
type_name = 'Tool'
|
|
|
|
|
2011-11-04 01:56:10 +08:00
|
|
|
@staticmethod
|
|
|
|
def parse(subpath, items):
|
|
|
|
kwargs = ComponentInfo.parse_items(items)
|
|
|
|
kwargs['required_libraries'] = items.get_list('required_libraries')
|
|
|
|
return ToolComponentInfo(subpath, **kwargs)
|
|
|
|
|
2011-11-04 01:56:06 +08:00
|
|
|
def __init__(self, subpath, name, dependencies, parent,
|
2011-11-04 01:56:10 +08:00
|
|
|
required_libraries):
|
2011-11-04 01:56:06 +08:00
|
|
|
ComponentInfo.__init__(self, subpath, name, dependencies, parent)
|
|
|
|
|
|
|
|
# The names of the library components which are required to link this
|
|
|
|
# tool.
|
|
|
|
self.required_libraries = list(required_libraries)
|
|
|
|
|
2011-11-04 01:56:12 +08:00
|
|
|
def get_component_references(self):
|
|
|
|
for r in ComponentInfo.get_component_references(self):
|
|
|
|
yield r
|
|
|
|
for r in self.required_libraries:
|
|
|
|
yield ('required library', r)
|
|
|
|
|
2011-11-04 01:56:21 +08:00
|
|
|
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()
|
|
|
|
|
2011-11-04 01:56:06 +08:00
|
|
|
class BuildToolComponentInfo(ToolComponentInfo):
|
|
|
|
type_name = 'BuildTool'
|
|
|
|
|
2011-11-04 01:56:10 +08:00
|
|
|
@staticmethod
|
|
|
|
def parse(subpath, items):
|
|
|
|
kwargs = ComponentInfo.parse_items(items)
|
|
|
|
kwargs['required_libraries'] = items.get_list('required_libraries')
|
|
|
|
return BuildToolComponentInfo(subpath, **kwargs)
|
|
|
|
|
|
|
|
###
|
|
|
|
|
|
|
|
class IniFormatParser(dict):
|
|
|
|
def get_list(self, key):
|
|
|
|
# Check if the value is defined.
|
|
|
|
value = self.get(key)
|
|
|
|
if value is None:
|
|
|
|
return []
|
|
|
|
|
|
|
|
# Lists are just whitespace separated strings.
|
|
|
|
return value.split()
|
|
|
|
|
|
|
|
def get_optional_string(self, key):
|
|
|
|
value = self.get_list(key)
|
|
|
|
if not value:
|
|
|
|
return None
|
|
|
|
if len(value) > 1:
|
|
|
|
raise ParseError("multiple values for scalar key: %r" % key)
|
|
|
|
return value[0]
|
|
|
|
|
|
|
|
def get_string(self, key):
|
|
|
|
value = self.get_optional_string(key)
|
|
|
|
if not value:
|
|
|
|
raise ParseError("missing value for required string: %r" % key)
|
|
|
|
return value
|
|
|
|
|
2011-11-10 08:49:51 +08:00
|
|
|
def get_optional_bool(self, key, default = None):
|
|
|
|
value = self.get_optional_string(key)
|
|
|
|
if not value:
|
|
|
|
return default
|
|
|
|
if value not in ('0', '1'):
|
|
|
|
raise ParseError("invalid value(%r) for boolean property: %r" % (
|
|
|
|
value, key))
|
|
|
|
return bool(int(value))
|
|
|
|
|
|
|
|
def get_bool(self, key):
|
|
|
|
value = self.get_optional_bool(key)
|
|
|
|
if value is None:
|
|
|
|
raise ParseError("missing value for required boolean: %r" % key)
|
|
|
|
return value
|
|
|
|
|
2011-11-04 01:56:06 +08:00
|
|
|
_component_type_map = dict(
|
|
|
|
(t.type_name, t)
|
|
|
|
for t in (GroupComponentInfo,
|
|
|
|
LibraryComponentInfo, LibraryGroupComponentInfo,
|
2011-11-10 08:49:51 +08:00
|
|
|
ToolComponentInfo, BuildToolComponentInfo,
|
2012-05-08 03:38:40 +08:00
|
|
|
TargetGroupComponentInfo, OptionalLibraryComponentInfo))
|
2011-11-04 01:56:06 +08:00
|
|
|
def load_from_path(path, subpath):
|
|
|
|
# Load the LLVMBuild.txt file as an .ini format file.
|
|
|
|
parser = ConfigParser.RawConfigParser()
|
|
|
|
parser.read(path)
|
|
|
|
|
2011-12-13 06:45:59 +08:00
|
|
|
# Extract the common section.
|
|
|
|
if parser.has_section("common"):
|
|
|
|
common = IniFormatParser(parser.items("common"))
|
|
|
|
parser.remove_section("common")
|
|
|
|
else:
|
|
|
|
common = IniFormatParser({})
|
|
|
|
|
|
|
|
return common, _read_components_from_parser(parser, path, subpath)
|
|
|
|
|
|
|
|
def _read_components_from_parser(parser, path, subpath):
|
2011-11-04 01:56:06 +08:00
|
|
|
# We load each section which starts with 'component' as a distinct component
|
|
|
|
# description (so multiple components can be described in one file).
|
|
|
|
for section in parser.sections():
|
|
|
|
if not section.startswith('component'):
|
|
|
|
# We don't expect arbitrary sections currently, warn the user.
|
2011-11-04 01:56:10 +08:00
|
|
|
warning("ignoring unknown section %r in %r" % (section, path))
|
2011-11-04 01:56:06 +08:00
|
|
|
continue
|
|
|
|
|
2011-11-04 01:56:10 +08:00
|
|
|
# Determine the type of the component to instantiate.
|
2011-11-04 01:56:06 +08:00
|
|
|
if not parser.has_option(section, 'type'):
|
2011-11-04 01:56:10 +08:00
|
|
|
fatal("invalid component %r in %r: %s" % (
|
|
|
|
section, path, "no component type"))
|
2011-11-04 01:56:06 +08:00
|
|
|
|
|
|
|
type_name = parser.get(section, 'type')
|
|
|
|
type_class = _component_type_map.get(type_name)
|
|
|
|
if type_class is None:
|
2011-11-04 01:56:10 +08:00
|
|
|
fatal("invalid component %r in %r: %s" % (
|
|
|
|
section, path, "invalid component type: %r" % type_name))
|
2011-11-04 01:56:06 +08:00
|
|
|
|
|
|
|
# Instantiate the component based on the remaining values.
|
|
|
|
try:
|
2011-11-04 01:56:10 +08:00
|
|
|
info = type_class.parse(subpath,
|
|
|
|
IniFormatParser(parser.items(section)))
|
2011-11-04 01:56:06 +08:00
|
|
|
except TypeError:
|
|
|
|
print >>sys.stderr, "error: invalid component %r in %r: %s" % (
|
|
|
|
section, path, "unable to instantiate: %r" % type_name)
|
|
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
|
|
raise SystemExit, 1
|
2011-11-04 01:56:10 +08:00
|
|
|
except ParseError,e:
|
|
|
|
fatal("unable to load component %r in %r: %s" % (
|
|
|
|
section, path, e.message))
|
2011-11-04 01:56:06 +08:00
|
|
|
|
2011-12-13 06:45:35 +08:00
|
|
|
info._source_path = path
|
2011-11-04 01:56:06 +08:00
|
|
|
yield info
|