示例#1
0
  def _topological_sort(self, phase_info_by_phase):
    dependees_by_phase = OrderedDict()

    def add_dependee(phase, dependee=None):
      dependees = dependees_by_phase.get(phase)
      if dependees is None:
        dependees = set()
        dependees_by_phase[phase] = dependees
      if dependee:
        dependees.add(dependee)

    for phase, phase_info in phase_info_by_phase.items():
      add_dependee(phase)
      for dependency in phase_info.phase_dependencies:
        add_dependee(dependency, phase)

    satisfied = set()
    while dependees_by_phase:
      count = len(dependees_by_phase)
      for phase, dependees in dependees_by_phase.items():
        unsatisfied = len(dependees - satisfied)
        if unsatisfied == 0:
          satisfied.add(phase)
          dependees_by_phase.pop(phase)
          yield phase_info_by_phase[phase]
          break
      if len(dependees_by_phase) == count:
        for dependees in dependees_by_phase.values():
          dependees.difference_update(satisfied)
        # TODO(John Sirois): Do a better job here and actually collect and print cycle paths
        # between Goals/Tasks.  The developer can most directly address that data.
        raise self.PhaseCycleError('Cycle detected in phase dependencies:\n\t{0}'
                                   .format('\n\t'.join('{0} <- {1}'.format(phase, list(dependees))
                                                       for phase, dependees
                                                       in dependees_by_phase.items())))
示例#2
0
class ZincAnalysisElementDiff(object):
  def __init__(self, left_elem, right_elem, keys_only_headers=None):
    left_type = type(left_elem)
    right_type = type(right_elem)
    if left_type != right_type:
      raise Exception('Cannot compare elements of types %s and %s' % (left_type, right_type))
    self._arg_diffs = OrderedDict()
    for header, left_dict, right_dict in zip(left_elem.headers, left_elem.args, right_elem.args):
      keys_only = header in (keys_only_headers or [])
      self._arg_diffs[header] = DictDiff(left_dict, right_dict, keys_only=keys_only)

  def is_different(self):
    return any([x.is_different() for x in self._arg_diffs.values()])

  def __unicode__(self):
    parts = []
    for header, arg_diff in self._arg_diffs.items():
      if arg_diff.is_different():
        parts.append('Section "%s" differs:\n' % header)
        parts.append(arg_diff)
        parts.append('\n\n')
    return ''.join(parts)  # '' is a unicode, so the entire result will be.

  def __str__(self):
    if Compatibility.PY3:
      return self.__unicode__()
    else:
      return self.__unicode__().encode('utf-8')
示例#3
0
    def _mapped_dependencies(self, jardepmap, binary, confs):
        # TODO(John Sirois): rework product mapping towards well known types

        # Generate a map of jars for each unique artifact (org, name)
        externaljars = OrderedDict()
        visited = set()
        for conf in confs:
            mapped = jardepmap.get((binary, conf))
            if mapped:
                for basedir, jars in mapped.items():
                    for externaljar in jars:
                        if (basedir, externaljar) not in visited:
                            visited.add((basedir, externaljar))
                            keys = jardepmap.keys_for(basedir, externaljar)
                            for key in keys:
                                if isinstance(key, tuple) and len(key) == 3:
                                    org, name, configuration = key
                                    classpath_entry = externaljars.get(
                                        (org, name))
                                    if not classpath_entry:
                                        classpath_entry = {}
                                        externaljars[(org,
                                                      name)] = classpath_entry
                                    classpath_entry[conf] = os.path.join(
                                        basedir, externaljar)
        return externaljars.values()
示例#4
0
  def _topological_sort(self, goal_info_by_goal):
    dependees_by_goal = OrderedDict()

    def add_dependee(goal, dependee=None):
      dependees = dependees_by_goal.get(goal)
      if dependees is None:
        dependees = set()
        dependees_by_goal[goal] = dependees
      if dependee:
        dependees.add(dependee)

    for goal, goal_info in goal_info_by_goal.items():
      add_dependee(goal)
      for dependency in goal_info.goal_dependencies:
        add_dependee(dependency, goal)

    satisfied = set()
    while dependees_by_goal:
      count = len(dependees_by_goal)
      for goal, dependees in dependees_by_goal.items():
        unsatisfied = len(dependees - satisfied)
        if unsatisfied == 0:
          satisfied.add(goal)
          dependees_by_goal.pop(goal)
          yield goal_info_by_goal[goal]
          break
      if len(dependees_by_goal) == count:
        for dependees in dependees_by_goal.values():
          dependees.difference_update(satisfied)
        # TODO(John Sirois): Do a better job here and actually collect and print cycle paths
        # between Goals/Tasks.  The developer can most directly address that data.
        raise self.GoalCycleError('Cycle detected in goal dependencies:\n\t{0}'
                                   .format('\n\t'.join('{0} <- {1}'.format(goal, list(dependees))
                                                       for goal, dependees
                                                       in dependees_by_goal.items())))
示例#5
0
class ZincAnalysisElementDiff(object):
    def __init__(self, left_elem, right_elem, keys_only_headers=None):
        left_type = type(left_elem)
        right_type = type(right_elem)
        if left_type != right_type:
            raise Exception('Cannot compare elements of types %s and %s' %
                            (left_type, right_type))
        self._arg_diffs = OrderedDict()
        for header, left_dict, right_dict in zip(left_elem.headers,
                                                 left_elem.args,
                                                 right_elem.args):
            keys_only = header in (keys_only_headers or [])
            self._arg_diffs[header] = DictDiff(left_dict,
                                               right_dict,
                                               keys_only=keys_only)

    def is_different(self):
        return any([x.is_different() for x in self._arg_diffs.values()])

    def __unicode__(self):
        parts = []
        for header, arg_diff in self._arg_diffs.items():
            if arg_diff.is_different():
                parts.append('Section "%s" differs:\n' % header)
                parts.append(arg_diff)
                parts.append('\n\n')
        return ''.join(parts)  # '' is a unicode, so the entire result will be.

    def __str__(self):
        if Compatibility.PY3:
            return self.__unicode__()
        else:
            return self.__unicode__().encode('utf-8')
示例#6
0
  def _mapped_dependencies(self, jardepmap, binary, confs):
    # TODO(John Sirois): rework product mapping towards well known types

    # Generate a map of jars for each unique artifact (org, name)
    externaljars = OrderedDict()
    visited = set()
    for conf in confs:
      mapped = jardepmap.get((binary, conf))
      if mapped:
        for basedir, jars in mapped.items():
          for externaljar in jars:
            if (basedir, externaljar) not in visited:
              visited.add((basedir, externaljar))
              keys = jardepmap.keys_for(basedir, externaljar)
              for key in keys:
                if isinstance(key, tuple) and len(key) == 3:
                  org, name, configuration = key
                  classpath_entry = externaljars.get((org, name))
                  if not classpath_entry:
                    classpath_entry = {}
                    externaljars[(org, name)] = classpath_entry
                  classpath_entry[conf] = os.path.join(basedir, externaljar)
    return externaljars.values()