8000 Fix Windows build on setuptools that default to local distutils. · matplotlib/mplcairo@2991c72 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 2991c72

Browse files
committed
Fix Windows build on setuptools that default to local distutils.
1 parent e384090 commit 2991c72

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

tools/build-windows-wheel.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import shutil
2323
import subprocess
2424
import sys
25+
from tempfile import TemporaryDirectory
2526
import urllib.request
2627

2728
import cairo # Needed to load the cairo dll.
@@ -96,9 +97,28 @@ class L(list): __bool__ = lambda self: True
9697
be.run()
9798
cc = be.compiler
9899
cc.initialize()
100+
# On setuptools versions that use "local" distutils,
101+
# ``cc.spawn(["dumpbin", ...])`` and ``cc.spawn(["lib", ...])`` no longer
102+
# manage to locate the right executables, even though they are correctly on the
103+
# PATH; instead, use shutil.which to walk the PATH and get absolute executable
104+
# paths.
105+
with TemporaryDirectory() as tmpdir:
106+
dest = Path(dest, "path")
107+
cc.spawn([
108+
"python", "-c",
109+
f"from shutil import which; "
110+
f"print(which('dumpbin'), file=open({str(dest)!r}, 'w'), end='')",
111+
])
112+
dumpbin_path = dest.read_text()
113+
cc.spawn([
114+
"python", "-c",
115+
f"from shutil import which; "
116+
f"print(which('lib'), file=open({str(dest)!r}, 'w'), end='')",
117+
])
118+
lib_path = dest.read_text()
99119
# Build the import library.
100120
cc.spawn(
101-
["dumpbin", "/EXPORTS", "/OUT:cairo/win64/cairo.exports",
121+
[dumpbin_path, "/EXPORTS", "/OUT:cairo/win64/cairo.exports",
102122
"cairo/win64/cairo.dll"])
103123
with open("cairo/win64/cairo.exports") as raw_exports, \
104124
open("cairo/win64/cairo.def", "x") as def_file:
@@ -113,7 +133,7 @@ class L(list): __bool__ = lambda self: True
113133
continue
114134
def_file.write(name + "\n")
115135
cc.spawn(
116-
["lib", f"/DEF:{def_file.name}", "/MACHINE:x64",
136+
[lib_path, f"/DEF:{def_file.name}", "/MACHINE:x64",
117137
"/OUT:cairo/win64/cairo.lib"])
118138

119139
# Build the wheel.

0 commit comments

Comments
 (0)
0