Example #1
0
def identify_compiler(object_):
  if typecheck.is_string(object_):
    return _COMPILER_CLASSES.get(object_, None)
  elif typecheck.is_class(object_):
    if _fix_compiler_name(object_.__name__) in _COMPILER_CLASSES:
      return _COMPILER_CLASSES[_fix_compiler_name(object_.__name__)]
  elif isinstance(object_, Compiler):
    return identify_compiler(object_.__class__)
  return None
Example #2
0
 def __init__(self, target=None, name=None, execute=None, deps=[]):
   """Each rule has a name that identifies it within existed context. In case
   name wasn't provided, it becomes a target and vice-versa.
   """
   if not target and not name:
     raise Exception("target and/or name have to be provided")
   if name and not typecheck.is_string(name):
     raise TypeError("name has to be a string: %s,%s" % (name, target))
   self._target = target
   if not name:
     if typecheck.is_string(target):
       name = target
     elif typecheck.is_class(target) or typecheck.is_function(target):
       name = target.__name__
     else:
       name = "i%d" % id(target)
   self._name = name
   self._description = None
   self._address = None
   self._address = self.locate()
   self._dependencies = [] # TODO: deprecated
   self._properties = dict()
   self._build_dir = None
   # TODO: test on windows and other systems!
   self.set_build_dir(path_utils.join(
       bb.config.user_settings.get("b3", "builddir"), os.getcwd()[1:]))
   if hasattr(self.__class__, "properties"):
     self.add_properties(self.__class__.properties)
   register_rule(self)
   if execute:
     if not callable(execute):
       raise TypeError()
     self.execute = types.MethodType(execute, self)
   # Defer dependency resolution after parsing the current BUILD file to
   # allow for forward references
   self._post_init(self._finalize_deps, deps)
Example #3
0
def get_all_subclasses(cls):
  """Returns all subclasses."""
  if not typecheck.is_class(cls):
    return [cls.__class__] + get_all_subclasses(cls.__class__)
  return list(cls.__bases__) + [g for s in cls.__bases__
                                for g in get_all_subclasses(s)]