Skip to content

Commit 8d40405

Browse files
committed
Reformat sysconfig
1 parent eaa7556 commit 8d40405

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

.github/workflows/apple.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,20 @@ jobs:
4545
fail-fast: false
4646
matrix:
4747
build:
48+
- target_triple: 'aarch64-apple-darwin'
49+
runner: macos-14
50+
py: 'cpython-3.9'
51+
options: 'debug'
52+
53+
- target_triple: 'aarch64-apple-darwin'
54+
runner: macos-14
55+
py: 'cpython-3.12'
56+
options: 'debug'
57+
4858
- target_triple: 'aarch64-apple-darwin'
4959
runner: macos-14
5060
py: 'cpython-3.13'
51-
options: 'freethreaded+debug'
61+
options: 'debug'
5262
needs:
5363
- pythonbuild
5464
runs-on: ${{ matrix.build.runner }}

cpython-unix/build-cpython.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ fi
587587
# that a) it works on as many machines as possible b) doesn't leak details
588588
# about the build environment, which is non-portable.
589589
cat > ${ROOT}/hack_sysconfig.py << EOF
590+
import json
590591
import os
591592
import sys
592593
import sysconfig
@@ -627,6 +628,33 @@ def replace_in_all(search, replace):
627628
replace_in_file(MAKEFILE, search, replace)
628629
replace_in_file(SYSCONFIGDATA, search, replace)
629630
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+
630658
# Remove the Xcode path from the compiler flags.
631659
#
632660
# CPython itself will drop this from `sysconfig.get_config_var("CFLAGS")` and

0 commit comments

Comments
 (0)