RELEASE 0.09 -
+ From Steven Knight:
+
+ - Add Repository() functionality.
+
From Anthony Roach:
- Fixed use of command lines with spaces in their arguments,
def Install(self, dir, source):
"""Install specified files in the given directory."""
- sources = SCons.Node.arg2nodes(source, self.fs.File)
+ sources = SCons.Node.arg2Rnodes(source, self.fs.File)
dnodes = SCons.Node.arg2nodes(dir, self.fs.Dir)
tgt = []
for dnode in dnodes:
def InstallAs(self, target, source):
"""Install sources as targets."""
- sources = SCons.Node.arg2nodes(source, self.fs.File)
+ sources = SCons.Node.arg2Rnodes(source, self.fs.File)
targets = SCons.Node.arg2nodes(target, self.fs.File)
ret = []
for src, tgt in map(lambda x, y: (x, y), sources, targets):
default_ans = AliasNameSpace()
SCons.Node.arg2nodes_lookups.append(default_ans.lookup)
+SCons.Node.arg2Rnodes_lookups.append(default_ans.lookup)
self.Root = {}
self.Top = None
self.Repositories = []
+ SCons.Node.arg2Rnodes_lookups.append(self.Rsearch)
def set_toplevel_dir(self, path):
assert not self.Top, "You can only set the top-level path on an FS object that has not had its File, Dir, or Entry methods called yet."
assert not hasattr(nodes[2], 'a'), nodes[1]
assert not hasattr(nodes[2], 'b'), nodes[1]
+ def lookup_bbbb(str, F=Factory):
+ if str == 'bbbb':
+ n = F(str)
+ n.bbbb = 1
+ return n
+ else:
+ return None
+
+ def lookup_c(str, F=Factory):
+ if str[0] == 'c':
+ n = F(str)
+ n.c = 1
+ return n
+ else:
+ return None
+
+ nodes = SCons.Node.arg2nodes(['bbbb', 'ccc'], Factory,
+ [lookup_c, lookup_bbbb, lookup_b])
+ assert len(nodes) == 2, nodes
+
+ assert nodes[0].name == 'bbbb'
+ assert not hasattr(nodes[0], 'a'), nodes[1]
+ assert not hasattr(nodes[0], 'b'), nodes[1]
+ assert nodes[0].bbbb == 1, nodes[1]
+ assert not hasattr(nodes[0], 'c'), nodes[0]
+
+ assert nodes[1].name == 'ccc'
+ assert not hasattr(nodes[1], 'a'), nodes[1]
+ assert not hasattr(nodes[1], 'b'), nodes[1]
+ assert not hasattr(nodes[1], 'bbbb'), nodes[0]
+ assert nodes[1].c == 1, nodes[1]
+
+ def test_arg2Rnodes(self):
+ """Test the arg2Rnodes function."""
+ dict = {}
+ class X(SCons.Node.Node):
+ pass
+ def Factory(name, directory = None, create = 1, dict=dict, X=X):
+ if not dict.has_key(name):
+ dict[name] = X()
+ dict[name].name = name
+ return dict[name]
+
+ nodes = SCons.Node.arg2Rnodes("Util.py UtilTests.py", Factory)
+ assert len(nodes) == 1, nodes
+ assert isinstance(nodes[0], X)
+ assert nodes[0].name == "Util.py UtilTests.py"
+
+ if hasattr(types, 'UnicodeType'):
+ code = """if 1:
+ nodes = SCons.Node.arg2Rnodes(u"Util.py UtilTests.py", Factory)
+ assert len(nodes) == 1, nodes
+ assert isinstance(nodes[0], X)
+ assert nodes[0].name == u"Util.py UtilTests.py"
+ \n"""
+ exec code in globals(), locals()
+
+ nodes = SCons.Node.arg2Rnodes(["Util.py", "UtilTests.py"], Factory)
+ assert len(nodes) == 2, nodes
+ assert isinstance(nodes[0], X)
+ assert isinstance(nodes[1], X)
+ assert nodes[0].name == "Util.py"
+ assert nodes[1].name == "UtilTests.py"
+
+ n1 = Factory("Util.py")
+ nodes = SCons.Node.arg2Rnodes([n1, "UtilTests.py"], Factory)
+ assert len(nodes) == 2, nodes
+ assert isinstance(nodes[0], X)
+ assert isinstance(nodes[1], X)
+ assert nodes[0].name == "Util.py"
+ assert nodes[1].name == "UtilTests.py"
+
+ class SConsNode(SCons.Node.Node):
+ pass
+ nodes = SCons.Node.arg2Rnodes(SConsNode())
+ assert len(nodes) == 1, nodes
+ assert isinstance(nodes[0], SConsNode), node
+
+ class OtherNode:
+ pass
+ nodes = SCons.Node.arg2Rnodes(OtherNode())
+ assert len(nodes) == 1, nodes
+ assert isinstance(nodes[0], OtherNode), node
+
+ def lookup_a(str, F=Factory):
+ if str[0] == 'a':
+ n = F(str)
+ n.a = 1
+ return n
+ else:
+ return None
+
+ def lookup_b(str, F=Factory):
+ if str[0] == 'b':
+ n = F(str)
+ n.b = 1
+ return n
+ else:
+ return None
+
+ SCons.Node.arg2Rnodes_lookups.append(lookup_a)
+ SCons.Node.arg2Rnodes_lookups.append(lookup_b)
+
+ nodes = SCons.Node.arg2Rnodes(['aaa', 'bbb', 'ccc'], Factory)
+ assert len(nodes) == 3, nodes
+
+ assert nodes[0].name == 'aaa', nodes[0]
+ assert nodes[0].a == 1, nodes[0]
+ assert not hasattr(nodes[0], 'b'), nodes[0]
+
+ assert nodes[1].name == 'bbb'
+ assert not hasattr(nodes[1], 'a'), nodes[1]
+ assert nodes[1].b == 1, nodes[1]
+
+ assert nodes[2].name == 'ccc'
+ assert not hasattr(nodes[2], 'a'), nodes[1]
+ assert not hasattr(nodes[2], 'b'), nodes[1]
+
if __name__ == "__main__":
arg2nodes_lookups = []
-def arg2nodes(args, node_factory=None):
+arg2Rnodes_lookups = []
+
+def arg2nodes(args, node_factory=None, lookup_list=arg2nodes_lookups):
"""This function converts a string or list into a list of Node
instances. It accepts the following inputs:
- A single string,
for v in args:
if SCons.Util.is_String(v):
n = None
- for l in arg2nodes_lookups:
+ for l in lookup_list:
n = l(v)
if not n is None:
break
if not n is None:
+ if SCons.Util.is_String(n) and node_factory:
+ n = node_factory(n)
nodes.append(n)
elif node_factory:
nodes.append(node_factory(v))
nodes.append(v)
return nodes
+
+def arg2Rnodes(args, node_factory=None):
+ return arg2nodes(args, node_factory, arg2Rnodes_lookups)
--- /dev/null
+#!/usr/bin/env python
+#
+# Copyright (c) 2001, 2002 Steven Knight
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+import os.path
+import sys
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.subdir('install', 'repository', 'work')
+
+install = test.workpath('install')
+install_file = test.workpath('install', 'file')
+
+opts = "-Y " + test.workpath('repository')
+
+#
+test.write(['repository', 'SConstruct'], r"""
+env = Environment()
+env.Install(r'%s', 'file')
+""" % install)
+
+test.write(['repository', 'file'], "repository/file\n")
+
+# Make the entire repository non-writable, so we'll detect
+# if we try to write into it accidentally.
+test.writable('repository', 0)
+
+test.run(chdir = 'work', options = opts, arguments = install)
+
+test.fail_test(test.read(install_file) != "repository/file\n")
+
+test.up_to_date(chdir = 'work', options = opts, arguments = install)
+
+#
+test.pass_test()
--- /dev/null
+#!/usr/bin/env python
+#
+# Copyright (c) 2001, 2002 Steven Knight
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+import os.path
+import sys
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.subdir('install', 'repository', 'work')
+
+install = test.workpath('install')
+install_file1_out = test.workpath('install', 'file1.out')
+install_file2_out = test.workpath('install', 'file2.out')
+install_file3_out = test.workpath('install', 'file3.out')
+
+opts = "-Y " + test.workpath('repository')
+
+#
+test.write(['repository', 'SConstruct'], r"""
+env = Environment()
+env.InstallAs(r'%s', 'file1.in')
+env.InstallAs([r'%s', r'%s'], ['file2.in', 'file3.in'])
+""" % (install_file1_out, install_file2_out, install_file3_out))
+
+test.write(['repository', 'file1.in'], "repository/file1.in\n")
+test.write(['repository', 'file2.in'], "repository/file2.in\n")
+test.write(['repository', 'file3.in'], "repository/file3.in\n")
+
+# Make the entire repository non-writable, so we'll detect
+# if we try to write into it accidentally.
+test.writable('repository', 0)
+
+test.run(chdir = 'work', options = opts, arguments = install)
+
+test.fail_test(test.read(install_file1_out) != "repository/file1.in\n")
+test.fail_test(test.read(install_file2_out) != "repository/file2.in\n")
+test.fail_test(test.read(install_file3_out) != "repository/file3.in\n")
+
+test.up_to_date(chdir = 'work', options = opts, arguments = install)
+
+#
+test.pass_test()