Skip to content

Commit 0655040

Browse files
committed
gh-161805: Match -arch ARG at the end of the string too
Drop the following \s so the -arch argument matches before either whitespace or end-of-string. Replace with '' (rather than ' ') correspondingly, to preserve existing rewriting behaviour.
1 parent 91ab655 commit 0655040

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎Lib/_osx_support.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def _remove_universal_flags(_config_vars):
265265
# Do not alter a config var explicitly overridden by env var
266266
if cv in _config_vars and cv not in os.environ:
267267
flags = _config_vars[cv]
268-
flags = re.sub(r'-arch\s+\w+\s', ' ', flags, flags=re.ASCII)
268+
flags = re.sub(r'-arch\s+\S+', '', flags, flags=re.ASCII)
269269
flags = re.sub(r'-isysroot\s*\S+', ' ', flags)
270270
_save_modified_value(_config_vars, cv, flags)
271271

@@ -306,7 +306,7 @@ def _remove_unsupported_archs(_config_vars):
306306
for cv in _UNIVERSAL_CONFIG_VARS:
307307
if cv in _config_vars and cv not in os.environ:
308308
flags = _config_vars[cv]
309-
flags = re.sub(r'-arch\s+ppc\w*\s', ' ', flags)
309+
flags = re.sub(r'-arch\s+ppc\S*', '', flags)
310310
_save_modified_value(_config_vars, cv, flags)
311311

312312
return _config_vars
@@ -322,7 +322,7 @@ def _override_all_archs(_config_vars):
322322
for cv in _UNIVERSAL_CONFIG_VARS:
323323
if cv in _config_vars and '-arch' in _config_vars[cv]:
324324
flags = _config_vars[cv]
325-
flags = re.sub(r'-arch\s+\w+\s', ' ', flags)
325+
flags = re.sub(r'-arch\s+\S+', '', flags)
326326
flags = flags + ' ' + arch
327327
_save_modified_value(_config_vars, cv, flags)
328328

‎Lib/test/test__osx_support.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def test__find_appropriate_compiler(self):
155155
def test__remove_universal_flags(self):
156156
config_vars = {
157157
'CFLAGS': '-fno-strict-aliasing -g -O3 -arch ppc -arch i386 ',
158+
'BASECFLAGS': '-O3 -arch i386 -arch ppc',
158159
'LDFLAGS': '-arch ppc -arch i386 -g',
159160
'CPPFLAGS': '-I. -isysroot /Developer/SDKs/MacOSX10.4u.sdk',
160161
'BLDSHARED': 'gcc-4.0 -bundle -arch ppc -arch i386 -g',
@@ -163,6 +164,7 @@ def test__remove_universal_flags(self):
163164
}
164165
expected_vars = {
165166
'CFLAGS': '-fno-strict-aliasing -g -O3 ',
167+
'BASECFLAGS': '-O3 ',
166168
'LDFLAGS': ' -g',
167169
'CPPFLAGS': '-I. ',
168170
'BLDSHARED': 'gcc-4.0 -bundle -g',
@@ -201,6 +203,7 @@ def test__remove_unsupported_archs(self):
201203
config_vars = {
202204
'CC': 'clang',
203205
'CFLAGS': '-fno-strict-aliasing -g -O3 -arch ppc -arch i386 ',
206+
'BASECFLAGS': '-O3 -arch i386 -arch ppc64',
204207
'LDFLAGS': '-arch ppc -arch i386 -g',
205208
'CPPFLAGS': '-I. -isysroot /Developer/SDKs/MacOSX10.4u.sdk',
206209
'BLDSHARED': 'gcc-4.0 -bundle -arch ppc -arch i386 -g',
@@ -210,6 +213,7 @@ def test__remove_unsupported_archs(self):
210213
expected_vars = {
211214
'CC': 'clang',
212215
'CFLAGS': '-fno-strict-aliasing -g -O3 -arch i386 ',
216+
'BASECFLAGS': '-O3 -arch i386 ',
213217
'LDFLAGS': ' -arch i386 -g',
214218
'CPPFLAGS': '-I. -isysroot /Developer/SDKs/MacOSX10.4u.sdk',
215219
'BLDSHARED': 'gcc-4.0 -bundle -arch i386 -g',
@@ -236,6 +240,7 @@ def test__override_all_archs(self):
236240
config_vars = {
237241
'CC': 'clang',
238242
'CFLAGS': '-fno-strict-aliasing -g -O3 -arch ppc -arch i386 ',
243+
'BASECFLAGS': '-O3 -arch i386 -arch ppc',
239244
'LDFLAGS': '-arch ppc -arch i386 -g',
240245
'CPPFLAGS': '-I. -isysroot /Developer/SDKs/MacOSX10.4u.sdk',
241246
'BLDSHARED': 'gcc-4.0 -bundle -arch ppc -arch i386 -g',
@@ -245,6 +250,7 @@ def test__override_all_archs(self):
245250
expected_vars = {
246251
'CC': 'clang',
247252
'CFLAGS': '-fno-strict-aliasing -g -O3 -arch x86_64',
253+
'BASECFLAGS': '-O3 -arch x86_64',
248254
'LDFLAGS': ' -g -arch x86_64',
249255
'CPPFLAGS': '-I. -isysroot /Developer/SDKs/MacOSX10.4u.sdk',
250256
'BLDSHARED': 'gcc-4.0 -bundle -g -arch x86_64',
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix :func:`sysconfig.get_config_vars` so that it adjusts ``-arch`` options
2+
on macOS even when they appear at the very end of ``CFLAGS`` et al.

0 commit comments

Comments
 (0)