Beispiel #1
0
    def _register_singletons(self, singletons):
        """Register the given singletons dict.

    Singleton tasks are those that are the default for a particular type(product). Like
    intrinsics, singleton tasks create Runnables that are not cacheable.
    """
        for product_type, rule in singletons.items():
            self._native.lib.singleton_task_add(
                self._scheduler, Function(self._to_id(rule.func)),
                self._to_constraint(product_type))
Beispiel #2
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)
Beispiel #3
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))
Beispiel #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)