diff --git a/SCons/Defaults.py b/SCons/Defaults.py index c0e7afc174..49e9cc48d7 100644 --- a/SCons/Defaults.py +++ b/SCons/Defaults.py @@ -462,6 +462,7 @@ def _stripixes( stripprefixes: str, stripsuffixes: str, env, + literal_prefix: str = "", c: Callable[[list], list] = None, ) -> list: """Returns a list with text added to items after first stripping them. @@ -498,14 +499,13 @@ def _stripixes( stripprefixes = list(map(env.subst, flatten(stripprefixes))) stripsuffixes = list(map(env.subst, flatten(stripsuffixes))) - # This is a little funky: if $LIBLITERAL is the same as os.pathsep + # This is a little funky: if literal_prefix is the same as os.pathsep # (e.g. both ':'), the normal conversion to a PathList will drop the - # $LIBLITERAL prefix. Tell it not to split in that case, which *should* + # literal_prefix prefix. Tell it not to split in that case, which *should* # be okay because if we come through here, we're normally processing # library names and won't have strings like "path:secondpath:thirdpath" # which is why PathList() otherwise wants to split strings. - libliteral = env.get('LIBLITERAL') - do_split = not libliteral == os.pathsep + do_split = not literal_prefix == os.pathsep stripped = [] for l in SCons.PathList.PathList(items, do_split).subst_path(env, None, None): @@ -516,7 +516,7 @@ def _stripixes( if not is_String(l): l = str(l) - if libliteral and l.startswith(libliteral): + if literal_prefix and l.startswith(literal_prefix): stripped.append(l) continue diff --git a/SCons/EnvironmentTests.py b/SCons/EnvironmentTests.py index 756e05592f..b1b6a0d648 100644 --- a/SCons/EnvironmentTests.py +++ b/SCons/EnvironmentTests.py @@ -1538,9 +1538,20 @@ def test__stripixes(self) -> None: LIBSUFFIXES=['.yyy'], LIBLITERAL='zz', ) - x = e.subst('$( ${_stripixes(PRE, LIST, SUF, LIBPREFIXES, LIBSUFFIXES,__env__)} $)') + x = e.subst('$( ${_stripixes(PRE, LIST, SUF, LIBPREFIXES, LIBSUFFIXES,__env__, LIBLITERAL)} $)') self.assertEqual(x, 'preasuf prebsuf prezzxxx-c.yyysuf') + # Test that setting literal_prefix (in this case LIBLITERAL) + # same as os.pathsep disables the literal protection + e['LIBLITERAL'] = os.pathsep + x = e.subst('$( ${_stripixes(PRE, LIST, SUF, LIBPREFIXES, LIBSUFFIXES,__env__, LIBLITERAL)} $)') + self.assertEqual(x, 'preasuf prebsuf prezzxxx-csuf') + + # Test that setting not settingliteral_prefix doesn't fail + x = e.subst('$( ${_stripixes(PRE, LIST, SUF, LIBPREFIXES, LIBSUFFIXES,__env__)} $)') + self.assertEqual(x, 'preasuf prebsuf prezzxxx-csuf') + + def test_gvars(self) -> None: """Test the Environment gvars() method""" diff --git a/SCons/Tool/dmd.py b/SCons/Tool/dmd.py index 13e9e7e446..7b95775362 100644 --- a/SCons/Tool/dmd.py +++ b/SCons/Tool/dmd.py @@ -138,7 +138,7 @@ def generate(env) -> None: env['DLIBLINKPREFIX'] = '' if env['PLATFORM'] == 'win32' else '-L-l' env['DLIBLINKSUFFIX'] = '.lib' if env['PLATFORM'] == 'win32' else '' - env['_DLIBFLAGS'] = '${_stripixes(DLIBLINKPREFIX, LIBS, DLIBLINKSUFFIX, LIBPREFIXES, LIBSUFFIXES, __env__)}' + env['_DLIBFLAGS'] = '${_stripixes(DLIBLINKPREFIX, LIBS, DLIBLINKSUFFIX, LIBPREFIXES, LIBSUFFIXES, __env__, LIBLITERAL)}' env['DLIBDIRPREFIX'] = '-L-L' env['DLIBDIRSUFFIX'] = '' diff --git a/SCons/Tool/ldc.py b/SCons/Tool/ldc.py index bd0767e7f5..b557134fe1 100644 --- a/SCons/Tool/ldc.py +++ b/SCons/Tool/ldc.py @@ -73,7 +73,7 @@ def generate(env) -> None: env['_DDEBUGFLAGS'] = '${_concat(DDEBUGPREFIX, DDEBUG, DDEBUGSUFFIX, __env__)}' env['_DI_FLAGS'] = "${DI_FILE_DIR and DI_FILE_DIR_PREFIX+DI_FILE_DIR+DI_FILE_DIR_SUFFFIX}" - + env['_DFLAGS'] = '${_concat(DFLAGPREFIX, DFLAGS, DFLAGSUFFIX, __env__)}' env['SHDC'] = '$DC' @@ -96,10 +96,10 @@ def generate(env) -> None: env['DFLAGPREFIX'] = '-' env['DFLAGSUFFIX'] = '' env['DFILESUFFIX'] = '.d' - + env['DI_FILE_DIR'] = '' env['DI_FILE_SUFFIX'] = '.di' - + env['DI_FILE_DIR_PREFIX'] = '-Hd=' env['DI_FILE_DIR_SUFFFIX'] = '' @@ -115,7 +115,7 @@ def generate(env) -> None: env['DLIBLINKPREFIX'] = '' if env['PLATFORM'] == 'win32' else '-L-l' env['DLIBLINKSUFFIX'] = '.lib' if env['PLATFORM'] == 'win32' else '' # env['_DLIBFLAGS'] = '${_concat(DLIBLINKPREFIX, LIBS, DLIBLINKSUFFIX, __env__, RDirs, TARGET, SOURCE)}' - env['_DLIBFLAGS'] = '${_stripixes(DLIBLINKPREFIX, LIBS, DLIBLINKSUFFIX, LIBPREFIXES, LIBSUFFIXES, __env__)}' + env['_DLIBFLAGS'] = '${_stripixes(DLIBLINKPREFIX, LIBS, DLIBLINKSUFFIX, LIBPREFIXES, LIBSUFFIXES, __env__, LIBLITERAL)}' env['DLIBDIRPREFIX'] = '-L-L' env['DLIBDIRSUFFIX'] = '' diff --git a/SCons/Tool/link.py b/SCons/Tool/link.py index e879ae8623..bfebc5def5 100644 --- a/SCons/Tool/link.py +++ b/SCons/Tool/link.py @@ -55,7 +55,7 @@ def generate(env) -> None: env['LINKCOM'] = '$LINK -o $TARGET $LINKFLAGS $__RPATH $SOURCES $_LIBDIRFLAGS $_LIBFLAGS' env['LIBDIRPREFIX'] = '-L' env['LIBDIRSUFFIX'] = '' - env['_LIBFLAGS'] = '${_stripixes(LIBLINKPREFIX, LIBS, LIBLINKSUFFIX, LIBPREFIXES, LIBSUFFIXES, __env__)}' + env['_LIBFLAGS'] = '${_stripixes(LIBLINKPREFIX, LIBS, LIBLINKSUFFIX, LIBPREFIXES, LIBSUFFIXES, __env__, LIBLITERAL)}' env['LIBLINKPREFIX'] = '-l' env['LIBLINKSUFFIX'] = ''