1#! /usr/bin/env python 2# 3# SCons - a Software Constructor 4# 5# Copyright (c) 2001 - 2016 The SCons Foundation 6# 7# Permission is hereby granted, free of charge, to any person obtaining 8# a copy of this software and associated documentation files (the 9# "Software"), to deal in the Software without restriction, including 10# without limitation the rights to use, copy, modify, merge, publish, 11# distribute, sublicense, and/or sell copies of the Software, and to 12# permit persons to whom the Software is furnished to do so, subject to 13# the following conditions: 14# 15# The above copyright notice and this permission notice shall be included 16# in all copies or substantial portions of the Software. 17# 18# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 19# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 20# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 26__revision__ = "src/script/scons.py rel_2.5.0:3544:95d356f188a3 2016/04/09 14:38:50 bdbaddog" 27 28__version__ = "2.5.0" 29 30__build__ = "rel_2.5.0:3544:95d356f188a3[MODIFIED]" 31 32__buildsys__ = "ubuntu1404-32bit" 33 34__date__ = "2016/04/09 14:38:50" 35 36__developer__ = "bdbaddog" 37 38import os 39import sys 40 41 42############################################################################## 43# BEGIN STANDARD SCons SCRIPT HEADER 44# 45# This is the cut-and-paste logic so that a self-contained script can 46# interoperate correctly with different SCons versions and installation 47# locations for the engine. If you modify anything in this section, you 48# should also change other scripts that use this same header. 49############################################################################## 50 51# Strip the script directory from sys.path() so on case-insensitive 52# (WIN32) systems Python doesn't think that the "scons" script is the 53# "SCons" package. Replace it with our own library directories 54# (version-specific first, in case they installed by hand there, 55# followed by generic) so we pick up the right version of the build 56# engine modules if they're in either directory. 57 58 59if sys.version_info >= (3,0,0): 60 msg = "scons: *** SCons version %s does not run under Python version %s.\n\ 61Python 3 is not yet supported.\n" 62 sys.stderr.write(msg % (__version__, sys.version.split()[0])) 63 sys.exit(1) 64 65 66script_dir = sys.path[0] 67 68if script_dir in sys.path: 69 sys.path.remove(script_dir) 70 71libs = [] 72 73if "SCONS_LIB_DIR" in os.environ: 74 libs.append(os.environ["SCONS_LIB_DIR"]) 75 76# - running from source takes priority (since 2.3.2), excluding SCONS_LIB_DIR settings 77script_path = os.path.abspath(os.path.dirname(__file__)) 78source_path = os.path.join(script_path, '..', 'engine') 79libs.append(source_path) 80 81local_version = 'scons-local-' + __version__ 82local = 'scons-local' 83if script_dir: 84 local_version = os.path.join(script_dir, local_version) 85 local = os.path.join(script_dir, local) 86libs.append(os.path.abspath(local_version)) 87libs.append(os.path.abspath(local)) 88 89scons_version = 'scons-%s' % __version__ 90 91# preferred order of scons lookup paths 92prefs = [] 93 94 95# - running from egg check 96try: 97 import pkg_resources 98except ImportError: 99 pass 100else: 101 # when running from an egg add the egg's directory 102 try: 103 d = pkg_resources.get_distribution('scons') 104 except pkg_resources.DistributionNotFound: 105 pass 106 else: 107 prefs.append(d.location) 108 109if sys.platform == 'win32': 110 # sys.prefix is (likely) C:\Python*; 111 # check only C:\Python*. 112 prefs.append(sys.prefix) 113 prefs.append(os.path.join(sys.prefix, 'Lib', 'site-packages')) 114else: 115 # On other (POSIX) platforms, things are more complicated due to 116 # the variety of path names and library locations. Try to be smart 117 # about it. 118 if script_dir == 'bin': 119 # script_dir is `pwd`/bin; 120 # check `pwd`/lib/scons*. 121 prefs.append(os.getcwd()) 122 else: 123 if script_dir == '.' or script_dir == '': 124 script_dir = os.getcwd() 125 head, tail = os.path.split(script_dir) 126 if tail == "bin": 127 # script_dir is /foo/bin; 128 # check /foo/lib/scons*. 129 prefs.append(head) 130 131 head, tail = os.path.split(sys.prefix) 132 if tail == "usr": 133 # sys.prefix is /foo/usr; 134 # check /foo/usr/lib/scons* first, 135 # then /foo/usr/local/lib/scons*. 136 prefs.append(sys.prefix) 137 prefs.append(os.path.join(sys.prefix, "local")) 138 elif tail == "local": 139 h, t = os.path.split(head) 140 if t == "usr": 141 # sys.prefix is /foo/usr/local; 142 # check /foo/usr/local/lib/scons* first, 143 # then /foo/usr/lib/scons*. 144 prefs.append(sys.prefix) 145 prefs.append(head) 146 else: 147 # sys.prefix is /foo/local; 148 # check only /foo/local/lib/scons*. 149 prefs.append(sys.prefix) 150 else: 151 # sys.prefix is /foo (ends in neither /usr or /local); 152 # check only /foo/lib/scons*. 153 prefs.append(sys.prefix) 154 155 temp = [os.path.join(x, 'lib') for x in prefs] 156 temp.extend([os.path.join(x, 157 'lib', 158 'python' + sys.version[:3], 159 'site-packages') for x in prefs]) 160 prefs = temp 161 162 # Add the parent directory of the current python's library to the 163 # preferences. On SuSE-91/AMD64, for example, this is /usr/lib64, 164 # not /usr/lib. 165 try: 166 libpath = os.__file__ 167 except AttributeError: 168 pass 169 else: 170 # Split /usr/libfoo/python*/os.py to /usr/libfoo/python*. 171 libpath, tail = os.path.split(libpath) 172 # Split /usr/libfoo/python* to /usr/libfoo 173 libpath, tail = os.path.split(libpath) 174 # Check /usr/libfoo/scons*. 175 prefs.append(libpath) 176 177# Look first for 'scons-__version__' in all of our preference libs, 178# then for 'scons'. 179libs.extend([os.path.join(x, scons_version) for x in prefs]) 180libs.extend([os.path.join(x, 'scons') for x in prefs]) 181 182sys.path = libs + sys.path 183 184############################################################################## 185# END STANDARD SCons SCRIPT HEADER 186############################################################################## 187 188if __name__ == "__main__": 189 try: 190 import SCons.Script 191 except ImportError: 192 print("SCons import failed. Unable to find engine files in:") 193 for path in libs: 194 print(" %s" % path) 195 raise 196 197 # this does all the work, and calls sys.exit 198 # with the proper exit status when done. 199 SCons.Script.main() 200 201# Local Variables: 202# tab-width:4 203# indent-tabs-mode:nil 204# End: 205# vim: set expandtab tabstop=4 shiftwidth=4: 206