예제 #1
0
 def background_worker_pool(self):
   if self._background_worker_pool is None:  # Initialize lazily.
     self._background_worker_pool = WorkerPool(parent_workunit=self.get_background_root_workunit(),
                                               run_tracker=self,
                                               num_workers=self._num_background_workers)
   return self._background_worker_pool
예제 #2
0
    def execute(self):
        # In case we have no relevant targets and return early create the requested product maps.
        self._create_empty_products()

        def select_target(target):
            return self.select(target)

        relevant_targets = list(self.context.targets(predicate=select_target))

        if not relevant_targets:
            return

        # Clone the compile_classpath to the runtime_classpath.
        compile_classpath = self.context.products.get_data('compile_classpath')
        runtime_classpath = self.context.products.get_data(
            'runtime_classpath', compile_classpath.copy)

        # This ensures the workunit for the worker pool is set
        with self.context.new_workunit('isolation-{}-pool-bootstrap'.format(self._name)) \
                as workunit:
            # This uses workunit.parent as the WorkerPool's parent so that child workunits
            # of different pools will show up in order in the html output. This way the current running
            # workunit is on the bottom of the page rather than possibly in the middle.
            self._worker_pool = WorkerPool(workunit.parent,
                                           self.context.run_tracker,
                                           self._worker_count)

        classpath_product = self.context.products.get_data('runtime_classpath')
        fingerprint_strategy = self._fingerprint_strategy(classpath_product)
        # Invalidation check. Everything inside the with block must succeed for the
        # invalid targets to become valid.
        with self.invalidated(relevant_targets,
                              invalidate_dependents=True,
                              partition_size_hint=0,
                              fingerprint_strategy=fingerprint_strategy,
                              topological_order=True) as invalidation_check:

            # Initialize the classpath for all targets.
            compile_contexts = {
                vt.target: self._compile_context(vt.target, vt.results_dir)
                for vt in invalidation_check.all_vts
            }
            for cc in compile_contexts.values():
                classpath_product.add_for_target(cc.target,
                                                 [(conf, cc.classes_dir)
                                                  for conf in self._confs])

            # Register products for valid targets.
            valid_targets = [
                vt.target for vt in invalidation_check.all_vts if vt.valid
            ]
            self._register_vts([compile_contexts[t] for t in valid_targets])

            # Build any invalid targets (which will register products in the background).
            if invalidation_check.invalid_vts:
                invalid_targets = [
                    vt.target for vt in invalidation_check.invalid_vts
                ]

                self.compile_chunk(
                    invalidation_check, compile_contexts, invalid_targets,
                    self.extra_compile_time_classpath_elements())

            # Once compilation has completed, replace the classpath entry for each target with
            # its jar'd representation.
            classpath_products = self.context.products.get_data(
                'runtime_classpath')
            for cc in compile_contexts.values():
                for conf in self._confs:
                    classpath_products.remove_for_target(
                        cc.target, [(conf, cc.classes_dir)])
                    classpath_products.add_for_target(cc.target,
                                                      [(conf, cc.jar_file)])
예제 #3
0
 def foreground_worker_pool(self):
   if self._foreground_worker_pool is None:  # Initialize lazily.
     self._foreground_worker_pool = WorkerPool(parent_workunit=self._main_root_workunit,
                                               run_tracker=self,
                                               num_workers=self._num_foreground_workers)
   return self._foreground_worker_pool