def _index(self, roots):
    """Index from the given roots into the storage provided by the base class.

    This is an additive operation: any existing connections involving these nodes are preserved.
    """
    all_addresses = set()
    new_targets = list()

    # Index the ProductGraph.
    for node, state in self._graph.walk(roots=roots):
      # Locate nodes that contain LegacyBuildGraphNode values.
      if type(state) is Throw:
        raise AddressLookupError(
            'Build graph construction failed for {}:\n  {}'.format(node.subject, state.exc))
      elif type(state) is not Return:
        State.raise_unrecognized(state)
      if node.product is not LegacyBuildGraphNode:
        continue
      if type(node) is not SelectNode:
        continue

      # We have a successfully parsed LegacyBuildGraphNode.
      target_adaptor, dependency_addresses = state.value
      address = target_adaptor.address
      all_addresses.add(address)

      if address not in self._target_by_address:
        new_targets.append(self._index_target(target_adaptor, dependency_addresses))

    # Once the declared dependencies of all targets are indexed, inject their
    # additional "traversable_(dependency_)?specs".
    deps_to_inject = set()
    addresses_to_inject = set()
    def inject(target, dep_spec, is_dependency):
      address = Address.parse(dep_spec, relative_to=target.address.spec_path)
      if not any(address == t.address for t in target.dependencies):
        addresses_to_inject.add(address)
        if is_dependency:
          deps_to_inject.add((target.address, address))

    for target in new_targets:
      for spec in target.traversable_dependency_specs:
        inject(target, spec, is_dependency=True)
      for spec in target.traversable_specs:
        inject(target, spec, is_dependency=False)

    # Inject all addresses, then declare injected dependencies.
    self.inject_addresses_closure(addresses_to_inject)
    for target_address, dep_address in deps_to_inject:
      self.inject_dependency(dependent=target_address, dependency=dep_address)

    return all_addresses
dataset/ETHPy150Open pantsbuild/pants/src/python/pants/engine/exp/legacy/graph.py/ExpGraph._index/original