1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
#
# __COPYRIGHT__
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import os
import os.path
import string
import sys
(head, tail) = os.path.split(sys.argv[0])
if head:
os.chdir(head)
sys.argv[0] = tail
try:
import distutils.core
import distutils.command.install
import distutils.command.install_lib
import distutils.command.install_scripts
except ImportError:
sys.stderr.write("""Could not import distutils.
Building or installing SCons from this package requires that the Python
distutils be installed. See the README or README.txt file from this
package for instructions on where to find distutils for installation on
your system, or on how to install SCons from a different package.
""")
sys.exit(1)
_install = distutils.command.install.install
_install_lib = distutils.command.install_lib.install_lib
_install_scripts = distutils.command.install_scripts.install_scripts
standard_lib = 0
standalone_lib = 0
version_lib = 0
installed_lib_dir = None
installed_scripts_dir = None
def set_explicitly(name, args):
"""
Return if the installation directory was set explicitly by the
user on the command line. This is complicated by the fact that
"install --install-lib=/foo" gets turned into "install_lib
--install-dir=/foo" internally.
"""
if args[0] == "install_" + name:
s = "--install-dir="
else:
# The command is something else (usually "install")
s = "--install-%s=" % name
set = 0
length = len(s)
for a in args[1:]:
if a[:length] == s:
set = 1
break
return set
class install(_install):
user_options = _install.user_options + [
('standard-lib', None,
"install SCons library in standard Python location"),
('standalone-lib', None,
"install SCons library in separate standalone directory"),
('version-lib', None,
"install SCons library in version-specific directory")
]
boolean_options = _install.boolean_options + [
'standard-lib',
'standalone-lib',
'version-lib'
]
def initialize_options(self):
_install.initialize_options(self)
self.standard_lib = 0
self.standalone_lib = 0
self.version_lib = 0
def finalize_options(self):
_install.finalize_options(self)
global standard_lib, standalone_lib, version_lib
standard_lib = self.standard_lib
standalone_lib = self.standalone_lib
version_lib = self.version_lib
def get_scons_prefix(libdir):
"""
Return the right prefix for SCons library installation. Find
this by starting with the library installation directory
(.../site-packages, most likely) and crawling back up until we reach
a directory name beginning with "python" (or "Python").
"""
drive, head = os.path.splitdrive(libdir)
while head:
if head == os.sep:
break
head, tail = os.path.split(head)
if string.lower(tail)[:6] == "python":
# Found the Python library directory...
if sys.platform == "win32":
# ...on Win32 systems, "scons" goes in the directory:
# C:\PythonXX => C:\PythonXX\scons
return os.path.join(drive + head, tail)
else:
# ...on other systems, "scons" goes above the directory:
# /usr/lib/pythonX.X => /usr/lib/scons
return os.path.join(drive + head)
return libdir
class install_lib(_install_lib):
def initialize_options(self):
_install_lib.initialize_options(self)
global standard_lib, standalone_lib, version_lib
self.standard_lib = standard_lib
self.standalone_lib = standalone_lib
self.version_lib = version_lib
def finalize_options(self):
_install_lib.finalize_options(self)
if not set_explicitly("lib", self.distribution.script_args):
# They didn't explicitly specify the installation
# directory for libraries...
prefix = get_scons_prefix(self.install_dir)
standard_dir = os.path.join(self.install_dir, "SCons")
version_dir = os.path.join(prefix, "scons-0.11")
standalone_dir = os.path.join(prefix, "scons")
if self.version_lib:
# ...but they asked for a version-specific directory.
self.install_dir = version_dir
elif self.standalone_lib:
# ...but they asked for a standalone directory.
self.install_dir = standalone_dir
elif not self.standard_lib:
# ...and they didn't explicitly ask for the standard
# directory, so guess based on what's out there.
try:
e = filter(lambda x: x[:6] == "scons-", os.listdir(prefix))
except:
e = None
if e:
# We found a path name (e.g.) /usr/lib/scons-XXX,
# so pick the version-specific directory.
self.install_dir = version_dir
elif os.path.exists(standalone_dir) or \
not os.path.exists(standard_dir):
# There's already a standalone directory, or
# there's no SCons library in the standard
# directory, so go with the standalone.
self.install_dir = standalone_dir
global installed_lib_dir
installed_lib_dir = self.install_dir
class install_scripts(_install_scripts):
def finalize_options(self):
_install_scripts.finalize_options(self)
global installed_scripts_dir
installed_scripts_dir = self.install_dir
arguments = {
'name' : "scons",
'version' : "0.11",
'packages' : ["SCons",
"SCons.Node",
"SCons.Optik",
"SCons.Platform",
"SCons.Scanner",
"SCons.Script",
"SCons.Sig",
"SCons.Tool"],
'package_dir' : {'' : 'engine'},
'scripts' : ["script/scons"],
'cmdclass' : {'install' : install,
'install_lib' : install_lib,
'install_scripts' : install_scripts}
}
try:
if sys.argv[1] == "bdist_wininst":
arguments['data_files'] = [('.', ["script/scons.bat"])]
except IndexError:
pass
apply(distutils.core.setup, (), arguments)
if installed_lib_dir:
print "Installed SCons library modules into %s" % installed_lib_dir
if installed_scripts_dir:
print "Installed SCons script into %s" % installed_scripts_dir
|