Return True if 'CCompiler.compile()' able to compile a source file with certain flags.
(self, source, flags, macros=[])
| 614 | return ccompiler.compile(sources, extra_postargs=flags, **kwargs) |
| 615 | |
| 616 | def dist_test(self, source, flags, macros=[]): |
| 617 | """Return True if 'CCompiler.compile()' able to compile |
| 618 | a source file with certain flags. |
| 619 | """ |
| 620 | assert(isinstance(source, str)) |
| 621 | from distutils.errors import CompileError |
| 622 | cc = self._ccompiler; |
| 623 | bk_spawn = getattr(cc, 'spawn', None) |
| 624 | if bk_spawn: |
| 625 | cc_type = getattr(self._ccompiler, "compiler_type", "") |
| 626 | if cc_type in ("msvc",): |
| 627 | setattr(cc, 'spawn', self._dist_test_spawn_paths) |
| 628 | else: |
| 629 | setattr(cc, 'spawn', self._dist_test_spawn) |
| 630 | test = False |
| 631 | try: |
| 632 | self.dist_compile( |
| 633 | [source], flags, macros=macros, output_dir=self.conf_tmp_path |
| 634 | ) |
| 635 | test = True |
| 636 | except CompileError as e: |
| 637 | self.dist_log(str(e), stderr=True) |
| 638 | if bk_spawn: |
| 639 | setattr(cc, 'spawn', bk_spawn) |
| 640 | return test |
| 641 | |
| 642 | def dist_info(self): |
| 643 | """ |
no test coverage detected