Skip to content

Commit

Permalink
Fix windows
Browse files Browse the repository at this point in the history
  • Loading branch information
savannahostrowski committed Jan 10, 2025
1 parent d6f91ff commit 437b0b4
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 54 deletions.
2 changes: 1 addition & 1 deletion PCbuild/regen.targets
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<_KeywordOutputs Include="$(PySourcePath)Lib\keyword.py" />
<!-- Taken from _Target._compute_digest in Tools\jit\_targets.py: -->
<_JITSources Include="$(PySourcePath)Python\executor_cases.c.h;$(GeneratedPyConfigDir)pyconfig.h;$(PySourcePath)Tools\jit\**"/>
<_JITOutputs Include="$(GeneratedPyConfigDir)jit_stencils.h"/>
<_JITOutputs Include="$(GeneratedPyConfigDir)jit_stencils.h;$(PySourcePath)Tools\jit\stencils\**"/>
<_CasesSources Include="$(PySourcePath)Python\bytecodes.c;$(PySourcePath)Python\optimizer_bytecodes.c;"/>
<_CasesOutputs Include="$(PySourcePath)Python\generated_cases.c.h;$(PySourcePath)Include\opcode_ids.h;$(PySourcePath)Include\internal\pycore_uop_ids.h;$(PySourcePath)Python\opcode_targets.h;$(PySourcePath)Include\internal\pycore_opcode_metadata.h;$(PySourcePath)Include\internal\pycore_uop_metadata.h;$(PySourcePath)Python\optimizer_cases.c.h;$(PySourcePath)Lib\_opcode_metadata.py"/>
<_SbomSources Include="$(PySourcePath)PCbuild\get_externals.bat" />
Expand Down
31 changes: 5 additions & 26 deletions Tools/jit/_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import pathlib
import re
import shutil
import sys
import tempfile
import typing
Expand Down Expand Up @@ -44,18 +45,6 @@ class _Target(typing.Generic[_S, _R]):
verbose: bool = False
known_symbols: dict[str, int] = dataclasses.field(default_factory=dict)

def _compute_digest(self, out: pathlib.Path) -> str:
hasher = hashlib.sha256()
hasher.update(self.triple.encode())
hasher.update(self.debug.to_bytes())
# These dependencies are also reflected in _JITSources in regen.targets:
hasher.update(PYTHON_EXECUTOR_CASES_C_H.read_bytes())
hasher.update((out / "pyconfig.h").read_bytes())
for dirpath, _, filenames in sorted(os.walk(TOOLS_JIT)):
for filename in filenames:
hasher.update(pathlib.Path(dirpath, filename).read_bytes())
return hasher.hexdigest()

async def _parse(self, path: pathlib.Path) -> _stencils.StencilGroup:
group = _stencils.StencilGroup()
args = ["--disassemble", "--reloc", f"{path}"]
Expand Down Expand Up @@ -177,41 +166,31 @@ async def _build_stencils(self) -> dict[str, _stencils.StencilGroup]:
return stencil_groups

def build(
self, out: pathlib.Path, *, comment: str = "", force: bool = False
self, out: pathlib.Path, *, force: bool = False
) -> None:
"""Build jit_stencils.h in the given directory."""
if not self.stable:
warning = f"JIT support for {self.triple} is still experimental!"
request = "Please report any issues you encounter.".center(len(warning))
outline = "=" * len(warning)
print("\n".join(["", outline, warning, request, outline, ""]))
digest = f"// {self._compute_digest(out)}\n"

target = self.triple
darwin_index = target.find("-darwin")
if darwin_index != -1:
target = self.triple[: darwin_index + len("-darwin")]

jit_stencils = out / "Tools" / "jit" / "stencils" / f"{target}.h"
jit_stencils = CPYTHON / "Tools" / "jit" / "stencils" / f"{target}.h"
print(f"Building {jit_stencils}...")
if (
not force
and jit_stencils.exists()
and jit_stencils.read_text().startswith(digest)
):
return
stencil_groups = asyncio.run(self._build_stencils())
jit_stencils_new = out / "Tools" / "jit" / "stencils" / f"{target}.h.new"
jit_stencils_new = CPYTHON / "Tools" / "jit" / "stencils" / f"{target}.h.new"
try:
with jit_stencils_new.open("w") as file:
file.write(digest)
if comment:
file.write(f"// {comment}\n")
file.write("\n")
for line in _writer.dump(stencil_groups, self.known_symbols):
file.write(f"{line}\n")
try:
jit_stencils_new.replace(jit_stencils)
shutil.copy(jit_stencils, out / "jit_stencils.h")
except FileNotFoundError:
# another process probably already moved the file
if not jit_stencils.is_file():
Expand Down
8 changes: 0 additions & 8 deletions Tools/jit/apply_stencil_patch.sh

This file was deleted.

3 changes: 1 addition & 2 deletions Tools/jit/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import _targets

if __name__ == "__main__":
comment = f"$ {shlex.join([pathlib.Path(sys.executable).name] + sys.argv)}"
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"target", type=_targets.get_target, help="a PEP 11 target triple to compile for"
Expand All @@ -25,4 +24,4 @@
args = parser.parse_args()
args.target.debug = args.debug
args.target.verbose = args.verbose
args.target.build(pathlib.Path.cwd(), comment=comment, force=args.force)
args.target.build(pathlib.Path.cwd(), force=args.force)
17 changes: 0 additions & 17 deletions jit_stencils.h

This file was deleted.

0 comments on commit 437b0b4

Please sign in to comment.