5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 Validate successful handling of errors when duplicating things in
28 VariantDirs. This is generally when the VariantDir, or something in it,
36 from TestCmd
import IS_ROOT
38 test
= TestSCons
.TestSCons()
41 test
.skip_test('SConscript permissions meaningless when running as root; skipping test.\n')
43 for dir in ['normal', 'ro-dir', 'ro-SConscript', 'ro-src']:
44 test
.subdir(dir, [dir, 'src'])
46 test
.write([dir, 'SConstruct'], """\
48 VariantDir('build', 'src')
49 SConscript(os.path.join('build', 'SConscript'))
52 test
.write([dir, 'src', 'SConscript'], """\
53 def fake_scan(node, env, target):
54 # We fetch the contents here, even though we don't examine
55 # them, because get_contents() will cause the engine to
56 # try to link the source file into the build directory,
57 # potentially triggering a different failure case.
58 contents = node.get_contents()
61 def cat(env, source, target):
62 target = str(target[0])
63 with open(target, "w") as f:
65 with open(str(src), "r") as f2:
68 env = Environment(BUILDERS={'Build':Builder(action=cat)},
69 SCANNERS=[Scanner(fake_scan, skeys = ['.in'])])
71 # Do some Node test operations to ensure no side-effects cause failures
72 File('file.in').exists()
73 File('file.in').is_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
.must_match(['normal', 'build', 'file.out'], "normal/src/file.in\n", mode
='r')
85 # Verify the error when the VariantDir 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 VariantDir 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 with
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
)
117 test
.run(chdir
= 'ro-SConscript',
120 stderr
= "scons: *** Cannot duplicate `%s' in `build': Permission denied. Stop.\n" % os
.path
.join('src', 'SConscript'))
122 # Verify the error when the source file within the VariantDir is
123 # read-only. Note that we have to make the directory read-only too,
124 # because otherwise our duplication logic will be able to unlink the
125 # read-only source file and duplicate the new one. But because we've
126 # made the VariantDir read-only, we must also create a writable SConscript
127 # file there so it can be duplicated from the source directory.
128 dir = os
.path
.join('ro-src', 'build')
130 test
.write([dir, 'SConscript'], '')
131 file_in
= test
.workpath(dir, 'file.in')
132 test
.write(file_in
, '')
133 os
.chmod(file_in
, os
.stat(file_in
)[stat
.ST_MODE
] & ~stat
.S_IWUSR
)
134 with
open(file_in
, 'r'):
135 os
.chmod(dir, os
.stat(dir)[stat
.ST_MODE
] & ~stat
.S_IWUSR
)
137 test
.run(chdir
= 'ro-src',
141 scons: *** Cannot duplicate `%s' in `build': Permission denied. Stop.
142 """ % (os
.path
.join('src', 'file.in')))
144 test
.run(chdir
= 'ro-src',
148 scons: *** Cannot duplicate `%s' in `build': Permission denied. Stop.
149 """ % (os
.path
.join('src', 'file.in')))
151 # ensure that specifying multiple source directories for one
152 # build directory results in an error message, rather
153 # than just silently failing.
154 test
.subdir('duplicate', ['duplicate', 'src1'], ['duplicate', 'src2'])
156 duplicate_SConstruct_path
= test
.workpath('duplicate', 'SConstruct')
158 test
.write(duplicate_SConstruct_path
, """\
159 VariantDir('build', 'src1')
160 VariantDir('build', 'src2')
164 scons: *** 'build' already has a source directory: 'src1'.
165 """ + test
.python_file_line(duplicate_SConstruct_path
, 2)
167 test
.run(chdir
= 'duplicate',
170 stderr
= expect_stderr
)
176 # indent-tabs-mode:nil
178 # vim: set expandtab tabstop=4 shiftwidth=4: