From 15928490b955a3d4ea4966102dc915ed0fdb8526 Mon Sep 17 00:00:00 2001 From: Steven Knight Date: Mon, 29 Oct 2001 05:33:03 +0000 Subject: Handle SConscript files in subdirectories. --- src/engine/SCons/Node/FS.py | 9 ++++++++- src/engine/SCons/Node/FSTests.py | 8 ++++++++ src/engine/SCons/Sig/MD5.py | 6 +++++- src/engine/SCons/Sig/MD5Tests.py | 7 +++++++ src/script/scons.py | 23 ++++++++++++++--------- test/Depends.py | 28 +++++++++++----------------- test/SConscript.py | 2 +- test/errors.py | 2 +- test/option-f.py | 2 +- 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() -- cgit v0.12