Skip to content

Commit

Permalink
Remove -Werror=unguarded-availability-new from sysconfig data (#422)
Browse files Browse the repository at this point in the history
## Summary

Per #210, we now strip `-Werror=unguarded-availability-new` from `CFLAGS` and `CPPFLAGS` (but not, e.g., `CONFIGURE_CFLAGS`).

Closes #210.
  • Loading branch information
charliermarsh authored Dec 17, 2024
1 parent ba4532d commit 12eeb3e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions cpython-unix/build-cpython.sh
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,26 @@ def replace_in_all(search, replace):
replace_in_file(SYSCONFIGDATA, search, replace)
def replace_in_sysconfigdata(search, replace, keys):
"""Replace a string in the sysconfigdata file for select keys."""
with open(SYSCONFIGDATA, "rb") as fh:
data = fh.read()
globals_dict = {}
locals_dict = {}
exec(data, globals_dict, locals_dict)
build_time_vars = locals_dict['build_time_vars']
for key in keys:
if key in build_time_vars:
build_time_vars[key] = build_time_vars[key].replace(search, replace)
with open(SYSCONFIGDATA, "wb") as fh:
fh.write(b'# system configuration generated and used by the sysconfig module\n')
fh.write(('build_time_vars = %s' % json.dumps(build_time_vars, indent=4, sort_keys=True)).encode("utf-8"))
fh.close()
def format_sysconfigdata():
"""Reformat the sysconfigdata file to avoid implicit string concatenations.
Expand All @@ -670,6 +690,18 @@ def format_sysconfigdata():
# Format sysconfig to ensure that string replacements take effect.
format_sysconfigdata()
# Remove `-Werror=unguarded-availability-new` from `CFLAGS` and `CPPFLAGS`.
# These flags are passed along when building extension modules. In that context,
# `-Werror=unguarded-availability-new` can cause builds that would otherwise
# succeed to fail. While the issues raised by `-Werror=unguarded-availability-new`
# are legitimate, enforcing them in extension modules is stricter than CPython's
# own behavior.
replace_in_sysconfigdata(
"-Werror=unguarded-availability-new",
"",
["CFLAGS", "CPPFLAGS"],
)
# Remove the Xcode path from the compiler flags.
#
# CPython itself will drop this from `sysconfig.get_config_var("CFLAGS")` and
Expand Down

0 comments on commit 12eeb3e

Please sign in to comment.