Injects targets into the graph for the given `Specs` object.

    Yields the resulting addresses.
4028
def _inject_specs(self, specs):
    
    if not specs:
      return

    logger.debug('Injecting specs to %s: %s', self, specs)
    with self._resolve_context():
      thts, = self._scheduler.product_request(TransitiveHydratedTargets,
                                              [specs])

    self._index(thts.closure)

    for hydrated_target in thts.roots:
      yield hydrated_target.address
1184528
def inject(cls, span, obj):
        
        opentracing.tracer.inject(span, cls.FORMAT, obj['headers'])
258607
def write_targets(targets, **params):
    """"""
    handler = ReplacementHandler(**params)
    for target, regexer in regexer_for_targets(targets):
        with open(target) as fh:
            lines = fh.readlines()
        lines = replace_lines(regexer, handler, lines)
        with open(target, "w") as fh:
            fh.writelines(lines)
    if handler.missing:
        raise Exception(
            "Failed to complete all expected replacements: %r" % handler.missing
        )
554096
def imported_targets(self):
    
    libs = []
    for spec in self.imported_target_specs(payload=self.payload):
      resolved_target = self._build_graph.get_target_from_spec(spec,
                                                               relative_to=self.address.spec_path)
      if not resolved_target:
        raise self.UnresolvedImportError(
          'Could not find target {spec} referenced from {relative_to}'
          .format(spec=spec, relative_to=self.address.spec))
      try:
        libs.append(self.expected_target_constraint.validate_satisfied_by(resolved_target))
      except TypeConstraintError as e:
        raise self.WrongTargetTypeError(
          'Wrong target type {spec} referenced from remote sources target {relative_to}: {err}'
          .format(spec=spec, relative_to=self.address.spec, err=str(e)),
          e)
    return libs
62598
def apply_customizations(cls, spec, options):
        
        for key in sorted(spec.keys()):
            if isinstance(spec[key], (list, tuple)):
                customization = {v.key:v for v in spec[key]}
            else:
                customization = {k:(Options(**v) if isinstance(v, dict) else v)
                                 for k,v in spec[key].items()}

            # Set the Keywords target on Options from the {type} part of the key.
            customization = {k:v.keywords_target(key.split('.')[0])
                             for k,v in customization.items()}
            options[str(key)] = customization
        return options
158359
def _create_mappings(self, spec):
        
        ret = dict(zip(set(spec.fields), set(spec.fields)))
        ret.update(dict([(n, s.alias) for n, s in spec.fields.items() if s.alias]))
        return ret
1039911
def hashify_targets(targets: list, build_context) -> list:
    """"""
    return sorted(build_context.targets[target_name].hash(build_context)
                  for target_name in listify(targets))
262374
def _FromSpecs(self, specs):
        

        if isinstance(specs, dict):
            specs_ = []
            for name, value in specs.items():
                specs_.append((name, {"value": value}))
        else:
            specs_ = specs
        for spec in specs_:
            self.params.append(Parameter(spec))
440236
def compute_targets_to_build(self, targets: Iterable[str]) -> Iterable[BuildTarget]:
        
        normalized_targets = set()
        for target in targets:
            normalized_targets.update(self._normalize_target(target))

        targets_to_parse = deque(normalized_targets)
        targets_seen = set(normalized_targets)
        targets_not_found = []
        build_targets = set()

        while targets_to_parse:
            next_target_string = targets_to_parse.popleft()
            next_target = self._parse_target(next_target_string)
            build_file = self.parser.parse_file(next_target.build_file_directory)
            if next_target.name not in build_file.targets:
                targets_not_found.append(next_target_string)
                continue
            target_to_build = build_file.targets[next_target.name]
            build_targets.add(target_to_build)

            new_targets = [
                dependency
                for dependency in target_to_build.dependencies
                if dependency not in targets_seen
            ]
            targets_to_parse.extend(new_targets)
            targets_seen.update(new_targets)

        if targets_not_found and self.fail_on_unbuilt_target:
            raise BuilderException(
                "Target(s) could not be built: {}".format(", ".join(targets_not_found)),
                targets=targets_not_found,
            )
        return build_targets
