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 Test how the setup.py script installs SCons.
30 Note that this is an installation test, not a functional test, so the
31 name of this script doesn't end in *Tests.py.
41 except NameError: WindowsError = OSError
45 version = TestSCons.TestSCons.scons_version
47 scons_version = 'scons-%s' % version
49 python = TestSCons.python
51 class MyTestSCons(TestSCons.TestSCons):
54 # A representative smattering of build engine modules.
69 'sconsign-%s' % version,
76 _bat_version_scripts = [
77 'scons-%s.bat' % version,
86 TestSCons.TestSCons.__init__(self)
87 self.root = self.workpath('root')
88 self.prefix = self.root + os.path.splitdrive(sys.prefix)[1]
90 if sys.platform == 'win32':
91 self.bin_dir = os.path.join(self.prefix, 'Scripts')
92 self.bat_dir = self.prefix
93 self.standalone_lib = os.path.join(self.prefix, 'scons')
94 self.standard_lib = os.path.join(self.prefix,
98 self.version_lib = os.path.join(self.prefix, scons_version)
99 self.man_dir = os.path.join(self.prefix, 'Doc')
101 self.bin_dir = os.path.join(self.prefix, 'bin')
102 self.bat_dir = self.bin_dir
103 self.lib_dir = os.path.join(self.prefix, 'lib')
104 self.standalone_lib = os.path.join(self.lib_dir, 'scons')
105 self.standard_lib = os.path.join(self.lib_dir,
106 'python%s' % sys.version[:3],
109 self.version_lib = os.path.join(self.lib_dir, scons_version)
110 self.man_dir = os.path.join(self.prefix, 'man', 'man1')
112 self.prepend_bin_dir = lambda p, d=self.bin_dir: os.path.join(d, p)
113 self.prepend_bat_dir = lambda p, d=self.bat_dir: os.path.join(d, p)
114 self.prepend_man_dir = lambda p, d=self.man_dir: os.path.join(d, p)
116 def run(self, *args, **kw):
117 kw['chdir'] = scons_version
118 kw['program'] = python
120 return apply(TestSCons.TestSCons.run, (self,)+args, kw)
122 def remove(self, dir):
123 try: shutil.rmtree(dir)
124 except (OSError, WindowsError): pass
126 def stdout_lines(self):
127 return string.split(self.stdout(), '\n')
130 def lib_line(self, lib):
131 return 'Installed SCons library modules into %s' % lib
133 def lib_paths(self, lib_dir):
134 prepend_lib_dir = lambda p, d=lib_dir: os.path.join(d, 'SCons', p)
135 return map(prepend_lib_dir, self._lib_modules)
137 def scripts_line(self):
138 return 'Installed SCons scripts into %s' % self.bin_dir
140 def base_script_paths(self):
141 scripts = self._base_scripts
142 return map(self.prepend_bin_dir, scripts)
144 def version_script_paths(self):
145 scripts = self._version_scripts
146 return map(self.prepend_bin_dir, scripts)
148 def bat_script_paths(self):
149 scripts = self._bat_scripts + self._bat_version_scripts
150 return map(self.prepend_bat_dir, scripts)
152 def man_page_line(self):
153 return 'Installed SCons man pages into %s' % self.man_dir
155 def man_page_paths(self):
156 return map(self.prepend_man_dir, self._man_pages)
159 def must_have_installed(self, paths):
163 def must_not_have_installed(self, paths):
165 self.must_not_exist(p)
168 cwd = os.environ['SCONS_CWD']
174 test.subdir(test.root)
176 tar_gz = os.path.join(cwd, 'build', 'dist', '%s.tar.gz' % scons_version)
177 zip = os.path.join(cwd, 'build', 'dist', '%s.zip' % scons_version)
179 if os.path.isfile(zip):
181 except ImportError: pass
183 zf = zipfile.ZipFile(zip, 'r')
185 for name in zf.namelist():
186 dir = os.path.dirname(name)
187 try: os.makedirs(dir)
189 # if the file exists, then delete it before writing
190 # to it so that we don't end up trying to write to a symlink:
191 if os.path.isfile(name) or os.path.islink(name):
193 if not os.path.isdir(name):
194 open(name, 'w').write(zf.read(name))
196 if not os.path.isdir(scons_version) and os.path.isfile(tar_gz):
197 # Unpack the .tar.gz file. This should create the scons_version/
198 # subdirectory from which we execute the setup.py script therein.
199 os.system("gunzip -c %s | tar xf -" % tar_gz)
201 if not os.path.isdir(scons_version):
202 print "Cannot test package installation, found none of the following packages:"
207 # Verify that a virgin installation installs the version library,
208 # the scripts and (on UNIX/Linux systems) the man pages.
209 test.run(arguments = 'setup.py install --root=%s' % test.root)
210 test.fail_test(not test.lib_line(test.version_lib) in test.stdout_lines())
211 test.must_have_installed(test.lib_paths(test.version_lib))
213 # Verify that --standard-lib installs into the Python standard library.
214 test.run(arguments = 'setup.py install --root=%s --standard-lib' % test.root)
215 test.fail_test(not test.lib_line(test.standard_lib) in test.stdout_lines())
216 test.must_have_installed(test.lib_paths(test.standard_lib))
218 # Verify that --standalone-lib installs the standalone library.
219 test.run(arguments = 'setup.py install --root=%s --standalone-lib' % test.root)
220 test.fail_test(not test.lib_line(test.standalone_lib) in test.stdout_lines())
221 test.must_have_installed(test.lib_paths(test.standalone_lib))
223 # Verify that --version-lib installs into a version-specific library directory.
224 test.run(arguments = 'setup.py install --root=%s --version-lib' % test.root)
225 test.fail_test(not test.lib_line(test.version_lib) in test.stdout_lines())
227 # Now that all of the libraries are in place,
228 # verify that a default installation still installs the version library.
229 test.run(arguments = 'setup.py install --root=%s' % test.root)
230 test.fail_test(not test.lib_line(test.version_lib) in test.stdout_lines())
232 test.remove(test.version_lib)
234 # Now with only the standard and standalone libraries in place,
235 # verify that a default installation still installs the version library.
236 test.run(arguments = 'setup.py install --root=%s' % test.root)
237 test.fail_test(not test.lib_line(test.version_lib) in test.stdout_lines())
239 test.remove(test.version_lib)
240 test.remove(test.standalone_lib)
242 # Now with only the standard libraries in place,
243 # verify that a default installation still installs the version library.
244 test.run(arguments = 'setup.py install --root=%s' % test.root)
245 test.fail_test(not test.lib_line(test.version_lib) in test.stdout_lines())
250 test.run(arguments = 'setup.py install --root=%s' % test.root)
251 test.fail_test(not test.scripts_line() in test.stdout_lines())
252 if sys.platform == 'win32':
253 test.must_have_installed(test.base_script_paths())
254 test.must_have_installed(test.version_script_paths())
255 test.must_have_installed(test.bat_script_paths())
257 test.must_have_installed(test.base_script_paths())
258 test.must_have_installed(test.version_script_paths())
259 test.must_not_have_installed(test.bat_script_paths())
261 test.remove(test.prefix)
263 test.run(arguments = 'setup.py install --root=%s --no-install-bat' % test.root)
264 test.fail_test(not test.scripts_line() in test.stdout_lines())
265 test.must_have_installed(test.base_script_paths())
266 test.must_have_installed(test.version_script_paths())
267 test.must_not_have_installed(test.bat_script_paths())
269 test.remove(test.prefix)
271 test.run(arguments = 'setup.py install --root=%s --install-bat' % test.root)
272 test.fail_test(not test.scripts_line() in test.stdout_lines())
273 test.must_have_installed(test.base_script_paths())
274 test.must_have_installed(test.version_script_paths())
275 test.must_have_installed(test.bat_script_paths())
277 test.remove(test.prefix)
279 test.run(arguments = 'setup.py install --root=%s --no-scons-script' % test.root)
280 test.fail_test(not test.scripts_line() in test.stdout_lines())
281 test.must_not_have_installed(test.base_script_paths())
282 test.must_have_installed(test.version_script_paths())
283 # Doesn't matter whether we installed the .bat scripts or not.
285 test.remove(test.prefix)
287 test.run(arguments = 'setup.py install --root=%s --no-version-script' % test.root)
288 test.fail_test(not test.scripts_line() in test.stdout_lines())
289 test.must_have_installed(test.base_script_paths())
290 test.must_not_have_installed(test.version_script_paths())
291 # Doesn't matter whether we installed the .bat scripts or not.
295 test.remove(test.man_dir)
297 test.run(arguments = 'setup.py install --root=%s' % test.root)
298 if sys.platform == 'win32':
299 test.fail_test(test.man_page_line() in test.stdout_lines())
300 test.must_not_have_installed(test.man_page_paths())
302 test.fail_test(not test.man_page_line() in test.stdout_lines())
303 test.must_have_installed(test.man_page_paths())
305 test.remove(test.man_dir)
307 test.run(arguments = 'setup.py install --root=%s --no-install-man' % test.root)
308 test.fail_test(test.man_page_line() in test.stdout_lines())
309 test.must_not_have_installed(test.man_page_paths())
311 test.remove(test.man_dir)
313 test.run(arguments = 'setup.py install --root=%s --install-man' % test.root)
314 test.fail_test(not test.man_page_line() in test.stdout_lines())
315 test.must_have_installed(test.man_page_paths())
319 # Verify that we don't warn about the directory in which we've
320 # installed the modules when using a non-standard prefix.
321 other_prefix = test.workpath('other-prefix')
322 test.subdir(other_prefix)
323 test.run(arguments = 'setup.py install --prefix=%s' % other_prefix)
324 test.fail_test(string.find(test.stderr(),
325 "you'll have to change the search path yourself")
333 # indent-tabs-mode:nil
335 # vim: set expandtab tabstop=4 shiftwidth=4: