Beispiel #1
0
    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)
Beispiel #2
0
    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))
Beispiel #3
0
    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)