1026942
def process_targets(self, targets, full_config, arguments):
        
        executor = _get_executor(arguments)
        resolver = _get_resolver(arguments)
        dep_manager = resolver(targets, full_config, self._task_order)
        task_queue = dep_manager.get_queue()
        config_info = devpipeline_core.configinfo.ConfigInfo(executor)

        try:
            failed = []

            def _keep_going_on_failure(failure, task):
                skipped = task_queue.fail(task)
                failed.append((task, skipped, str(failure)))

            def _fail_immediately(failure, task):
                del task
                raise failure

            fail_fn = _fail_immediately
            if arguments.keep_going:
                fail_fn = _keep_going_on_failure

            self._execute_targets(task_queue, config_info, full_config, fail_fn)
            if failed:
                raise _PartialFailureException(failed)
        finally:
            full_config.write()
684696
def _build_rules(specs):
    
    for spec in specs:
        if "context" in spec:
            yield Context(spec["context"], list(_build_rules(spec.get("routes", []))))
        else:
            rulespec = spec.copy()
            match = rulespec.pop("match")
            name = rulespec.pop("name")
            yield Rule(match, endpoint=name, **rulespec)
992160
def infect(cls, graph, key, default_scope=None):
        
        func = graph.factory_for(key)
        if isinstance(func, cls):
            func = func.func
        factory = cls(key, func, default_scope)
        graph._registry.factories[key] = factory
        return factory
52871
private Collection<Key<?>> getRequiredSourcesTargeting(
      DependencyGraph graph, Iterable<Key<?>> targets) {
    Collection<Key<?>> requiredSources = new LinkedHashSet<Key<?>>();
    for (Key<?> target : targets) {
      for (Dependency edge : graph.getDependenciesTargeting(target)) {
        if (!edge.isOptional()) {
          PrettyPrinter.log(logger, TreeLogger.DEBUG, "Removing the key %s because of %s",
              edge.getSource(), edge);
          requiredSources.add(edge.getSource());
        }
      }
    }
    return requiredSources;
  }
779480
def create_build_graph(self, target_roots, build_root=None):
    
    logger.debug('target_roots are: %r', target_roots)
    graph = LegacyBuildGraph.create(self.scheduler_session, self.build_file_aliases)
    logger.debug('build_graph is: %s', graph)
    # Ensure the entire generator is unrolled.
    for _ in graph.inject_roots_closure(target_roots):
      pass

    address_mapper = LegacyAddressMapper(self.scheduler_session, build_root or get_buildroot())
    logger.debug('address_mapper is: %s', address_mapper)
    return graph, address_mapper
605244
def add_new_target(self, address, target_type, target_base=None, dependencies=None,
                     derived_from=None, **kwargs):
    
    rel_target_base = target_base or address.spec_path
    abs_target_base = os.path.join(get_buildroot(), rel_target_base)
    if not os.path.exists(abs_target_base):
      os.makedirs(abs_target_base)
      # TODO: Adding source roots on the fly like this is yucky, but hopefully this
      # method will go away entirely under the new engine. It's primarily used for injecting
      # synthetic codegen targets, and that isn't how codegen will work in the future.
    if not self.source_roots.find_by_path(rel_target_base):
      # TODO: Set the lang and root category (source/test/thirdparty) based on the target type?
      self.source_roots.add_source_root(rel_target_base)
    if dependencies:
      dependencies = [dep.address for dep in dependencies]

    self.build_graph.inject_synthetic_target(address=address,
                                             target_type=target_type,
                                             dependencies=dependencies,
                                             derived_from=derived_from,
                                             **kwargs)
    new_target = self.build_graph.get_target(address)

    return new_target
171856
def get_for_targets(self, targets):
    
    products = OrderedSet()
    for target in targets:
      products.update(self._products_by_target[target])
    return products
855464
def injectables_specs_for_key(self, key):
    
    mapping = self.injectables_spec_mapping
    if key not in mapping:
      raise self.NoMappingForKey(key)
    specs = mapping[key]
    assert isinstance(specs, list), (
      'invalid `injectables_spec_mapping` on {!r} for key "{}". '
      'expected a `list` but instead found a `{}`: {}'
    ).format(self, key, type(specs), specs)
    return [Address.parse(s).spec for s in specs]