waf-light (4246B)
1 #!/usr/bin/env python 2 # encoding: latin-1 3 # Thomas Nagy, 2005-2018 4 # 5 """ 6 Redistribution and use in source and binary forms, with or without 7 modification, are permitted provided that the following conditions 8 are met: 9 10 1. Redistributions of source code must retain the above copyright 11 notice, this list of conditions and the following disclaimer. 12 13 2. Redistributions in binary form must reproduce the above copyright 14 notice, this list of conditions and the following disclaimer in the 15 documentation and/or other materials provided with the distribution. 16 17 3. The name of the author may not be used to endorse or promote products 18 derived from this software without specific prior written permission. 19 20 THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 21 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 24 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 POSSIBILITY OF SUCH DAMAGE. 31 """ 32 33 import os, sys, inspect 34 35 VERSION="2.0.25" 36 REVISION="x" 37 GIT="x" 38 INSTALL="x" 39 C1='x' 40 C2='x' 41 C3='x' 42 cwd = os.getcwd() 43 join = os.path.join 44 45 if sys.hexversion<0x206000f: 46 raise ImportError('Python >= 2.6 is required to create the waf file') 47 48 WAF='waf' 49 def b(x): 50 return x 51 if sys.hexversion>0x300000f: 52 WAF='waf3' 53 def b(x): 54 return x.encode() 55 56 def err(m): 57 print(('\033[91mError: %s\033[0m' % m)) 58 sys.exit(1) 59 60 def unpack_wafdir(dir, src): 61 f = open(src,'rb') 62 c = 'corrupt archive (%d)' 63 while 1: 64 line = f.readline() 65 if not line: err('run waf-light from a folder containing waflib') 66 if line == b('#==>\n'): 67 txt = f.readline() 68 if not txt: err(c % 1) 69 if f.readline() != b('#<==\n'): err(c % 2) 70 break 71 if not txt: err(c % 3) 72 txt = txt[1:-1].replace(b(C1), b('\n')).replace(b(C2), b('\r')).replace(b(C3), b('\x00')) 73 74 import shutil, tarfile 75 try: shutil.rmtree(dir) 76 except OSError: pass 77 try: 78 for x in ('Tools', 'extras'): 79 os.makedirs(join(dir, 'waflib', x)) 80 except OSError: 81 err("Cannot unpack waf lib into %s\nMove waf in a writable directory" % dir) 82 83 os.chdir(dir) 84 tmp = 't.bz2' 85 t = open(tmp,'wb') 86 try: t.write(txt) 87 finally: t.close() 88 89 try: 90 t = tarfile.open(tmp) 91 except: 92 try: 93 os.system('bunzip2 t.bz2') 94 t = tarfile.open('t') 95 tmp = 't' 96 except: 97 os.chdir(cwd) 98 try: shutil.rmtree(dir) 99 except OSError: pass 100 err("Waf cannot be unpacked, check that bzip2 support is present") 101 102 try: 103 for x in t: t.extract(x) 104 finally: 105 t.close() 106 107 for x in ('Tools', 'extras'): 108 os.chmod(join('waflib',x), 493) 109 110 if sys.hexversion<0x300000f: 111 sys.path = [join(dir, 'waflib')] + sys.path 112 import fixpy2 113 fixpy2.fixdir(dir) 114 115 os.remove(tmp) 116 os.chdir(cwd) 117 118 try: dir = unicode(dir, 'mbcs') 119 except: pass 120 try: 121 from ctypes import windll 122 windll.kernel32.SetFileAttributesW(dir, 2) 123 except: 124 pass 125 126 def test(dir): 127 try: 128 os.stat(join(dir, 'waflib')) 129 return os.path.abspath(dir) 130 except OSError: 131 pass 132 133 def find_lib(): 134 src = os.path.abspath(inspect.getfile(inspect.getmodule(err))) 135 base, name = os.path.split(src) 136 137 #devs use $WAFDIR 138 w=test(os.environ.get('WAFDIR', '')) 139 if w: return w 140 141 #waf-light 142 if name.endswith('waf-light'): 143 w = test(base) 144 if w: return w 145 for dir in sys.path: 146 if test(dir): 147 return dir 148 err('waf-light requires waflib -> export WAFDIR=/folder') 149 150 dirname = '%s-%s-%s' % (WAF, VERSION, REVISION) 151 for i in (INSTALL,'/usr','/usr/local','/opt'): 152 w = test(i + '/lib/' + dirname) 153 if w: return w 154 155 #waf-local 156 dir = join(base, (sys.platform != 'win32' and '.' or '') + dirname) 157 w = test(dir) 158 if w: return w 159 160 #unpack 161 unpack_wafdir(dir, src) 162 return dir 163 164 wafdir = find_lib() 165 sys.path.insert(0, wafdir) 166 167 if __name__ == '__main__': 168 #import waflib.extras.compat15#PRELUDE 169 from waflib import Scripting 170 Scripting.waf_entry_point(cwd, VERSION, wafdir) 171