|
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
|
@@ -628,6 +629,41 @@ def replace_in_all(search, replace):
|
628 | 629 | replace_in_file(SYSCONFIGDATA, search, replace)
|
629 | 630 |
|
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 | +
|
| 658 | +# Remove the Xcode path from the compiler flags. |
| 659 | +# |
| 660 | +# CPython itself will drop this from `sysconfig.get_config_var("CFLAGS")` and |
| 661 | +# similar calls, but _not_ if `CFLAGS` is set in the environment (regardless of |
| 662 | +# the `CFLAGS` value). It will almost always be wrong, so we drop it unconditionally. |
| 663 | +xcode_path = os.getenv("APPLE_SDK_PATH") |
| 664 | +if xcode_path: |
| 665 | + replace_in_all("-isysroot %s" % xcode_path, "") |
| 666 | +
|
631 | 667 | # -fdebug-default-version is Clang only. Strip so compiling works on GCC.
|
632 | 668 | replace_in_all("-fdebug-default-version=4", "")
|
633 | 669 |
|
|
0 commit comments