|
12 | 12 | import sys |
13 | 13 | import sysconfig |
14 | 14 | import tarfile |
| 15 | +from tempfile import TemporaryDirectory |
15 | 16 | import textwrap |
16 | 17 | import urllib.request |
17 | 18 |
|
@@ -691,15 +692,31 @@ def do_custom_build(self, env): |
691 | 692 | f.write(vcxproj) |
692 | 693 |
|
693 | 694 | cc = get_ccompiler() |
694 | | - cc.initialize() # Get msbuild in the %PATH% of cc.spawn. |
| 695 | + cc.initialize() |
| 696 | + # On setuptools versions that use "local" distutils, |
| 697 | + # ``cc.spawn(["msbuild", ...])`` no longer manages to locate the |
| 698 | + # right executable, even though they are correctly on the PATH, |
| 699 | + # because only the env kwarg to Popen() is updated, and not |
| 700 | + # os.environ["PATH"]. Instead, use shutil.which to walk the PATH |
| 701 | + # and get absolute executable paths. |
| 702 | + with TemporaryDirectory() as tmpdir: |
| 703 | + dest = Path(tmpdir, "path") |
| 704 | + cc.spawn([ |
| 705 | + sys.executable, "-c", |
| 706 | + "import pathlib, shutil, sys\n" |
| 707 | + "dest = pathlib.Path(sys.argv[1])\n" |
| 708 | + "dest.write_text(shutil.which('msbuild'))\n", |
| 709 | + str(dest), |
| 710 | + ]) |
| 711 | + msbuild_path = dest.read_text() |
695 | 712 | # Freetype 2.10.0+ support static builds. |
696 | 713 | msbuild_config = ( |
697 | 714 | "Release Static" |
698 | 715 | if [*map(int, LOCAL_FREETYPE_VERSION.split("."))] >= [2, 10] |
699 | 716 | else "Release" |
700 | 717 | ) |
701 | 718 |
|
702 | | - cc.spawn(["msbuild", str(sln_path), |
| 719 | + cc.spawn([msbuild_path, str(sln_path), |
703 | 720 | "/t:Clean;Build", |
704 | 721 | f"/p:Configuration={msbuild_config};" |
705 | 722 | f"Platform={msbuild_platform}"]) |
|
0 commit comments