Add a 'buildbot' action with knowledge of relevant packages.
[scons.git] / bin / install_scons.py
1 #!/usr/bin/env python
2 #
3 # A script for unpacking and installing different historic versions of
4 # SCons in a consistent manner for side-by-side development testing.
5 #
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.
10 #
11 # By default, we expect to extract the .tar.gz files from a Downloads
12 # subdirectory in the current directory.
13 #
14 # Note that this script cleans up after itself, removing the extracted
15 # directory in which we do the build.
16 #
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.
20
21 import getopt
22 import os
23 import shutil
24 import sys
25
26 from Command import CommandRunner, Usage
27
28 all_versions = [
29     '0.01',
30     '0.02',
31     '0.03',
32     '0.04',
33     '0.05',
34     '0.06',
35     '0.07',
36     '0.08',
37     '0.09',
38     '0.10',
39     '0.11',
40     '0.12',
41     '0.13',
42     '0.14',
43     '0.90',
44     '0.91',
45     '0.92',
46     '0.93',
47     '0.94',
48     #'0.94.1',
49     '0.95',
50     #'0.95.1',
51     '0.96',
52     '0.96.1',
53     '0.96.90',
54     '0.96.91',
55     '0.96.92',
56     '0.96.93',
57     '0.96.94',
58     '0.96.95',
59     '0.96.96',
60     '0.97',
61     '0.97.0d20070809',
62     '0.97.0d20070918',
63     '0.97.0d20071212',
64     '0.98.0',
65     '0.98.1',
66     '0.98.2',
67     '0.98.3',
68     '0.98.4',
69     '0.98.5',
70     '1.0.0',
71     '1.0.0.d20080826',
72     '1.0.1',
73     '1.0.1.d20080915',
74     '1.0.1.d20081001',
75     '1.1.0',
76 ]
77
78 def main(argv=None):
79     if argv is None:
80         argv = sys.argv
81
82     all = False
83     downloads_dir = 'Downloads'
84     downloads_url = 'http://downloads.sourceforge.net/scons'
85     sudo = 'sudo'
86     prefix = '/usr/local'
87     python = sys.executable
88
89     short_options = 'ad:hnp:q'
90     long_options = ['all', 'help', 'no-exec', 'prefix=', 'quiet']
91
92     helpstr = """\
93 Usage:  install-scons.py [-ahnq] [-d DIR] [-p PREFIX] [VERSION ...]
94
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
101 """
102
103     try:
104         try:
105             opts, args = getopt.getopt(argv[1:], short_options, long_options)
106         except getopt.error, msg:
107             raise Usage(msg)
108
109         for o, a in opts:
110             if o in ('-a', '--all'):
111                 all = True
112             elif o in ('-d', '--downloads'):
113                 downloads_dir = a
114             elif o in ('-h', '--help'):
115                 print helpstr
116                 sys.exit(0)
117             elif o in ('-n', '--no-exec'):
118                 CommandRunner.execute = CommandRunner.do_not_execute
119             elif o in ('-p', '--prefix'):
120                 prefix = a
121             elif o in ('-q', '--quiet'):
122                 CommandRunner.display = CommandRunner.do_not_display
123     except Usage, err:
124         sys.stderr.write(str(err.msg) + '\n')
125         sys.stderr.write('use -h to get help\n')
126         return 2
127
128     if all:
129         if args:
130             msg = 'install-scons.py:  -a and version arguments both specified'
131             sys.stderr.write(msg)
132             sys.exit(1)
133
134         args = all_versions
135
136     cmd = CommandRunner()
137
138     for version in args:
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')
142
143         cmd.subst_dictionary(locals())
144
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')
150
151         cmd.run('tar zxf %(tar_gz)s')
152
153         cmd.run((os.chdir, scons), 'cd %(scons)s')
154
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'):
157
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')
167
168         elif version in ('0.11', '0.12', '0.13', '0.14', '0.90'):
169
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')
176
177         elif version in ('0.91', '0.92', '0.93',
178                          '0.94', '0.94.1',
179                          '0.95', '0.95.1',
180                          '0.96', '0.96.1', '0.96.90'):
181
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')
192
193         else:
194
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')
199
200         cmd.run((os.chdir, '..'), 'cd ..')
201
202         cmd.run((shutil.rmtree, scons), 'rm -rf %(scons)s')
203
204 if __name__ == "__main__":
205     sys.exit(main())
206
207 # Local Variables:
208 # tab-width:4
209 # indent-tabs-mode:nil
210 # End:
211 # vim: set expandtab tabstop=4 shiftwidth=4: