5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
28 Validate successful handling of errors when duplicating things in
29 BuildDirs. This is generally when the BuildDir, or something in it,
39 test = TestSCons.TestSCons()
41 for dir in ['normal', 'ro-dir', 'ro-SConscript', 'ro-src']:
42 test.subdir(dir, [dir, 'src'])
44 test.write([dir, 'SConstruct'], """\
46 BuildDir('build', 'src')
47 SConscript(os.path.join('build', 'SConscript'))
50 test.write([dir, 'src', 'SConscript'], """\
51 def fake_scan(node, env, target):
52 # We fetch the contents here, even though we don't examine
53 # them, because get_contents() will cause the engine to
54 # try to link the source file into the build directory,
55 # potentially triggering a different failure case.
56 contents = node.get_contents()
59 def cat(env, source, target):
60 target = str(target[0])
61 source = map(str, source)
62 f = open(target, "wb")
64 f.write(open(src, "rb").read())
67 env = Environment(BUILDERS={'Build':Builder(action=cat)},
68 SCANNERS=[Scanner(fake_scan, skeys = ['.in'])])
70 # Do some Node test operations to ensure no side-effects cause failures
71 File('file.in').exists()
72 File('file.in').is_derived()
73 File('file.in').is_pseudo_derived()
75 env.Build('file.out', 'file.in')
78 test.write([dir, 'src', 'file.in'], dir + "/src/file.in\n")
80 # Just verify that the normal case works fine.
81 test.run(chdir = 'normal', arguments = ".")
83 test.fail_test(test.read(['normal', 'build', 'file.out']) != "normal/src/file.in\n")
85 # Verify the error when the BuildDir itself is read-only. Don't bother
86 # to test this on Windows, because the ACL (I think) still allows the
87 # owner to create files in the directory even when it's read-only.
88 if sys.platform != 'win32':
89 dir = os.path.join('ro-dir', 'build')
91 os.chmod(dir, os.stat(dir)[stat.ST_MODE] & ~stat.S_IWUSR)
93 test.run(chdir = 'ro-dir',
96 stderr = "scons: *** Cannot duplicate `%s' in `build': Permission denied. Stop.\n" % os.path.join('src', 'SConscript'))
98 # Verify the error when the SConscript file within the BuildDir is
99 # read-only. Note that we have to make the directory read-only too,
100 # because otherwise our duplication logic will be able to unlink
101 # the read-only SConscript and duplicate the new one.
102 dir = os.path.join('ro-SConscript', 'build')
104 SConscript = test.workpath(dir, 'SConscript')
105 test.write(SConscript, '')
106 os.chmod(SConscript, os.stat(SConscript)[stat.ST_MODE] & ~stat.S_IWUSR)
107 f = open(SConscript, 'r')
108 os.chmod(dir, os.stat(dir)[stat.ST_MODE] & ~stat.S_IWUSR)
110 test.run(chdir = 'ro-SConscript',
113 stderr = "scons: *** Cannot duplicate `%s' in `build': Permission denied. Stop.\n" % os.path.join('src', 'SConscript'))
115 os.chmod('ro-SConscript', os.stat('ro-SConscript')[stat.ST_MODE] | stat.S_IWUSR)
118 test.run(chdir = 'ro-SConscript',
121 stderr = "scons: *** Cannot duplicate `%s' in `build': Permission denied. Stop.\n" % os.path.join('src', 'SConscript'))
123 # Verify the error when the source file within the BuildDir is
124 # read-only. Note that we have to make the directory read-only too,
125 # because otherwise our duplication logic will be able to unlink the
126 # read-only source file and duplicate the new one. But because we've
127 # made the BuildDir read-only, we must also create a writable SConscript
128 # file there so it can be duplicated from the source directory.
129 dir = os.path.join('ro-src', 'build')
131 test.write([dir, 'SConscript'], '')
132 file_in = test.workpath(dir, 'file.in')
133 test.write(file_in, '')
134 os.chmod(file_in, os.stat(file_in)[stat.ST_MODE] & ~stat.S_IWUSR)
135 f = open(file_in, 'r')
136 os.chmod(dir, os.stat(dir)[stat.ST_MODE] & ~stat.S_IWUSR)
138 test.run(chdir = 'ro-src',
142 scons: *** Cannot duplicate `%s' in `build': Permission denied. Stop.
143 """ % (os.path.join('src', 'file.in')))
145 test.run(chdir = 'ro-src',
149 scons: *** Cannot duplicate `%s' in `build': Permission denied. Stop.
150 """ % (os.path.join('src', 'file.in')))
154 # ensure that specifying multiple source directories for one
155 # build directory results in an error message, rather
156 # than just silently failing.
157 test.subdir('duplicate', ['duplicate', 'src1'], ['duplicate', 'src2'])
159 duplicate_SConstruct_path = test.workpath('duplicate', 'SConstruct')
161 test.write(duplicate_SConstruct_path, """\
162 BuildDir('build', 'src1')
163 BuildDir('build', 'src2')
167 scons: *** 'build' already has a source directory: 'src1'.
168 """ + test.python_file_line(duplicate_SConstruct_path, 2)
170 test.run(chdir = 'duplicate',
173 stderr = expect_stderr)