|
1 | 1 | import configparser
|
2 |
| -from distutils import ccompiler, sysconfig |
3 |
| -from distutils.core import Extension |
| 2 | +from distutils import sysconfig |
4 | 3 | import functools
|
5 | 4 | import hashlib
|
6 | 5 | from io import BytesIO
|
|
16 | 15 | import textwrap
|
17 | 16 | import urllib.request
|
18 | 17 |
|
| 18 | +from setuptools import Distribution, Extension |
| 19 | + |
19 | 20 | _log = logging.getLogger(__name__)
|
20 | 21 |
|
21 | 22 |
|
@@ -523,16 +524,37 @@ def add_libagg_flags_and_sources(ext):
|
523 | 524 | os.path.join("extern", "agg24-svn", "src", x) for x in agg_sources)
|
524 | 525 |
|
525 | 526 |
|
526 |
| -# First compile checkdep_freetype2.c, which aborts the compilation either |
527 |
| -# with "foo.h: No such file or directory" if the header is not found, or an |
528 |
| -# appropriate error message if the header indicates a too-old version. |
| 527 | +def get_ccompiler(): |
| 528 | + """ |
| 529 | + Return a new CCompiler instance. |
| 530 | +
|
| 531 | + CCompiler used to be constructible via `distutils.ccompiler.new_compiler`, |
| 532 | + but this API was removed as part of the distutils deprecation. Instead, |
| 533 | + we trick setuptools into instantiating it by creating a du
10422
mmy Distribution |
| 534 | + with a list of extension modules that claims to be truthy, but is actually |
| 535 | + empty, and then running the Distribution's build_ext command. (If using |
| 536 | + a plain empty ext_modules, build_ext would early-return without doing |
| 537 | + anything.) |
| 538 | + """ |
| 539 | + |
| 540 | + class L(list): |
| 541 | + def __bool__(self): |
| 542 | + return True |
| 543 | + |
| 544 | + build_ext = Distribution({"ext_modules": L()}).get_command_obj("build_ext") |
| 545 | + build_ext.finalize_options() |
| 546 | + build_ext.run() |
| 547 | + return build_ext.compiler |
529 | 548 |
|
530 | 549 |
|
531 | 550 | class FreeType(SetupPackage):
|
532 | 551 | name = "freetype"
|
533 | 552 |
|
534 | 553 | @classmethod
|
535 | 554 | def add_flags(cls, ext):
|
| 555 | + # checkdep_freetype2.c immediately aborts the compilation either with |
| 556 | + # "foo.h: No such file or directory" if the header is not found, or an |
| 557 | + # appropriate error message if the header indicates a too-old version. |
536 | 558 | ext.sources.insert(0, 'src/checkdep_freetype2.c')
|
537 | 559 | if options.get('system_freetype'):
|
538 | 560 | pkg_config_setup_extension(
|
@@ -636,7 +658,7 @@ def do_custom_build(self, env):
|
636 | 658 | f.truncate()
|
637 | 659 | f.write(vcxproj)
|
638 | 660 |
|
639 |
| - cc = ccompiler.new_compiler() |
| 661 | + cc = get_ccompiler() |
640 | 662 | cc.initialize() # Get msbuild in the %PATH% of cc.spawn.
|
641 | 663 | cc.spawn(["msbuild", str(sln_path),
|
642 | 664 | "/t:Clean;Build",
|
|
0 commit comments