示例#1
0
  def _register_tasks(self, tasks):
    """Register the given tasks dict with the native scheduler."""
    registered = set()
    for output_type, rules in tasks.items():
      output_constraint = self._to_constraint(output_type)
      for rule in rules:
        # TODO: The task map has heterogeneous keys, so we normalize them to type constraints
        # and dedupe them before registering to the native engine:
        #   see: https://github.com/pantsbuild/pants/issues/4005
        key = (output_constraint, rule)
        if key in registered:
          continue
        registered.add(key)

        _, input_selects, func = rule.as_triple()
        self._native.lib.tasks_task_begin(self._tasks, Function(self._to_id(func)), output_constraint)
        for selector in input_selects:
          selector_type = type(selector)
          product_constraint = self._to_constraint(selector.product)
          if selector_type is Select:
            self._native.lib.tasks_add_select(self._tasks, product_constraint)
          elif selector_type is SelectVariant:
            key_buf = self._to_utf8_buf(selector.variant_key)
            self._native.lib.tasks_add_select_variant(self._tasks,
                                                      product_constraint,
                                                      key_buf)
          elif selector_type is SelectLiteral:
            # NB: Intentionally ignores subject parameter to provide a literal subject.
            self._native.lib.tasks_add_select_literal(self._tasks,
                                                      self._to_key(selector.subject),
                                                      product_constraint)
          elif selector_type is SelectDependencies:
            self._native.lib.tasks_add_select_dependencies(self._tasks,
                                                           product_constraint,
                                                           self._to_constraint(selector.dep_product),
                                                           self._to_utf8_buf(selector.field),
                                                           self._to_ids_buf(selector.field_types))
          elif selector_type is SelectTransitive:
            self._native.lib.tasks_add_select_transitive(self._tasks,
                                                         product_constraint,
                                                         self._to_constraint(selector.dep_product),
                                                         self._to_utf8_buf(selector.field),
                                                         self._to_ids_buf(selector.field_types))
          elif selector_type is SelectProjection:
            if len(selector.fields) != 1:
              raise ValueError("TODO: remove support for projecting multiple fields at once.")
            field = selector.fields[0]
            self._native.lib.tasks_add_select_projection(self._tasks,
                                                         self._to_constraint(selector.product),
                                                         TypeId(self._to_id(selector.projected_subject)),
                                                         self._to_utf8_buf(field),
                                                         self._to_constraint(selector.input_product))
          else:
            raise ValueError('Unrecognized Selector type: {}'.format(selector))
        self._native.lib.tasks_task_end(self._tasks)
示例#2
0
    def _register_intrinsics(self, intrinsics):
        """Register the given intrinsics dict.

    Intrinsic tasks are those that are the default for a particular type(subject), type(product)
    pair. By default, intrinsic tasks create Runnables that are not cacheable.
    """
        for (subject_type, product_type), rule in intrinsics.items():
            self._native.lib.intrinsic_task_add(
                self._scheduler, Function(self._to_id(rule.func)),
                TypeId(self._to_id(subject_type)),
                self._to_constraint(subject_type),
                self._to_constraint(product_type))
示例#3
0
    def rule_subgraph_visualization(self, root_subject_type, product_type):
        root_type_id = TypeId(self._to_id(root_subject_type))

        product_type_id = TypeConstraint(
            self._to_id(constraint_for(product_type)))
        with temporary_file_path() as path:
            self._native.lib.rule_subgraph_visualize(self._scheduler,
                                                     root_type_id,
                                                     product_type_id,
                                                     bytes(path))
            with open(path) as fd:
                for line in fd.readlines():
                    yield line.rstrip()
示例#4
0
 def _register_task(self, output_constraint, rule):
     """Register the given TaskRule with the native scheduler."""
     input_selects = rule.input_selectors
     func = rule.func
     self._native.lib.tasks_task_begin(self._tasks,
                                       Function(self._to_id(func)),
                                       output_constraint)
     for selector in input_selects:
         selector_type = type(selector)
         product_constraint = self._to_constraint(selector.product)
         if selector_type is Select:
             self._native.lib.tasks_add_select(self._tasks,
                                               product_constraint)
         elif selector_type is SelectVariant:
             key_buf = self._to_utf8_buf(selector.variant_key)
             self._native.lib.tasks_add_select_variant(
                 self._tasks, product_constraint, key_buf)
         elif selector_type is SelectDependencies:
             self._native.lib.tasks_add_select_dependencies(
                 self._tasks, product_constraint,
                 self._to_constraint(selector.dep_product),
                 self._to_utf8_buf(selector.field),
                 self._to_ids_buf(selector.field_types))
         elif selector_type is SelectTransitive:
             self._native.lib.tasks_add_select_transitive(
                 self._tasks, product_constraint,
                 self._to_constraint(selector.dep_product),
                 self._to_utf8_buf(selector.field),
                 self._to_ids_buf(selector.field_types))
         elif selector_type is SelectProjection:
             self._native.lib.tasks_add_select_projection(
                 self._tasks, self._to_constraint(selector.product),
                 TypeId(self._to_id(selector.projected_subject)),
                 self._to_utf8_buf(selector.field),
                 self._to_constraint(selector.input_product))
         else:
             raise ValueError(
                 'Unrecognized Selector type: {}'.format(selector))
     self._native.lib.tasks_task_end(self._tasks)
示例#5
0
 def _root_type_ids(self):
   return list(TypeId(self._to_id(t)) for t in sorted(self.root_subject_types))
示例#6
0
 def _to_ids_buf(self, types):
   return self._native.context.type_ids_buf([TypeId(self._to_id(t)) for t in types])