3 # A script for unpacking and installing different historic versions of
4 # SCons in a consistent manner for side-by-side development testing.
6 # This abstracts the changes we've made to the SCons setup.py scripts in
7 # different versions so that, no matter what version is specified, it ends
8 # up installing the necessary script(s) and library into version-specific
9 # names that won't interfere with other things.
11 # By default, we expect to extract the .tar.gz files from a Downloads
12 # subdirectory in the current directory.
14 # Note that this script cleans up after itself, removing the extracted
15 # directory in which we do the build.
17 # This was written for a Linux system (specifically Ubuntu) but should
18 # be reasonably generic to any POSIX-style system with a /usr/local
26 from Command import CommandRunner, Usage
83 downloads_dir = 'Downloads'
84 downloads_url = 'http://downloads.sourceforge.net/scons'
87 python = sys.executable
89 short_options = 'ad:hnp:q'
90 long_options = ['all', 'help', 'no-exec', 'prefix=', 'quiet']
93 Usage: install-scons.py [-ahnq] [-d DIR] [-p PREFIX] [VERSION ...]
95 -a, --all Install all SCons versions.
96 -d DIR, --downloads=DIR Downloads directory.
97 -h, --help Print this help and exit
98 -n, --no-exec No execute, just print the command line
99 -p PREFIX, --prefix=PREFIX Installation prefix.
100 -q, --quiet Quiet, don't print the command line
105 opts, args = getopt.getopt(argv[1:], short_options, long_options)
106 except getopt.error, msg:
110 if o in ('-a', '--all'):
112 elif o in ('-d', '--downloads'):
114 elif o in ('-h', '--help'):
117 elif o in ('-n', '--no-exec'):
118 CommandRunner.execute = CommandRunner.do_not_execute
119 elif o in ('-p', '--prefix'):
121 elif o in ('-q', '--quiet'):
122 CommandRunner.display = CommandRunner.do_not_display
124 sys.stderr.write(str(err.msg) + '\n')
125 sys.stderr.write('use -h to get help\n')
130 msg = 'install-scons.py: -a and version arguments both specified'
131 sys.stderr.write(msg)
136 cmd = CommandRunner()
139 scons = 'scons-' + version
140 tar_gz = os.path.join(downloads_dir, scons + '.tar.gz')
141 tar_gz_url = os.path.join(downloads_url, scons + '.tar.gz')
143 cmd.subst_dictionary(locals())
145 if not os.path.exists(tar_gz):
146 if not os.path.exists(downloads_dir):
147 cmd.run((os.mkdir, downloads_dir),
148 'mkdir %(downloads_dir)s')
149 cmd.run('wget -O %(tar_gz)s %(tar_gz_url)s')
151 cmd.run('tar zxf %(tar_gz)s')
153 cmd.run((os.chdir, scons), 'cd %(scons)s')
155 if version in ('0.01', '0.02', '0.03', '0.04', '0.05',
156 '0.06', '0.07', '0.08', '0.09', '0.10'):
158 # 0.01 through 0.10 install /usr/local/bin/scons and
159 # /usr/local/lib/scons. The "scons" script knows how to
160 # look up the library in a version-specific directory, but
161 # we have to move both it and the library directory into
162 # the right version-specific name by hand.
163 cmd.run('%(python)s setup.py build')
164 cmd.run('%(sudo)s %(python)s setup.py install --prefix=%(prefix)s')
165 cmd.run('%(sudo)s mv %(prefix)s/bin/scons %(prefix)s/bin/scons-%(version)s')
166 cmd.run('%(sudo)s mv %(prefix)s/lib/scons %(prefix)s/lib/scons-%(version)s')
168 elif version in ('0.11', '0.12', '0.13', '0.14', '0.90'):
170 # 0.11 through 0.90 install /usr/local/bin/scons and
171 # /usr/local/lib/scons-%(version)s. We just need to move
172 # the script to a version-specific name.
173 cmd.run('%(python)s setup.py build')
174 cmd.run('%(sudo)s %(python)s setup.py install --prefix=%(prefix)s')
175 cmd.run('%(sudo)s mv %(prefix)s/bin/scons %(prefix)s/bin/scons-%(version)s')
177 elif version in ('0.91', '0.92', '0.93',
180 '0.96', '0.96.1', '0.96.90'):
182 # 0.91 through 0.96.90 install /usr/local/bin/scons,
183 # /usr/local/bin/sconsign and /usr/local/lib/scons-%(version)s.
184 # We need to move both scripts to version-specific names.
185 cmd.run('%(python)s setup.py build')
186 cmd.run('%(sudo)s %(python)s setup.py install --prefix=%(prefix)s')
187 cmd.run('%(sudo)s mv %(prefix)s/bin/scons %(prefix)s/bin/scons-%(version)s')
188 cmd.run('%(sudo)s mv %(prefix)s/bin/sconsign %(prefix)s/bin/sconsign-%(version)s')
189 lib_scons = os.path.join(prefix, 'lib', 'scons')
190 if os.path.isdir(lib_scons):
191 cmd.run('%(sudo)s mv %(prefix)s/lib/scons %(prefix)s/lib/scons-%(version)s')
195 # Versions from 0.96.91 and later support what we want
196 # with a --no-scons-script option.
197 cmd.run('%(python)s setup.py build')
198 cmd.run('%(sudo)s %(python)s setup.py install --prefix=%(prefix)s --no-scons-script')
200 cmd.run((os.chdir, '..'), 'cd ..')
202 cmd.run((shutil.rmtree, scons), 'rm -rf %(scons)s')
204 if __name__ == "__main__":
209 # indent-tabs-mode:nil
211 # vim: set expandtab tabstop=4 shiftwidth=4: