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
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
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
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"""
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')
-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:
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',
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':
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
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")
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()
test.write('SConstruct', """
import os
print "SConstruct", os.getcwd()
-Conscript('SConscript')
+SConscript('SConscript')
""")
# XXX I THINK THEY SHOULD HAVE TO RE-IMPORT OS HERE
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
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()