Speed up adding children to the various Node lists (depends, ignore, sources, implicit).
[scons.git] / bootstrap.py
1 """bootstrap.py
2
3 This is an Aegis-to-SCons build script that collects a copy of the
4 current SCons into a bootstrap/ subdirectory and then executes it with
5 the supplied command-line options.
6
7 Right now, it only understands the SCons -Y option, which is the only
8 one currently used.  It collects the repositories specified by -Y and
9 searches them, in order, for the pieces of SCons to copy into the local
10 bootstrap/ subdirectory.
11
12 This is essentially a minimal build of SCons to bootstrap ourselves into
13 executing it for the full build of all the packages, as specified in our
14 local SConstruct file.
15
16 """
17
18 #
19 # Copyright (c) 2001, 2002, 2003 Steven Knight
20 #
21 # Permission is hereby granted, free of charge, to any person obtaining
22 # a copy of this software and associated documentation files (the
23 # "Software"), to deal in the Software without restriction, including
24 # without limitation the rights to use, copy, modify, merge, publish,
25 # distribute, sublicense, and/or sell copies of the Software, and to
26 # permit persons to whom the Software is furnished to do so, subject to
27 # the following conditions:
28 #
29 # The above copyright notice and this permission notice shall be included
30 # in all copies or substantial portions of the Software.
31 #
32 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
33 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
34 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 #
40
41 import os
42 import os.path
43 import getopt
44 import string
45 import sys
46
47 search = ['.']
48
49 opts, args = getopt.getopt(sys.argv[1:], "Y:", [])
50
51 for o, a in opts:
52     if o == '-Y':
53         search.append(a)
54
55 def find(file, search=search):
56     for dir in search:
57         f = os.path.join(dir, file)
58         if os.path.exists(f):
59             return os.path.normpath(f)
60     sys.stderr.write("could not find `%s' in search path:\n" % file)
61     sys.stderr.write("\t" + string.join(search, "\n\t") + "\n")
62     sys.exit(2)
63
64 scons_py = os.path.join('src', 'script', 'scons.py')
65 src_engine = os.path.join('src', 'engine')
66 MANIFEST_in = find(os.path.join(src_engine, 'MANIFEST.in'))
67
68 files = [ scons_py ] + map(lambda x: os.path.join(src_engine, x[:-1]),
69                            open(MANIFEST_in).readlines())
70
71 subdir = 'bootstrap'
72
73 for file in files:
74     src = find(file)
75     dst = os.path.join(subdir, file)
76     dir, _ = os.path.split(dst)
77     if not os.path.isdir(dir):
78         os.makedirs(dir)
79     contents = open(src, 'rb').read()
80     try: os.unlink(dst)
81     except: pass
82     open(dst, 'wb').write(contents)
83
84 args = [ sys.executable, os.path.join(subdir, scons_py) ] + sys.argv[1:]
85
86 sys.stdout.write(string.join(args, " ") + '\n')
87 sys.stdout.flush()
88
89 os.environ['SCONS_LIB_DIR'] = os.path.join(subdir, src_engine)
90
91 os.execve(sys.executable, args, os.environ)