Skip to content

Commit

Permalink
switch from embedding LIBLITERAL in _stripixes() to being a passed ar…
Browse files Browse the repository at this point in the history
…gument with a False default value, and add properly passing LIBLITERAL in link, dmd, ldc tools where _stripixes() is actually used in current SCons Code (#10)
  • Loading branch information
bdbaddog authored Oct 26, 2023
1 parent 2a52282 commit 07e3ddf
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
10 changes: 5 additions & 5 deletions SCons/Defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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):
Expand All @@ -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

Expand Down
13 changes: 12 additions & 1 deletion SCons/EnvironmentTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
2 changes: 1 addition & 1 deletion SCons/Tool/dmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = ''
Expand Down
8 changes: 4 additions & 4 deletions SCons/Tool/ldc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'] = ''

Expand All @@ -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'] = ''
Expand Down
2 changes: 1 addition & 1 deletion SCons/Tool/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = ''

Expand Down

0 comments on commit 07e3ddf

Please sign in to comment.