| 1 |
#!/usr/bin/env python |
|---|
| 2 |
# encoding: utf-8 |
|---|
| 3 |
# Thomas Nagy, 2005-2009 |
|---|
| 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 |
|---|
| 34 |
if sys.hexversion<0x203000f: raise ImportError("Waf requires Python >= 2.3") |
|---|
| 35 |
|
|---|
| 36 |
if 'PSYCOWAF' in os.environ: |
|---|
| 37 |
try:import psyco;psyco.full() |
|---|
| 38 |
except:pass |
|---|
| 39 |
|
|---|
| 40 |
VERSION="1.5.4" |
|---|
| 41 |
REVISION="2b784c8f011b1ba2d603528e440a4a27" |
|---|
| 42 |
INSTALL='' |
|---|
| 43 |
C1='#.' |
|---|
| 44 |
C2='#(' |
|---|
| 45 |
cwd = os.getcwd() |
|---|
| 46 |
join = os.path.join |
|---|
| 47 |
|
|---|
| 48 |
WAF='waf' |
|---|
| 49 |
def b(x): |
|---|
| 50 |
return x |
|---|
| 51 |
|
|---|
| 52 |
if sys.hexversion>0x300000f: |
|---|
| 53 |
WAF='waf3' |
|---|
| 54 |
def b(x): |
|---|
| 55 |
return x.encode() |
|---|
| 56 |
|
|---|
| 57 |
def err(m): |
|---|
| 58 |
print(('\033[91mError: %s\033[0m' % m)) |
|---|
| 59 |
sys.exit(1) |
|---|
| 60 |
|
|---|
| 61 |
def unpack_wafdir(dir): |
|---|
| 62 |
f = open(sys.argv[0],'rb') |
|---|
| 63 |
c = "corrupted waf (%d)" |
|---|
| 64 |
while 1: |
|---|
| 65 |
line = f.readline() |
|---|
| 66 |
if not line: err("run waf-light from a folder containing wafadmin") |
|---|
| 67 |
if line == b('#==>\n'): |
|---|
| 68 |
txt = f.readline() |
|---|
| 69 |
if not txt: err(c % 1) |
|---|
| 70 |
if f.readline()!=b('#<==\n'): err(c % 2) |
|---|
| 71 |
break |
|---|
| 72 |
if not txt: err(c % 3) |
|---|
| 73 |
txt = txt[1:-1].replace(b(C1), b('\n')).replace(b(C2), b('\r')) |
|---|
| 74 |
|
|---|
| 75 |
import shutil, tarfile |
|---|
| 76 |
try: shutil.rmtree(dir) |
|---|
| 77 |
except OSError: pass |
|---|
| 78 |
try: os.makedirs(join(dir, 'wafadmin', 'Tools')) |
|---|
| 79 |
except OSError: err("Cannot unpack waf lib into %s\nMove waf into a writeable directory" % dir) |
|---|
| 80 |
|
|---|
| 81 |
os.chdir(dir) |
|---|
| 82 |
tmp = 't.tbz2' |
|---|
| 83 |
t = open(tmp,'wb') |
|---|
| 84 |
t.write(txt) |
|---|
| 85 |
t.close() |
|---|
| 86 |
|
|---|
| 87 |
t = tarfile.open(tmp) |
|---|
| 88 |
for x in t: t.extract(x) |
|---|
| 89 |
t.close() |
|---|
| 90 |
|
|---|
| 91 |
os.chmod(join('wafadmin','Tools'), 493) |
|---|
| 92 |
|
|---|
| 93 |
os.unlink(tmp) |
|---|
| 94 |
|
|---|
| 95 |
if sys.hexversion>0x300000f: |
|---|
| 96 |
sys.path = [join(dir, 'wafadmin')] + sys.path |
|---|
| 97 |
import py3kfixes |
|---|
| 98 |
py3kfixes.fixdir(dir) |
|---|
| 99 |
|
|---|
| 100 |
os.chdir(cwd) |
|---|
| 101 |
|
|---|
| 102 |
def test(dir): |
|---|
| 103 |
try: os.stat(join(dir, 'wafadmin')); return os.path.abspath(dir) |
|---|
| 104 |
except OSError: pass |
|---|
| 105 |
|
|---|
| 106 |
def find_lib(): |
|---|
| 107 |
name = sys.argv[0] |
|---|
| 108 |
base = os.path.dirname(os.path.abspath(name)) |
|---|
| 109 |
|
|---|
| 110 |
#devs use $WAFDIR |
|---|
| 111 |
w=test(os.environ.get('WAFDIR', '')) |
|---|
| 112 |
if w: return w |
|---|
| 113 |
|
|---|
| 114 |
#waf-light |
|---|
| 115 |
if name.endswith('waf-light'): |
|---|
| 116 |
w = test(base) |
|---|
| 117 |
if w: return w |
|---|
| 118 |
err("waf-light requires wafadmin -> export WAFDIR=/folder") |
|---|
| 119 |
|
|---|
| 120 |
dir = "/lib/%s-%s-%s/" % (WAF, VERSION, REVISION) |
|---|
| 121 |
for i in [INSTALL,'/usr','/usr/local','/opt']: |
|---|
| 122 |
w = test(i+dir) |
|---|
| 123 |
if w: return w |
|---|
| 124 |
|
|---|
| 125 |
#waf-local |
|---|
| 126 |
s = '.%s-%s-%s' |
|---|
| 127 |
if sys.platform == 'win32': s = s[1:] |
|---|
| 128 |
dir = join(base, s % (WAF, VERSION, REVISION)) |
|---|
| 129 |
w = test(dir) |
|---|
| 130 |
if w: return w |
|---|
| 131 |
|
|---|
| 132 |
#unpack |
|---|
| 133 |
unpack_wafdir(dir) |
|---|
| 134 |
return dir |
|---|
| 135 |
|
|---|
| 136 |
wafdir = find_lib() |
|---|
| 137 |
w = join(wafdir, 'wafadmin') |
|---|
| 138 |
t = join(w, 'Tools') |
|---|
| 139 |
sys.path = [w, t] + sys.path |
|---|
| 140 |
|
|---|
| 141 |
import Scripting |
|---|
| 142 |
Scripting.prepare(t, cwd, VERSION, wafdir) |
|---|
| 143 |
sys.exit(0) |
|---|
| 144 |
|
|---|
| 145 |
#==> |
|---|
| 146 |
#BZh91AY&SYrš |
|---|
| 147 |
tÿÿ¹`ÿÿÿÿÿÿÿÿÿÿÿÿT#.Á$
Download in other formats:
|
|---|