Debian Codegraph @

Tools/jit/build.py

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 """Build an experimental just-in-time compiler for CPython."""
2
3 import argparse
4 import pathlib
5 import shlex
6 import sys
7
8 import _targets
9
10 if __name__ == "__main__":
11 comment = f"$ {shlex.join([pathlib.Path(sys.executable).name] + sys.argv)}"
12 parser = argparse.ArgumentParser(description=__doc__)
13 parser.add_argument(
14 "target",
15 nargs="+",
16 type=_targets.get_target,
17 help="a PEP 11 target triple to compile for",
18 )
19 parser.add_argument(
20 "-d", "--debug", action="store_true", help="compile for a debug build of Python"
21 )
22 parser.add_argument(
23 "-f", "--force", action="store_true", help="force the entire JIT to be rebuilt"
24 )
25 parser.add_argument(
26 "-o",
27 "--output-dir",
28 help="where to output generated files",
29 required=True,
30 type=lambda p: pathlib.Path(p).resolve(),
31 )
32 parser.add_argument(
33 "-p",
34 "--pyconfig-dir",
35 help="where to find pyconfig.h",
36 required=True,
37 type=lambda p: pathlib.Path(p).resolve(),
38 )
39 parser.add_argument(
40 "-v", "--verbose", action="store_true", help="echo commands as they are run"
41 )
42 parser.add_argument(
43 "--cflags", help="additional flags to pass to the compiler", default=""
44 )
45 args = parser.parse_args()
46 for target in args.target:
47 target.debug = args.debug
48 target.force = args.force
49 target.verbose = args.verbose
50 target.cflags = args.cflags
51 target.pyconfig_dir = args.pyconfig_dir
52 target.build(
53 comment=comment,
54 force=args.force,
55 jit_stencils=args.output_dir / f"jit_stencils-{target.triple}.h",
56 )
57 jit_stencils_h = args.output_dir / "jit_stencils.h"
58 lines = [f"// {comment}\n"]
59 guard = "#if"
60 for target in args.target:
61 lines.append(f"{guard} {target.condition}\n")
62 lines.append(f'#include "jit_stencils-{target.triple}.h"\n')
63 guard = "#elif"
64 lines.append("#else\n")
65 lines.append('#error "unexpected target"\n')
66 lines.append("#endif\n")
67 body = "".join(lines)
68 # Don't touch the file if it hasn't changed (so we don't trigger a rebuild):
69 if not jit_stencils_h.is_file() or jit_stencils_h.read_text() != body:
70 jit_stencils_h.write_text(body)