[ci skip] Add note that this change may break SetOption() + ninja usage with fix
[scons.git] / bin / install_scons.py
blobfa260a79e2503730cedbd0a588ddddcba27de876
1 #!/usr/bin/env python
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
19 # hierarchy.
21 import getopt
22 import os
23 import shutil
24 import sys
25 import tarfile
26 from urllib.request import urlretrieve
28 from Command import CommandRunner, Usage
30 all_versions = [
31 '0.01',
32 '0.02',
33 '0.03',
34 '0.04',
35 '0.05',
36 '0.06',
37 '0.07',
38 '0.08',
39 '0.09',
40 '0.10',
41 '0.11',
42 '0.12',
43 '0.13',
44 '0.14',
45 '0.90',
46 '0.91',
47 '0.92',
48 '0.93',
49 '0.94',
50 #'0.94.1',
51 '0.95',
52 #'0.95.1',
53 '0.96',
54 '0.96.1',
55 '0.96.90',
56 '0.96.91',
57 '0.96.92',
58 '0.96.93',
59 '0.96.94',
60 '0.96.95',
61 '0.96.96',
62 '0.97',
63 '0.97.0d20070809',
64 '0.97.0d20070918',
65 '0.97.0d20071212',
66 '0.98.0',
67 '0.98.1',
68 '0.98.2',
69 '0.98.3',
70 '0.98.4',
71 '0.98.5',
72 '1.0.0',
73 '1.0.0.d20080826',
74 '1.0.1',
75 '1.0.1.d20080915',
76 '1.0.1.d20081001',
77 '1.1.0',
78 '1.1.0.d20081104',
79 '1.1.0.d20081125',
80 '1.1.0.d20081207',
81 '1.2.0',
82 '1.2.0.d20090113',
83 '1.2.0.d20090223',
84 '1.2.0.d20090905',
85 '1.2.0.d20090919',
86 '1.2.0.d20091224',
87 '1.2.0.d20100117',
88 '1.2.0.d20100306',
89 '1.3.0',
90 '1.3.0.d20100404',
91 '1.3.0.d20100501',
92 '1.3.0.d20100523',
93 '1.3.0.d20100606',
94 '2.0.0.alpha.20100508',
95 '2.0.0.beta.20100531',
96 '2.0.0.beta.20100605',
97 '2.0.0.final.0',
100 def main(argv=None):
101 if argv is None:
102 argv = sys.argv
104 all = False
105 downloads_dir = 'Downloads'
106 downloads_url = 'http://downloads.sourceforge.net/scons'
107 if sys.platform == 'win32':
108 sudo = ''
109 prefix = sys.prefix
110 else:
111 sudo = 'sudo'
112 prefix = '/usr/local'
113 python = sys.executable
115 short_options = 'ad:hnp:q'
116 long_options = ['all', 'help', 'no-exec', 'prefix=', 'quiet']
118 helpstr = """\
119 Usage: install_scons.py [-ahnq] [-d DIR] [-p PREFIX] [VERSION ...]
121 -a, --all Install all SCons versions.
122 -d DIR, --downloads=DIR Downloads directory.
123 -h, --help Print this help and exit
124 -n, --no-exec No execute, just print command lines
125 -p PREFIX, --prefix=PREFIX Installation prefix.
126 -q, --quiet Quiet, don't print command lines
129 try:
130 try:
131 opts, args = getopt.getopt(argv[1:], short_options, long_options)
132 except getopt.error as msg:
133 raise Usage(msg)
135 for o, a in opts:
136 if o in ('-a', '--all'):
137 all = True
138 elif o in ('-d', '--downloads'):
139 downloads_dir = a
140 elif o in ('-h', '--help'):
141 print(helpstr)
142 sys.exit(0)
143 elif o in ('-n', '--no-exec'):
144 CommandRunner.execute = CommandRunner.do_not_execute
145 elif o in ('-p', '--prefix'):
146 prefix = a
147 elif o in ('-q', '--quiet'):
148 CommandRunner.display = CommandRunner.do_not_display
149 except Usage as err:
150 sys.stderr.write(str(err.msg) + '\n')
151 sys.stderr.write('use -h to get help\n')
152 return 2
154 if all:
155 if args:
156 msg = 'install-scons.py: -a and version arguments both specified'
157 sys.stderr.write(msg)
158 sys.exit(1)
160 args = all_versions
162 cmd = CommandRunner()
164 for version in args:
165 scons = 'scons-' + version
166 tar_gz = os.path.join(downloads_dir, scons + '.tar.gz')
167 tar_gz_url = "%s/%s.tar.gz" % (downloads_url, scons)
169 cmd.subst_dictionary(locals())
171 if not os.path.exists(tar_gz):
172 if not os.path.exists(downloads_dir):
173 cmd.run('mkdir %(downloads_dir)s')
174 cmd.run((urlretrieve, tar_gz_url, tar_gz),
175 'wget -O %(tar_gz)s %(tar_gz_url)s')
177 def extract(tar_gz):
178 tarfile.open(tar_gz, "r:gz").extractall()
179 cmd.run((extract, tar_gz), 'tar zxf %(tar_gz)s')
181 cmd.run('cd %(scons)s')
183 if version in ('0.01', '0.02', '0.03', '0.04', '0.05',
184 '0.06', '0.07', '0.08', '0.09', '0.10'):
186 # 0.01 through 0.10 install /usr/local/bin/scons and
187 # /usr/local/lib/scons. The "scons" script knows how to
188 # look up the library in a version-specific directory, but
189 # we have to move both it and the library directory into
190 # the right version-specific name by hand.
191 cmd.run('%(python)s setup.py build')
192 cmd.run('%(sudo)s %(python)s setup.py install --prefix=%(prefix)s')
193 cmd.run('%(sudo)s mv %(prefix)s/bin/scons %(prefix)s/bin/scons-%(version)s')
194 cmd.run('%(sudo)s mv %(prefix)s/lib/scons %(prefix)s/lib/scons-%(version)s')
196 elif version in ('0.11', '0.12', '0.13', '0.14', '0.90'):
198 # 0.11 through 0.90 install /usr/local/bin/scons and
199 # /usr/local/lib/scons-%(version)s. We just need to move
200 # the script to a version-specific name.
201 cmd.run('%(python)s setup.py build')
202 cmd.run('%(sudo)s %(python)s setup.py install --prefix=%(prefix)s')
203 cmd.run('%(sudo)s mv %(prefix)s/bin/scons %(prefix)s/bin/scons-%(version)s')
205 elif version in ('0.91', '0.92', '0.93',
206 '0.94', '0.94.1',
207 '0.95', '0.95.1',
208 '0.96', '0.96.1', '0.96.90'):
210 # 0.91 through 0.96.90 install /usr/local/bin/scons,
211 # /usr/local/bin/sconsign and /usr/local/lib/scons-%(version)s.
212 # We need to move both scripts to version-specific names.
213 cmd.run('%(python)s setup.py build')
214 cmd.run('%(sudo)s %(python)s setup.py install --prefix=%(prefix)s')
215 cmd.run('%(sudo)s mv %(prefix)s/bin/scons %(prefix)s/bin/scons-%(version)s')
216 cmd.run('%(sudo)s mv %(prefix)s/bin/sconsign %(prefix)s/bin/sconsign-%(version)s')
217 lib_scons = os.path.join(prefix, 'lib', 'scons')
218 if os.path.isdir(lib_scons):
219 cmd.run('%(sudo)s mv %(prefix)s/lib/scons %(prefix)s/lib/scons-%(version)s')
221 else:
223 # Versions from 0.96.91 and later support what we want
224 # with a --no-scons-script option.
225 cmd.run('%(python)s setup.py build')
226 cmd.run('%(sudo)s %(python)s setup.py install --prefix=%(prefix)s --no-scons-script')
228 cmd.run('cd ..')
230 cmd.run((shutil.rmtree, scons), 'rm -rf %(scons)s')
232 if __name__ == "__main__":
233 sys.exit(main())
235 # Local Variables:
236 # tab-width:4
237 # indent-tabs-mode:nil
238 # End:
239 # vim: set expandtab tabstop=4 shiftwidth=4: