summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2001-10-29 05:33:03 (GMT)
committerSteven Knight <knight@baldmt.com>2001-10-29 05:33:03 (GMT)
commit15928490b955a3d4ea4966102dc915ed0fdb8526 (patch)
tree4b7b65dd605a53881ad0ee1977cea88db9f31885
parent3bce8a9e6e70d61723e4824bd7ba84a7b9547456 (diff)
downloadSCons-15928490b955a3d4ea4966102dc915ed0fdb8526.zip
SCons-15928490b955a3d4ea4966102dc915ed0fdb8526.tar.gz
SCons-15928490b955a3d4ea4966102dc915ed0fdb8526.tar.bz2
Handle SConscript files in subdirectories.
-rw-r--r--src/engine/SCons/Node/FS.py9
-rw-r--r--src/engine/SCons/Node/FSTests.py8
-rw-r--r--src/engine/SCons/Sig/MD5.py6
-rw-r--r--src/engine/SCons/Sig/MD5Tests.py7
-rw-r--r--src/script/scons.py23
-rw-r--r--test/Depends.py28
-rw-r--r--test/SConscript.py2
-rw-r--r--test/errors.py2
-rw-r--r--test/option-f.py2
9 files changed, 56 insertions, 31 deletions
diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py
index c3566a6..860f46b 100644
--- a/src/engine/SCons/Node/FS.py
+++ b/src/engine/SCons/Node/FS.py
@@ -120,6 +120,7 @@ class FS:
self.Top = self.__doLookup(Dir, path)
self.Top.path = '.'
self.Top.path_ = './'
+ self.cwd = self.Top
def __doLookup(self, fsclass, name, directory=None):
"""This method differs from the File and Dir factory methods in
@@ -188,9 +189,15 @@ class FS:
directory = self.Top
name = os.path.join(os.path.normpath('./'), name[1:])
elif not directory:
- directory = self.Top
+ directory = self.cwd
return (name, directory)
+ def chdir(self, dir):
+ """Change the current working directory for lookups.
+ """
+ if not dir is None:
+ self.cwd = dir
+
def Entry(self, name, directory = None):
"""Lookup or create a generic Entry node with the specified name.
If the name is a relative path (begins with ./, ../, or a file
diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py
index 360132a..430d4b4 100644
--- a/src/engine/SCons/Node/FSTests.py
+++ b/src/engine/SCons/Node/FSTests.py
@@ -278,6 +278,14 @@ class FSTestCase(unittest.TestCase):
assert d10.get_bsig() is None, d10.get_bsig()
assert d10.get_csig() is None, d10.get_csig()
+ fs.chdir(fs.Dir('subdir'))
+ f11 = fs.File("f11")
+ assert f11.path == "subdir/f11"
+ d12 = fs.Dir("d12")
+ assert d12.path_ == "subdir/d12/"
+ e13 = fs.Entry("subdir/e13")
+ assert e13.path == "subdir/subdir/e13"
+
#XXX test exists()
#XXX test current() for directories
diff --git a/src/engine/SCons/Sig/MD5.py b/src/engine/SCons/Sig/MD5.py
index 11ba961..e13669e 100644
--- a/src/engine/SCons/Sig/MD5.py
+++ b/src/engine/SCons/Sig/MD5.py
@@ -78,7 +78,11 @@ def collect(signatures):
def signature(obj):
"""Generate a signature for an object
"""
- return hexdigest(md5.new(obj.get_contents()).digest())
+ try:
+ contents = obj.get_contents()
+ except AttributeError:
+ raise AttributeError, "unable to fetch contents of '%s'" % str(obj)
+ return hexdigest(md5.new(contents).digest())
def to_string(signature):
"""Convert a signature to a string"""
diff --git a/src/engine/SCons/Sig/MD5Tests.py b/src/engine/SCons/Sig/MD5Tests.py
index 641dcb0..f9cf61f 100644
--- a/src/engine/SCons/Sig/MD5Tests.py
+++ b/src/engine/SCons/Sig/MD5Tests.py
@@ -75,6 +75,13 @@ class MD5TestCase(unittest.TestCase):
o1 = my_obj(value = '111')
assert '698d51a19d8a121ce581499d7b701668' == signature(o1)
+ try:
+ signature('string')
+ except AttributeError, e:
+ assert str(e) == "unable to fetch contents of 'string'"
+ else:
+ raise AttributeError, "unexpected get_contents() attribute"
+
def test_to_string(self):
assert '698d51a19d8a121ce581499d7b701668' == to_string('698d51a19d8a121ce581499d7b701668')
diff --git a/src/script/scons.py b/src/script/scons.py
index d6c7698..49a8467 100644
--- a/src/script/scons.py
+++ b/src/script/scons.py
@@ -147,9 +147,9 @@ def _scons_other_errors():
-def Conscript(filename):
+def SConscript(filename):
global scripts
- scripts.append(filename)
+ scripts.append(SCons.Node.FS.default_fs.File(filename))
def Default(*targets):
for t in targets:
@@ -361,7 +361,10 @@ def options_init():
def opt_f(opt, arg):
global scripts
- scripts.append(arg)
+ if arg == '-':
+ scripts.append(arg)
+ else:
+ scripts.append(SCons.Node.FS.default_fs.File(arg))
Option(func = opt_f,
short = 'f', long = ['file', 'makefile', 'sconstruct'], arg = 'FILE',
@@ -581,7 +584,7 @@ def main():
if not scripts:
for file in ['SConstruct', 'Sconstruct', 'sconstruct']:
if os.path.isfile(file):
- scripts.append(file)
+ scripts.append(SCons.Node.FS.default_fs.File(file))
break
if help_option == 'H':
@@ -616,16 +619,18 @@ def main():
sys.path = include_dirs + sys.path
while scripts:
- file, scripts = scripts[0], scripts[1:]
- if file == "-":
+ f, scripts = scripts[0], scripts[1:]
+ if f == "-":
exec sys.stdin in globals()
else:
try:
- f = open(file, "r")
+ file = open(f.path, "r")
except IOError, s:
- sys.stderr.write("Ignoring missing script '%s'\n" % file)
+ sys.stderr.write("Ignoring missing SConscript '%s'\n" % f.path)
else:
- exec f in globals()
+ SCons.Node.FS.default_fs.chdir(f.dir)
+ exec file in globals()
+ SCons.Node.FS.default_fs.chdir(SCons.Node.FS.default_fs.Top)
if help_option == 'h':
# They specified -h, but there was no Help() inside the
diff --git a/test/Depends.py b/test/Depends.py
index 3777fbd..5fb0479 100644
--- a/test/Depends.py
+++ b/test/Depends.py
@@ -52,12 +52,12 @@ env.Depends(target = 'f3.out', dependency = 'subdir/bar.dep')
env.Foo(target = 'f1.out', source = 'f1.in')
env.Foo(target = 'f2.out', source = 'f2.in')
env.Bar(target = 'f3.out', source = 'f3.in')
-Conscript('subdir/SConscript')
+SConscript('subdir/SConscript')
""" % (python, python))
test.write(['subdir', 'SConscript'], """
env.Depends(target = 'f4.out', dependency = 'bar.dep')
-env.Foo(target = 'f4.out', source = 'f4.in')
+env.Bar(target = 'f4.out', source = 'f4.in')
""")
test.write('f1.in', "f1.in\n")
@@ -72,40 +72,34 @@ test.write(['subdir', 'foo.dep'], "subdir/foo.dep 1\n")
test.write(['subdir', 'bar.dep'], "subdir/bar.dep 1\n")
-#XXXtest.run(arguments = '.')
-#test.run(arguments = 'f1.out f2.out f3.out subdir/f4.out')
-test.run(arguments = 'f1.out f2.out f3.out')
+test.run(arguments = '.')
test.fail_test(test.read('f1.out') != "f1.in\nsubdir/foo.dep 1\n")
test.fail_test(test.read('f2.out') != "f2.in\nsubdir/foo.dep 1\n")
test.fail_test(test.read('f3.out') != "f3.in\nsubdir/bar.dep 1\n")
-#XXXtest.fail_test(test.read(['subdir', 'f4.out']) !=
-#XXX "subdir/f4.in\nsubdir/bar.dep 1\n")
+test.fail_test(test.read(['subdir', 'f4.out']) !=
+ "subdir/f4.in\nsubdir/bar.dep 1\n")
test.write(['subdir', 'foo.dep'], "subdir/foo.dep 2\n")
test.write(['subdir', 'bar.dep'], "subdir/bar.dep 2\n")
-#XXXtest.run(arguments = '.')
-#test.run(arguments = 'f1.out f2.out f3.out subdir/f4.out')
-test.run(arguments = 'f1.out f2.out f3.out')
+test.run(arguments = '.')
test.fail_test(test.read('f1.out') != "f1.in\nsubdir/foo.dep 2\n")
test.fail_test(test.read('f2.out') != "f2.in\nsubdir/foo.dep 2\n")
test.fail_test(test.read('f3.out') != "f3.in\nsubdir/bar.dep 2\n")
-#XXXtest.fail_test(test.read(['subdir', 'f4.out']) !=
-#XXX "subdir/f4.in\nsubdir/bar.dep 2\n")
+test.fail_test(test.read(['subdir', 'f4.out']) !=
+ "subdir/f4.in\nsubdir/bar.dep 2\n")
test.write(['subdir', 'bar.dep'], "subdir/bar.dep 3\n")
-#XXXtest.run(arguments = '.')
-#test.run(arguments = 'f1.out f2.out f3.out subdir/f4.out')
-test.run(arguments = 'f1.out f2.out f3.out')
+test.run(arguments = '.')
test.fail_test(test.read('f1.out') != "f1.in\nsubdir/foo.dep 2\n")
test.fail_test(test.read('f2.out') != "f2.in\nsubdir/foo.dep 2\n")
test.fail_test(test.read('f3.out') != "f3.in\nsubdir/bar.dep 3\n")
-#XXXtest.fail_test(test.read(['subdir', 'f4.out']) !=
-#XXX "subdir/f4.in\nsubdir/bar.dep 3\n")
+test.fail_test(test.read(['subdir', 'f4.out']) !=
+ "subdir/f4.in\nsubdir/bar.dep 3\n")
test.pass_test()
diff --git a/test/SConscript.py b/test/SConscript.py
index 8a0f28b..b463f7e 100644
--- a/test/SConscript.py
+++ b/test/SConscript.py
@@ -31,7 +31,7 @@ test = TestSCons.TestSCons()
test.write('SConstruct', """
import os
print "SConstruct", os.getcwd()
-Conscript('SConscript')
+SConscript('SConscript')
""")
# XXX I THINK THEY SHOULD HAVE TO RE-IMPORT OS HERE
diff --git a/test/errors.py b/test/errors.py
index 3965f77..b973f37 100644
--- a/test/errors.py
+++ b/test/errors.py
@@ -67,7 +67,7 @@ test.run(arguments='-f SConstruct3',
File ".*scons(\.py)?", line \d+, in \?
main\(\)
File ".*scons(\.py)?", line \d+, in main
- exec f in globals\(\)
+ exec file in globals\(\)
File "SConstruct3", line \d+, in \?
raise InternalError, 'error inside'
InternalError: error inside
diff --git a/test/option-f.py b/test/option-f.py
index 84b8ed3..55ec367 100644
--- a/test/option-f.py
+++ b/test/option-f.py
@@ -77,6 +77,6 @@ print "STDIN " + os.getcwd()
test.run(arguments = '-f no_such_file',
stdout = "",
- stderr = "Ignoring missing script 'no_such_file'\n")
+ stderr = "Ignoring missing SConscript 'no_such_file'\n")
test.pass_test()