@@ -47,6 +47,7 @@ class _Target(typing.Generic[_S, _R]):
47
47
debug : bool = False
48
48
verbose : bool = False
49
49
known_symbols : dict [str , int ] = dataclasses .field (default_factory = dict )
50
+ pyconfig_dir : pathlib .Path = pathlib .Path .cwd ().resolve ()
50
51
51
52
def _get_nop (self ) -> bytes :
52
53
if re .fullmatch (r"aarch64-.*" , self .triple ):
@@ -57,13 +58,13 @@ def _get_nop(self) -> bytes:
57
58
raise ValueError (f"NOP not defined for { self .triple } " )
58
59
return nop
59
60
60
- def _compute_digest (self , out : pathlib . Path ) -> str :
61
+ def _compute_digest (self ) -> str :
61
62
hasher = hashlib .sha256 ()
62
63
hasher .update (self .triple .encode ())
63
64
hasher .update (self .debug .to_bytes ())
64
65
# These dependencies are also reflected in _JITSources in regen.targets:
65
66
hasher .update (PYTHON_EXECUTOR_CASES_C_H .read_bytes ())
66
- hasher .update ((out / "pyconfig.h" ).read_bytes ())
67
+ hasher .update ((self . pyconfig_dir / "pyconfig.h" ).read_bytes ())
67
68
for dirpath , _ , filenames in sorted (os .walk (TOOLS_JIT )):
68
69
for filename in filenames :
69
70
hasher .update (pathlib .Path (dirpath , filename ).read_bytes ())
@@ -125,7 +126,7 @@ async def _compile(
125
126
f"-D_JIT_OPCODE={ opname } " ,
126
127
"-D_PyJIT_ACTIVE" ,
127
128
"-D_Py_JIT" ,
128
- "-I. " ,
129
+ f "-I{ self . pyconfig_dir } " ,
129
130
f"-I{ CPYTHON / 'Include' } " ,
130
131
f"-I{ CPYTHON / 'Include' / 'internal' } " ,
131
132
f"-I{ CPYTHON / 'Include' / 'internal' / 'mimalloc' } " ,
@@ -193,28 +194,27 @@ async def _build_stencils(self) -> dict[str, _stencils.StencilGroup]:
193
194
194
195
def build (
195
196
self ,
196
- out : pathlib .Path ,
197
197
* ,
198
198
comment : str = "" ,
199
199
force : bool = False ,
200
- stencils_h : str = "jit_stencils.h" ,
200
+ jit_stencils : pathlib . Path ,
201
201
) -> None :
202
202
"""Build jit_stencils.h in the given directory."""
203
+ jit_stencils .parent .mkdir (parents = True , exist_ok = True )
203
204
if not self .stable :
204
205
warning = f"JIT support for { self .triple } is still experimental!"
205
206
request = "Please report any issues you encounter." .center (len (warning ))
206
207
outline = "=" * len (warning )
207
208
print ("\n " .join (["" , outline , warning , request , outline , "" ]))
208
- digest = f"// { self ._compute_digest (out )} \n "
209
- jit_stencils = out / stencils_h
209
+ digest = f"// { self ._compute_digest ()} \n "
210
210
if (
211
211
not force
212
212
and jit_stencils .exists ()
213
213
and jit_stencils .read_text ().startswith (digest )
214
214
):
215
215
return
216
216
stencil_groups = ASYNCIO_RUNNER .run (self ._build_stencils ())
217
- jit_stencils_new = out / "jit_stencils.h.new"
217
+ jit_stencils_new = jit_stencils . parent / "jit_stencils.h.new"
218
218
try :
219
219
with jit_stencils_new .open ("w" ) as file :
220
220
file .write (digest )
0 commit comments