|
587 | 587 | # that a) it works on as many machines as possible b) doesn't leak details |
588 | 588 | # about the build environment, which is non-portable. |
589 | 589 | cat > ${ROOT}/hack_sysconfig.py << EOF |
| 590 | +import json |
590 | 591 | import os |
591 | 592 | import sys |
592 | 593 | import sysconfig |
@@ -627,6 +628,33 @@ def replace_in_all(search, replace): |
627 | 628 | replace_in_file(MAKEFILE, search, replace) |
628 | 629 | replace_in_file(SYSCONFIGDATA, search, replace) |
629 | 630 |
|
| 631 | +
|
| 632 | +def format_sysconfigdata(): |
| 633 | + """Reformat the sysconfigdata file to avoid implicit string concatenations. |
| 634 | +
|
| 635 | + In some Python versions, the sysconfigdata file contains implicit string |
| 636 | + concatenations that extend over multiple lines, which make string replacement |
| 637 | + much harder. This function reformats the file to avoid this issue. |
| 638 | +
|
| 639 | + See: https://github.com/python/cpython/blob/a03efb533a58fd13fb0cc7f4a5c02c8406a407bd/Mac/BuildScript/build-installer.py#L1360C1-L1385C15. |
| 640 | + """ |
| 641 | + with open(SYSCONFIGDATA, "rb") as fh: |
| 642 | + data = fh.read() |
| 643 | +
|
| 644 | + globals_dict = {} |
| 645 | + locals_dict = {} |
| 646 | + exec(data, globals_dict, locals_dict) |
| 647 | + build_time_vars = locals_dict['build_time_vars'] |
| 648 | +
|
| 649 | + with open(SYSCONFIGDATA, "wb") as fh: |
| 650 | + fh.write(b'# system configuration generated and used by the sysconfig module\n') |
| 651 | + fh.write(('build_time_vars = %s' % json.dumps(build_time_vars, indent=4)).encode("utf-8")) |
| 652 | + fh.close() |
| 653 | +
|
| 654 | +
|
| 655 | +# Format sysconfig to ensure that string replacements take effect. |
| 656 | +format_sysconfigdata() |
| 657 | +
|
630 | 658 | # Remove the Xcode path from the compiler flags. |
631 | 659 | # |
632 | 660 | # CPython itself will drop this from `sysconfig.get_config_var("CFLAGS")` and |
|
0 commit comments