22
22
import shutil
23
23
import subprocess
24
24
import sys
25
+ from tempfile import TemporaryDirectory
25
26
import urllib .request
26
27
27
28
import cairo # Needed to load the cairo dll.
@@ -96,9 +97,28 @@ class L(list): __bool__ = lambda self: True
96
97
be .run ()
97
98
cc = be .compiler
98
99
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 ()
99
119
# Build the import library.
100
120
cc .spawn (
101
- ["dumpbin" , "/EXPORTS" , "/OUT:cairo/win64/cairo.exports" ,
121
+ [dumpbin_path , "/EXPORTS" , "/OUT:cairo/win64/cairo.exports" ,
102
122
"cairo/win64/cairo.dll" ])
103
123
with open ("cairo/win64/cairo.exports" ) as raw_exports , \
104
124
open ("cairo/win64/cairo.def" , "x" ) as def_file :
@@ -113,7 +133,7 @@ class L(list): __bool__ = lambda self: True
113
133
continue
114
134
def_file .write (name + "\n " )
115
135
cc .spawn (
116
- ["lib" , f"/DEF:{ def_file .name } " , "/MACHINE:x64" ,
136
+ [lib_path , f"/DEF:{ def_file .name } " , "/MACHINE:x64" ,
117
137
"/OUT:cairo/win64/cairo.lib" ])
118
138
119
139
# Build the wheel.
0 commit comments