def VerifyNoGYPFileCircularDependencies(targets):
  # Create a DependencyGraphNode for each gyp file containing a target.  Put
  # it into a dict for easy access.
  dependency_nodes = {}
  for target in targets.iterkeys():
    build_file = gyp.common.BuildFile(target)
    if not build_file in dependency_nodes:
      dependency_nodes[build_file] = DependencyGraphNode(build_file)

  # Set up the dependency links.
  for target, spec in targets.iteritems():
    build_file = gyp.common.BuildFile(target)
    build_file_node = dependency_nodes[build_file]
    target_dependencies = spec.get('dependencies', [])
    for dependency in target_dependencies:
      try:
        dependency_build_file = gyp.common.BuildFile(dependency)
      except GypError, e:
        gyp.common.ExceptionAppend(
            e, build_file % 'while computing dependencies of .gyp file %s')
        raise

      if dependency_build_file == build_file:
        # A .gyp file is allowed to refer back to itself.
        continue
      dependency_node = dependency_nodes.get(dependency_build_file)
      if not dependency_node:
        raise GypError("Dependancy '%s' not found" % dependency_build_file)
      if dependency_node not in build_file_node.dependencies:
        build_file_node.dependencies.append(dependency_node)
        dependency_node.dependents.append(build_file_node)


  # Files that have no dependencies are treated as dependent on root_node.
  root_node = DependencyGraphNode(None)
  for build_file_node in dependency_nodes.itervalues():
    if len(build_file_node.dependencies) == 0:
      build_file_node.dependencies.append(root_node)
      root_node.dependents.append(build_file_node)

  flat_list = root_node.FlattenToList()

  # If there's anything left unvisited, there must be a circular dependency
  # (cycle).
  if len(flat_list) != len(dependency_nodes):
    if not root_node.dependents:
      # If all files have dependencies, add the first file as a dependent
      # of root_node so that the cycle can be discovered from root_node.
      file_node = dependency_nodes.values()[0]
      file_node.dependencies.append(root_node)
      root_node.dependents.append(file_node)
    cycles = []
    for cycle in root_node.FindCycles():
      paths = [node.ref for node in cycle]
      cycles.append('Cycle: %s' % ' -> '.join(paths))
    raise DependencyGraphNode.CircularException(
        'Cycles in .gyp file dependency graph detected:\n' + '\n'.join(cycles))
dataset/ETHPy150Open adblockplus/gyp/pylib/gyp/input.py/VerifyNoGYPFileCircularDependencies/swapped operands of `%`