def _isolation(self, all_targets): run_dir = '_runs' output_dir = os.path.join(self.workdir, run_dir, Target.identify(all_targets)) safe_mkdir(output_dir, clean=True) coverage = None options = self.get_options() if options.coverage or options.is_flagged('coverage_open'): coverage_processor = options.coverage_processor if coverage_processor == 'cobertura': settings = CoberturaTaskSettings.from_task(self, workdir=output_dir) coverage = Cobertura(settings) else: raise TaskError('unknown coverage processor {0}'.format( coverage_processor)) self.context.release_lock() if coverage: coverage.instrument( targets=all_targets, compute_junit_classpath=lambda: self.classpath(all_targets), execute_java_for_targets=self.execute_java_for_coverage) def do_report(exc=None): if coverage: coverage.report(all_targets, self.execute_java_for_coverage, tests_failed_exception=exc) if self._html_report: html_file_path = JUnitHtmlReport().report( output_dir, os.path.join(output_dir, 'reports')) if self._open: desktop.ui_open(html_file_path) try: yield output_dir, do_report, coverage finally: # NB: Deposit of the "current" test output in the root workdir (.pants.d/test/junit) is a # defacto public API and so we implement that behavior here to maintain backwards # compatibility for non-pants report file consumers. # TODO(John Sirois): Deprecate this ~API and provide a stable directory solution for test # output: https://github.com/pantsbuild/pants/issues/3879 lock_file = '.file_lock' with OwnerPrintingInterProcessFileLock( os.path.join(self.workdir, lock_file)): # Kill everything except the isolated runs/ dir. for name in os.listdir(self.workdir): path = os.path.join(self.workdir, name) if name not in (run_dir, lock_file): if os.path.isdir(path): safe_rmtree(path) else: os.unlink(path) # Link all the isolated run/ dir contents back up to the stable workdir for name in os.listdir(output_dir): path = os.path.join(output_dir, name) os.symlink(path, os.path.join(self.workdir, name))
def _isolation(self, all_targets): run_dir = '_runs' mode_dir = 'isolated' if self._per_target else 'combined' batch_dir = str(self._batch_size) if self._batched else 'all' output_dir = os.path.join(self.workdir, run_dir, Target.identify(all_targets), mode_dir, batch_dir) safe_mkdir(output_dir, clean=False) if self._html_report: junit_html_report = JUnitHtmlReport.create( xml_dir=output_dir, open_report=self.get_options().open, logger=self.context.log, error_on_conflict=True) else: junit_html_report = NoJunitHtmlReport() coverage = CodeCoverage.global_instance().get_coverage_engine( self, output_dir, all_targets, self.execute_java_for_coverage) reports = self.Reports(junit_html_report, coverage) self.context.release_lock() try: yield output_dir, reports, coverage finally: lock_file = '.file_lock' preserve = (run_dir, lock_file) dist_dir = os.path.join( self.get_options().pants_distdir, os.path.relpath(self.workdir, self.get_options().pants_workdir)) with OwnerPrintingInterProcessFileLock( os.path.join(dist_dir, lock_file)): self._link_current_reports(report_dir=output_dir, link_dir=dist_dir, preserve=preserve) if self._legacy_report_layout: deprecated_conditional( predicate=lambda: True, entity_description='[test.junit] legacy_report_layout', stacklevel=3, removal_version='1.6.0.dev0', hint_message= 'Reports are now linked into {} by default; so scripts ' 'and CI jobs should be pointed there and the option ' 'configured to False in pants.ini until such time as ' 'the option is removed.'.format(dist_dir)) # NB: Deposit of the "current" test output in the root workdir (.pants.d/test/junit) is a # defacto public API and so we implement that behavior here to maintain backwards # compatibility for non-pants report file consumers. with OwnerPrintingInterProcessFileLock( os.path.join(self.workdir, lock_file)): self._link_current_reports(report_dir=output_dir, link_dir=self.workdir, preserve=preserve)
def add(self, targets, cache_key, valid, phase): # Manufacture an id from a hash of the target ids targets_hash = Target.identify(targets) self._entries.append(self.TaskEntry(targets_hash=targets_hash, target_ids=[t.id for t in targets], cache_key_id=cache_key.id, cache_key_hash=cache_key.hash, valid=valid, phase=phase))
def add(self, targets, cache_key, valid, phase=None): if not phase: raise ValueError('Must specify a descriptive phase= value (e.g. "init", "pre-check", ...') # Manufacture an id from a hash of the target ids targets_hash = Target.identify(targets) self._entries.append(self.TaskEntry(targets_hash=targets_hash, target_ids=[t.id for t in targets], cache_key_id=cache_key.id, cache_key_hash=cache_key.hash, valid=valid, phase=phase))
def _isolation(self, all_targets): run_dir = '_runs' output_dir = os.path.join(self.workdir, run_dir, Target.identify(all_targets)) safe_mkdir(output_dir, clean=True) coverage = None options = self.get_options() if options.coverage or options.is_flagged('coverage_open'): coverage_processor = options.coverage_processor if coverage_processor == 'cobertura': settings = CoberturaTaskSettings.from_task(self, workdir=output_dir) coverage = Cobertura(settings) else: raise TaskError('unknown coverage processor {0}'.format(coverage_processor)) self.context.release_lock() if coverage: coverage.instrument(targets=all_targets, compute_junit_classpath=lambda: self.classpath(all_targets), execute_java_for_targets=self.execute_java_for_coverage) def do_report(exc=None): if coverage: coverage.report(all_targets, self.execute_java_for_coverage, tests_failed_exception=exc) if self._html_report: html_file_path = JUnitHtmlReport().report(output_dir, os.path.join(output_dir, 'reports')) if self._open: desktop.ui_open(html_file_path) try: yield output_dir, do_report, coverage finally: # NB: Deposit of the "current" test output in the root workdir (.pants.d/test/junit) is a # defacto public API and so we implement that behavior here to maintain backwards # compatibility for non-pants report file consumers. # TODO(John Sirois): Deprecate this ~API and provide a stable directory solution for test # output: https://github.com/pantsbuild/pants/issues/3879 lock_file = '.file_lock' with OwnerPrintingInterProcessFileLock(os.path.join(self.workdir, lock_file)): # Kill everything except the isolated runs/ dir. for name in os.listdir(self.workdir): path = os.path.join(self.workdir, name) if name not in (run_dir, lock_file): if os.path.isdir(path): safe_rmtree(path) else: os.unlink(path) # Link all the isolated run/ dir contents back up to the stable workdir for name in os.listdir(output_dir): path = os.path.join(output_dir, name) os.symlink(path, os.path.join(self.workdir, name))
def add(self, targets, cache_key, valid, phase=None): if not phase: raise ValueError( 'Must specify a descriptive phase= value (e.g. "init", "pre-check", ...' ) # Manufacture an id from a hash of the target ids targets_hash = Target.identify(targets) self._entries.append( self.TaskEntry(targets_hash=targets_hash, target_ids=[t.id for t in targets], cache_key_id=cache_key.id, cache_key_hash=cache_key.hash, valid=valid, phase=phase))
def _isolation(self, all_targets): run_dir = '_runs' output_dir = os.path.join(self.workdir, run_dir, Target.identify(all_targets)) safe_mkdir(output_dir, clean=False) if self._html_report: junit_html_report = JUnitHtmlReport.create(output_dir, self.context.log) else: junit_html_report = NoJunitHtmlReport() if self.get_options().coverage or self.get_options().is_flagged( 'coverage_open'): settings = CoberturaTaskSettings.from_task(self, workdir=output_dir) coverage = Cobertura(settings, all_targets, self.execute_java_for_coverage) else: coverage = NoCoverage() reports = self.Reports(junit_html_report, coverage) self.context.release_lock() try: yield output_dir, reports, coverage finally: # NB: Deposit of the "current" test output in the root workdir (.pants.d/test/junit) is a # defacto public API and so we implement that behavior here to maintain backwards # compatibility for non-pants report file consumers. # TODO(John Sirois): Deprecate this ~API and provide a stable directory solution for test # output: https://github.com/pantsbuild/pants/issues/3879 lock_file = '.file_lock' with OwnerPrintingInterProcessFileLock( os.path.join(self.workdir, lock_file)): # Kill everything except the isolated `_runs/` dir. for name in os.listdir(self.workdir): path = os.path.join(self.workdir, name) if name not in (run_dir, lock_file): if os.path.isdir(path): safe_rmtree(path) else: os.unlink(path) # Link all the isolated run/ dir contents back up to the stable workdir for name in os.listdir(output_dir): path = os.path.join(output_dir, name) os.symlink(path, os.path.join(self.workdir, name))
def _isolation(self, all_targets): run_dir = '_runs' output_dir = os.path.join(self.workdir, run_dir, Target.identify(all_targets)) safe_mkdir(output_dir, clean=False) if self._html_report: junit_html_report = JUnitHtmlReport.create(output_dir, self.context.log) else: junit_html_report = NoJunitHtmlReport() if self.get_options().coverage or self.get_options().is_flagged('coverage_open'): settings = CoberturaTaskSettings.from_task(self, workdir=output_dir) coverage = Cobertura(settings, all_targets, self.execute_java_for_coverage) else: coverage = NoCoverage() reports = self.Reports(junit_html_report, coverage) self.context.release_lock() try: yield output_dir, reports, coverage finally: # NB: Deposit of the "current" test output in the root workdir (.pants.d/test/junit) is a # defacto public API and so we implement that behavior here to maintain backwards # compatibility for non-pants report file consumers. # TODO(John Sirois): Deprecate this ~API and provide a stable directory solution for test # output: https://github.com/pantsbuild/pants/issues/3879 lock_file = '.file_lock' with OwnerPrintingInterProcessFileLock(os.path.join(self.workdir, lock_file)): # Kill everything except the isolated `_runs/` dir. for name in os.listdir(self.workdir): path = os.path.join(self.workdir, name) if name not in (run_dir, lock_file): if os.path.isdir(path): safe_rmtree(path) else: os.unlink(path) # Link all the isolated run/ dir contents back up to the stable workdir for name in os.listdir(output_dir): path = os.path.join(output_dir, name) os.symlink(path, os.path.join(self.workdir, name))
def _isolation(self, per_target, all_targets): run_dir = '_runs' mode_dir = 'isolated' if per_target else 'combined' batch_dir = str(self._batch_size) if self._batched else 'all' output_dir = os.path.join(self.workdir, run_dir, Target.identify(all_targets), mode_dir, batch_dir) safe_mkdir(output_dir, clean=False) if self._html_report: junit_html_report = JUnitHtmlReport.create( xml_dir=output_dir, open_report=self.get_options().open, logger=self.context.log, error_on_conflict=self.get_options( ).html_report_error_on_conflict) else: junit_html_report = NoJunitHtmlReport() coverage = CodeCoverage.global_instance().get_coverage_engine( self, output_dir, all_targets, self.execute_java_for_coverage) reports = self.Reports(junit_html_report, coverage) self.context.release_lock() try: yield output_dir, reports, coverage finally: lock_file = '.file_lock' preserve = (run_dir, lock_file) dist_dir = os.path.join( self.get_options().pants_distdir, os.path.relpath(self.workdir, self.get_options().pants_workdir)) with OwnerPrintingInterProcessFileLock( os.path.join(dist_dir, lock_file)): self._link_current_reports(report_dir=output_dir, link_dir=dist_dir, preserve=preserve)
def _isolation(self, per_target, all_targets): run_dir = '_runs' mode_dir = 'isolated' if per_target else 'combined' batch_dir = str(self._batch_size) if self._batched else 'all' output_dir = os.path.join(self.workdir, run_dir, Target.identify(all_targets), mode_dir, batch_dir) safe_mkdir(output_dir, clean=False) if self._html_report: junit_html_report = JUnitHtmlReport.create(xml_dir=output_dir, open_report=self.get_options().open, logger=self.context.log, error_on_conflict=True) else: junit_html_report = NoJunitHtmlReport() coverage = CodeCoverage.global_instance().get_coverage_engine( self, output_dir, all_targets, self.execute_java_for_coverage) reports = self.Reports(junit_html_report, coverage) self.context.release_lock() try: yield output_dir, reports, coverage finally: lock_file = '.file_lock' preserve = (run_dir, lock_file) dist_dir = os.path.join(self.get_options().pants_distdir, os.path.relpath(self.workdir, self.get_options().pants_workdir)) with OwnerPrintingInterProcessFileLock(os.path.join(dist_dir, lock_file)): self._link_current_reports(report_dir=output_dir, link_dir=dist_dir, preserve=preserve)
def __str__(self): ident = Target.identify(self.targets()) return 'Context(id:{}, targets:{})'.format(ident, self.targets())