|
2 | 2 |
|
3 | 3 | import asyncio |
4 | 4 | import dataclasses |
5 | | -import hashlib |
6 | 5 | import json |
7 | | -import os |
8 | 6 | import pathlib |
9 | 7 | import re |
| 8 | +import shutil |
10 | 9 | import sys |
11 | 10 | import tempfile |
12 | 11 | import typing |
@@ -44,18 +43,6 @@ class _Target(typing.Generic[_S, _R]): |
44 | 43 | verbose: bool = False |
45 | 44 | known_symbols: dict[str, int] = dataclasses.field(default_factory=dict) |
46 | 45 |
|
47 | | - def _compute_digest(self, out: pathlib.Path) -> str: |
48 | | - hasher = hashlib.sha256() |
49 | | - hasher.update(self.triple.encode()) |
50 | | - hasher.update(self.debug.to_bytes()) |
51 | | - # These dependencies are also reflected in _JITSources in regen.targets: |
52 | | - hasher.update(PYTHON_EXECUTOR_CASES_C_H.read_bytes()) |
53 | | - hasher.update((out / "pyconfig.h").read_bytes()) |
54 | | - for dirpath, _, filenames in sorted(os.walk(TOOLS_JIT)): |
55 | | - for filename in filenames: |
56 | | - hasher.update(pathlib.Path(dirpath, filename).read_bytes()) |
57 | | - return hasher.hexdigest() |
58 | | - |
59 | 46 | async def _parse(self, path: pathlib.Path) -> _stencils.StencilGroup: |
60 | 47 | group = _stencils.StencilGroup() |
61 | 48 | args = ["--disassemble", "--reloc", f"{path}"] |
@@ -176,35 +163,28 @@ async def _build_stencils(self) -> dict[str, _stencils.StencilGroup]: |
176 | 163 | ) |
177 | 164 | return stencil_groups |
178 | 165 |
|
179 | | - def build( |
180 | | - self, out: pathlib.Path, *, comment: str = "", force: bool = False |
181 | | - ) -> None: |
| 166 | + def build(self, out: pathlib.Path, *, force: bool = False) -> None: |
182 | 167 | """Build jit_stencils.h in the given directory.""" |
183 | 168 | if not self.stable: |
184 | 169 | warning = f"JIT support for {self.triple} is still experimental!" |
185 | 170 | request = "Please report any issues you encounter.".center(len(warning)) |
186 | 171 | outline = "=" * len(warning) |
187 | 172 | print("\n".join(["", outline, warning, request, outline, ""])) |
188 | | - digest = f"// {self._compute_digest(out)}\n" |
189 | | - jit_stencils = out / "jit_stencils.h" |
190 | | - if ( |
191 | | - not force |
192 | | - and jit_stencils.exists() |
193 | | - and jit_stencils.read_text().startswith(digest) |
194 | | - ): |
195 | | - return |
| 173 | + target = self.triple |
| 174 | + darwin_index = target.find("-darwin") |
| 175 | + if darwin_index != -1: |
| 176 | + target = self.triple[: darwin_index + len("-darwin")] |
| 177 | + |
| 178 | + jit_stencils = CPYTHON / "Tools" / "jit" / "stencils" / f"{target}.h" |
196 | 179 | stencil_groups = asyncio.run(self._build_stencils()) |
197 | | - jit_stencils_new = out / "jit_stencils.h.new" |
| 180 | + jit_stencils_new = CPYTHON / "Tools" / "jit" / "stencils" / f"{target}.h.new" |
198 | 181 | try: |
199 | | - with jit_stencils_new.open("w") as file: |
200 | | - file.write(digest) |
201 | | - if comment: |
202 | | - file.write(f"// {comment}\n") |
203 | | - file.write("\n") |
| 182 | + with jit_stencils_new.open("w", newline="\n") as file: |
204 | 183 | for line in _writer.dump(stencil_groups, self.known_symbols): |
205 | 184 | file.write(f"{line}\n") |
206 | 185 | try: |
207 | 186 | jit_stencils_new.replace(jit_stencils) |
| 187 | + shutil.copy(jit_stencils, out / "jit_stencils.h") |
208 | 188 | except FileNotFoundError: |
209 | 189 | # another process probably already moved the file |
210 | 190 | if not jit_stencils.is_file(): |
|
0 commit comments