summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Klimkin <klimkin@gmail.com>2015-01-20 21:26:56 (GMT)
committerAlexey Klimkin <klimkin@gmail.com>2015-01-20 21:26:56 (GMT)
commit8e4b5aca7a47a60ed3a5f0b98bf0804e91e182b4 (patch)
tree13427f02edd42e3a0fde536c550c161102891b39
parent505226b97a4aaf41695e3e1c818f768e35565bf9 (diff)
downloadSCons-8e4b5aca7a47a60ed3a5f0b98bf0804e91e182b4.zip
SCons-8e4b5aca7a47a60ed3a5f0b98bf0804e91e182b4.tar.gz
SCons-8e4b5aca7a47a60ed3a5f0b98bf0804e91e182b4.tar.bz2
Improve readability of LIB substitution code
-rw-r--r--src/engine/SCons/Scanner/Prog.py22
-rw-r--r--src/engine/SCons/Scanner/ProgTests.py11
2 files changed, 17 insertions, 16 deletions
diff --git a/src/engine/SCons/Scanner/Prog.py b/src/engine/SCons/Scanner/Prog.py
index 848f874..4781175 100644
--- a/src/engine/SCons/Scanner/Prog.py
+++ b/src/engine/SCons/Scanner/Prog.py
@@ -38,13 +38,21 @@ def ProgramScanner(**kw):
ps = SCons.Scanner.Base(scan, "ProgramScanner", **kw)
return ps
-def _split_libs(env, libs):
+def _subst_libs(env, libs):
"""
Substitute environment variables and split into list.
"""
- libs = env.subst(libs)
if SCons.Util.is_String(libs):
- libs = libs.split()
+ libs = env.subst(libs)
+ if SCons.Util.is_String(libs):
+ libs = libs.split()
+ elif SCons.Util.is_Sequence(libs):
+ _libs = []
+ for l in libs:
+ _libs += _subst_libs(env, l)
+ libs = _libs
+ else:
+ libs = [libs]
return libs
def scan(node, env, libpath = ()):
@@ -59,12 +67,8 @@ def scan(node, env, libpath = ()):
except KeyError:
# There are no LIBS in this environment, so just return a null list:
return []
- if SCons.Util.is_String(libs):
- libs = _split_libs(env, libs)
- else:
- libs = SCons.Util.flatten(libs)
- libs = map(lambda x: _split_libs(env, x) if SCons.Util.is_String(x) else x, libs)
- libs = SCons.Util.flatten(libs)
+
+ libs = _subst_libs(env, libs)
try:
prefix = env['LIBPREFIXES']
diff --git a/src/engine/SCons/Scanner/ProgTests.py b/src/engine/SCons/Scanner/ProgTests.py
index 98e20cc..ace3ff4 100644
--- a/src/engine/SCons/Scanner/ProgTests.py
+++ b/src/engine/SCons/Scanner/ProgTests.py
@@ -32,6 +32,7 @@ import TestUnit
import SCons.Node.FS
import SCons.Scanner.Prog
+import SCons.Subst
test = TestCmd.TestCmd(workdir = '')
@@ -72,12 +73,7 @@ class DummyEnvironment(object):
del self.Dictionary()[key]
def subst(self, s, target=None, source=None, conv=None):
- try:
- if isinstance(s, str) and s[0] == '$':
- return self._dict[s[1:]]
- except IndexError:
- return ''
- return s
+ return SCons.Subst.scons_subst(s, self, gvars=self._dict, lvars=self._dict)
def subst_path(self, path, target=None, source=None, conv=None):
if not isinstance(path, list):
@@ -241,7 +237,8 @@ class ProgramScannerTestCase10(unittest.TestCase):
LIBS=['foo', '$LIBBAR'],
LIBPREFIXES=['lib'],
LIBSUFFIXES=['.a'],
- LIBBAR='sub/libbar xyz.other')
+ LIBBAR='sub/libbar $LIBBAR2',
+ LIBBAR2=['xyz.other'])
s = SCons.Scanner.Prog.ProgramScanner()
path = s.path(env)
deps = s(DummyNode('dummy'), env, path)