Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ParseFlags so -stdlib goes in CXXFLAGS #4521

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
expected exceptions (whereas previously many of these were silently
caught and suppressed by the SCons Action exection code).

From Ryan Carsten Schmidt:
- Teach ParseFlags to put a --stdlib=libname argument into CXXFLAGS.
If placed in CCFLAGS (the default location), it could be fed to the
C compiler (gcc, clang) where it is not applicable and causes a
warning message.

From Mats Wichmann:
- Updated Value Node docs and tests.
- Python 3.13 compat: re.sub deprecated count, flags as positional args,
Expand Down
2 changes: 2 additions & 0 deletions RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ CHANGED/ENHANCED EXISTING FUNCTIONALITY
NOTE: With this change, user created Actions should now catch and handle
expected exceptions (whereas previously many of these were silently caught
and suppressed by the SCons Action exection code).
- ParseFlags now sorts a --stdlib=libname argument into CXXFLAGS instead
of CCFLAGS; the latter variable could cause a compiler warning.
- The implementation of Variables was slightly refactored, there should
not be user-visible changes.

Expand Down
10 changes: 7 additions & 3 deletions SCons/Environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,11 +881,11 @@ def ParseFlags(self, *flags) -> dict:
'RPATH' : [],
}

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

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

# Loop through the flags and add them to the appropriate option.
# Loop through the flags and add them to the appropriate variable.
# This tries to strike a balance between checking for all possible
# flags and keeping the logic to a finite size, so it doesn't
# check for some that don't occur often. It particular, if the
Expand All @@ -926,6 +926,8 @@ def append_define(name, mapping=mapping) -> None:
append_next_arg_to = None # for multi-word args
for arg in params:
if append_next_arg_to:
# these are the second pass for options where the
# option-argument follows as a second word.
if append_next_arg_to == 'CPPDEFINES':
append_define(arg)
elif append_next_arg_to == '-include':
Expand Down Expand Up @@ -1022,6 +1024,8 @@ def append_define(name, mapping=mapping) -> None:
else:
key = 'CFLAGS'
mapping[key].append(arg)
elif arg.startswith('-stdlib='):
mapping['CXXFLAGS'].append(arg)
elif arg[0] == '+':
mapping['CCFLAGS'].append(arg)
mapping['LINKFLAGS'].append(arg)
Expand Down
1 change: 1 addition & 0 deletions SCons/Environment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2687,6 +2687,7 @@ and added to the following construction variables:
-openmp CCFLAGS, LINKFLAGS
-pthread CCFLAGS, LINKFLAGS
-std= CFLAGS
-stdlib= CXXFLAGS
-Wa, ASFLAGS, CCFLAGS
-Wl,-rpath= RPATH
-Wl,-R, RPATH
Expand Down
3 changes: 2 additions & 1 deletion SCons/EnvironmentTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ def test_ParseFlags(self) -> None:
"-DFOO -DBAR=value -D BAZ "
"-fsanitize=memory "
"-fsanitize-address-use-after-return "
"-stdlib=libc++"
)

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