Skip to content

Commit 3e6a7ac

Browse files
authored
Merge pull request SCons#4521 from mwichmann/finish-4520
Fix ParseFlags so -stdlib goes in CXXFLAGS
2 parents 4202208 + 561a862 commit 3e6a7ac

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

CHANGES.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
2222
expected exceptions (whereas previously many of these were silently
2323
caught and suppressed by the SCons Action exection code).
2424

25+
From Ryan Carsten Schmidt:
26+
- Teach ParseFlags to put a --stdlib=libname argument into CXXFLAGS.
27+
If placed in CCFLAGS (the default location), it could be fed to the
28+
C compiler (gcc, clang) where it is not applicable and causes a
29+
warning message.
30+
2531
From Mats Wichmann:
2632
- Updated Value Node docs and tests.
2733
- Python 3.13 compat: re.sub deprecated count, flags as positional args,

RELEASE.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ CHANGED/ENHANCED EXISTING FUNCTIONALITY
3939
NOTE: With this change, user created Actions should now catch and handle
4040
expected exceptions (whereas previously many of these were silently caught
4141
and suppressed by the SCons Action exection code).
42+
- ParseFlags now sorts a --stdlib=libname argument into CXXFLAGS instead
43+
of CCFLAGS; the latter variable could cause a compiler warning.
4244
- The implementation of Variables was slightly refactored, there should
4345
not be user-visible changes.
4446

SCons/Environment.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -881,11 +881,11 @@ def ParseFlags(self, *flags) -> dict:
881881
'RPATH' : [],
882882
}
883883

884-
def do_parse(arg) -> None:
885-
# if arg is a sequence, recurse with each element
884+
def do_parse(arg: Union[str, Sequence]) -> None:
886885
if not arg:
887886
return
888887

888+
# if arg is a sequence, recurse with each element
889889
if not is_String(arg):
890890
for t in arg: do_parse(t)
891891
return
@@ -902,7 +902,7 @@ def append_define(name, mapping=mapping) -> None:
902902
else:
903903
mapping['CPPDEFINES'].append([t[0], '='.join(t[1:])])
904904

905-
# Loop through the flags and add them to the appropriate option.
905+
# Loop through the flags and add them to the appropriate variable.
906906
# This tries to strike a balance between checking for all possible
907907
# flags and keeping the logic to a finite size, so it doesn't
908908
# check for some that don't occur often. It particular, if the
@@ -926,6 +926,8 @@ def append_define(name, mapping=mapping) -> None:
926926
append_next_arg_to = None # for multi-word args
927927
for arg in params:
928928
if append_next_arg_to:
929+
# these are the second pass for options where the
930+
# option-argument follows as a second word.
929931
if append_next_arg_to == 'CPPDEFINES':
930932
append_define(arg)
931933
elif append_next_arg_to == '-include':
@@ -1022,6 +1024,8 @@ def append_define(name, mapping=mapping) -> None:
10221024
else:
10231025
key = 'CFLAGS'
10241026
mapping[key].append(arg)
1027+
elif arg.startswith('-stdlib='):
1028+
mapping['CXXFLAGS'].append(arg)
10251029
elif arg[0] == '+':
10261030
mapping['CCFLAGS'].append(arg)
10271031
mapping['LINKFLAGS'].append(arg)

SCons/Environment.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2687,6 +2687,7 @@ and added to the following construction variables:
26872687
-openmp CCFLAGS, LINKFLAGS
26882688
-pthread CCFLAGS, LINKFLAGS
26892689
-std= CFLAGS
2690+
-stdlib= CXXFLAGS
26902691
-Wa, ASFLAGS, CCFLAGS
26912692
-Wl,-rpath= RPATH
26922693
-Wl,-R, RPATH

SCons/EnvironmentTests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ def test_ParseFlags(self) -> None:
822822
"-DFOO -DBAR=value -D BAZ "
823823
"-fsanitize=memory "
824824
"-fsanitize-address-use-after-return "
825+
"-stdlib=libc++"
825826
)
826827

827828
d = env.ParseFlags(s)
@@ -841,7 +842,7 @@ def test_ParseFlags(self) -> None:
841842
'+DD64',
842843
'-fsanitize=memory',
843844
'-fsanitize-address-use-after-return'], repr(d['CCFLAGS'])
844-
assert d['CXXFLAGS'] == ['-std=c++0x'], repr(d['CXXFLAGS'])
845+
assert d['CXXFLAGS'] == ['-std=c++0x', '-stdlib=libc++'], repr(d['CXXFLAGS'])
845846
assert d['CPPDEFINES'] == ['FOO', ['BAR', 'value'], 'BAZ'], d['CPPDEFINES']
846847
assert d['CPPFLAGS'] == ['-Wp,-cpp'], d['CPPFLAGS']
847848
assert d['CPPPATH'] == ['/usr/include/fum',

0 commit comments

Comments
 (0)