summaryrefslogtreecommitdiffstats
path: root/src/engine/SCons
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2004-09-25 02:50:45 (GMT)
committerSteven Knight <knight@baldmt.com>2004-09-25 02:50:45 (GMT)
commit10457428a793ab83448c6752f647f8fec882c2fa (patch)
tree5c0fc7d7e7bec84d3e88ca77133d693f7eb98cd1 /src/engine/SCons
parent25b2149133eec63f8501efb37f4dd6e59cdc7506 (diff)
downloadSCons-10457428a793ab83448c6752f647f8fec882c2fa.zip
SCons-10457428a793ab83448c6752f647f8fec882c2fa.tar.gz
SCons-10457428a793ab83448c6752f647f8fec882c2fa.tar.bz2
Add a ParseDepends() function to read up mkdep-style files.
Diffstat (limited to 'src/engine/SCons')
-rw-r--r--src/engine/SCons/Environment.py26
-rw-r--r--src/engine/SCons/EnvironmentTests.py32
-rw-r--r--src/engine/SCons/Script/SConscript.py1
-rw-r--r--src/engine/SCons/Util.py29
-rw-r--r--src/engine/SCons/UtilTests.py23
5 files changed, 111 insertions, 0 deletions
diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py
index df2a93a..9fa7b34 100644
--- a/src/engine/SCons/Environment.py
+++ b/src/engine/SCons/Environment.py
@@ -792,6 +792,32 @@ class Base:
command = self.subst(command)
return function(self, os.popen(command).read())
+ def ParseDepends(self, filename, must_exist=None):
+ """
+ Parse a mkdep-style file for explicit dependencies. This is
+ completely abusable, and should be unnecessary in the "normal"
+ case of proper SCons configuration, but it may help make
+ the transition from a Make hierarchy easier for some people
+ to swallow. It can also be genuinely useful when using a tool
+ that can write a .d file, but for which writing a scanner would
+ be too complicated.
+ """
+ try:
+ fp = open(filename, 'r')
+ except IOError:
+ if must_exist:
+ raise
+ return
+ for line in SCons.Util.LogicalLines(fp).readlines():
+ if line[0] == '#':
+ continue
+ try:
+ target, depends = string.split(line, ':', 1)
+ except:
+ pass
+ else:
+ self.Depends(string.split(target), string.split(depends))
+
def Platform(self, platform):
platform = self.subst(platform)
return SCons.Platform.Platform(platform)(self)
diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py
index 7023fea..aa38965 100644
--- a/src/engine/SCons/EnvironmentTests.py
+++ b/src/engine/SCons/EnvironmentTests.py
@@ -1353,6 +1353,38 @@ class EnvironmentTestCase(unittest.TestCase):
finally:
os.popen = orig_popen
+ def test_ParseDepends(self):
+ """Test the ParseDepends() method"""
+ env = Environment()
+
+ test = TestCmd.TestCmd(workdir = '')
+
+ test.write('mkdep', """
+f1: foo
+f2 f3: bar
+f4: abc def
+#file: dependency
+f5: \
+ ghi \
+ jkl \
+ mno \
+""")
+
+ tlist = []
+ dlist = []
+ def my_depends(target, dependency, tlist=tlist, dlist=dlist):
+ tlist.extend(target)
+ dlist.extend(dependency)
+
+ env.Depends = my_depends
+
+ env.ParseDepends(test.workpath('mkdep'))
+
+ t = map(str, tlist)
+ d = map(str, dlist)
+ assert t == ['f1', 'f2', 'f3', 'f4', 'f5'], t
+ assert d == ['foo', 'bar', 'abc', 'def', 'ghi', 'jkl', 'mno'], d
+
def test_Platform(self):
"""Test the Platform() method"""
env = Environment(WIN32='win32', NONE='no-such-platform')
diff --git a/src/engine/SCons/Script/SConscript.py b/src/engine/SCons/Script/SConscript.py
index fab0d82..88d3268 100644
--- a/src/engine/SCons/Script/SConscript.py
+++ b/src/engine/SCons/Script/SConscript.py
@@ -594,6 +594,7 @@ GlobalDefaultEnvironmentFunctions = [
'InstallAs',
'Literal',
'Local',
+ 'ParseDepends',
'Precious',
'Repository',
'SConsignFile',
diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py
index df2f604..afcaf11 100644
--- a/src/engine/SCons/Util.py
+++ b/src/engine/SCons/Util.py
@@ -1520,3 +1520,32 @@ def unique(s):
if x not in u:
u.append(x)
return u
+
+# Much of the logic here was originally based on recipe 4.9 from the
+# Python CookBook, but we had to dumb it way down for Python 1.5.2.
+class LogicalLines:
+
+ def __init__(self, fileobj):
+ self.fileobj = fileobj
+
+ def readline(self):
+ result = []
+ while 1:
+ line = self.fileobj.readline()
+ if not line:
+ break
+ if line[-2:] == '\\\n':
+ result.append(line[:-2])
+ else:
+ result.append(line)
+ break
+ return string.join(result, '')
+
+ def readlines(self):
+ result = []
+ while 1:
+ line = self.readline()
+ if not line:
+ break
+ result.append(line)
+ return result
diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py
index 2b5fdef..054d0b2 100644
--- a/src/engine/SCons/UtilTests.py
+++ b/src/engine/SCons/UtilTests.py
@@ -1552,6 +1552,29 @@ class UtilTestCase(unittest.TestCase):
assert containsOnly('.83', '0123456789.')
assert not containsOnly('43221', '123')
+ def test_LogicalLines(self):
+ """Test the LogicalLines class"""
+ import StringIO
+
+ fobj = StringIO.StringIO(r"""
+foo \
+bar \
+baz
+foo
+bling \
+bling \ bling
+bling
+""")
+
+ lines = LogicalLines(fobj).readlines()
+ assert lines == [
+ '\n',
+ 'foo bar baz\n',
+ 'foo\n',
+ 'bling bling \\ bling\n',
+ 'bling\n',
+ ], lines
+
if __name__ == "__main__":
suite = unittest.makeSuite(UtilTestCase, 'test_')
if not unittest.TextTestRunner().run(suite).wasSuccessful():