[653ac08] | 1 | #!/usr/bin/env python |
---|
| 2 | # encoding: ISO8859-1 |
---|
[904702d] | 3 | # Thomas Nagy, 2005-2015 |
---|
[653ac08] | 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 | |
---|
[904702d] | 33 | import os, sys, inspect |
---|
[653ac08] | 34 | |
---|
[904702d] | 35 | VERSION="1.8.7" |
---|
| 36 | REVISION="073060339ba56c09e143ed641610cbec" |
---|
| 37 | GIT="x" |
---|
[653ac08] | 38 | INSTALL='' |
---|
[904702d] | 39 | C1='#/' |
---|
| 40 | C2='#-' |
---|
| 41 | C3='#+' |
---|
[653ac08] | 42 | cwd = os.getcwd() |
---|
| 43 | join = os.path.join |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | WAF='waf' |
---|
| 47 | def b(x): |
---|
| 48 | return x |
---|
| 49 | if sys.hexversion>0x300000f: |
---|
| 50 | WAF='waf3' |
---|
| 51 | def b(x): |
---|
| 52 | return x.encode() |
---|
| 53 | |
---|
| 54 | def err(m): |
---|
| 55 | print(('\033[91mError: %s\033[0m' % m)) |
---|
| 56 | sys.exit(1) |
---|
| 57 | |
---|
[904702d] | 58 | def unpack_wafdir(dir, src): |
---|
| 59 | f = open(src,'rb') |
---|
[653ac08] | 60 | c = 'corrupt archive (%d)' |
---|
| 61 | while 1: |
---|
| 62 | line = f.readline() |
---|
| 63 | if not line: err('run waf-light from a folder containing waflib') |
---|
| 64 | if line == b('#==>\n'): |
---|
| 65 | txt = f.readline() |
---|
| 66 | if not txt: err(c % 1) |
---|
| 67 | if f.readline() != b('#<==\n'): err(c % 2) |
---|
| 68 | break |
---|
| 69 | if not txt: err(c % 3) |
---|
[904702d] | 70 | txt = txt[1:-1].replace(b(C1), b('\n')).replace(b(C2), b('\r')).replace(b(C3), b('\x00')) |
---|
[653ac08] | 71 | |
---|
| 72 | import shutil, tarfile |
---|
| 73 | try: shutil.rmtree(dir) |
---|
| 74 | except OSError: pass |
---|
| 75 | try: |
---|
[904702d] | 76 | for x in ('Tools', 'extras'): |
---|
[653ac08] | 77 | os.makedirs(join(dir, 'waflib', x)) |
---|
| 78 | except OSError: |
---|
[6ed0f4e] | 79 | err("Cannot unpack waf lib into %s\nMove waf in a writable directory" % dir) |
---|
[653ac08] | 80 | |
---|
| 81 | os.chdir(dir) |
---|
| 82 | tmp = 't.bz2' |
---|
| 83 | t = open(tmp,'wb') |
---|
[6ed0f4e] | 84 | try: t.write(txt) |
---|
| 85 | finally: t.close() |
---|
[653ac08] | 86 | |
---|
| 87 | try: |
---|
| 88 | t = tarfile.open(tmp) |
---|
| 89 | except: |
---|
| 90 | try: |
---|
| 91 | os.system('bunzip2 t.bz2') |
---|
| 92 | t = tarfile.open('t') |
---|
| 93 | tmp = 't' |
---|
| 94 | except: |
---|
| 95 | os.chdir(cwd) |
---|
| 96 | try: shutil.rmtree(dir) |
---|
| 97 | except OSError: pass |
---|
| 98 | err("Waf cannot be unpacked, check that bzip2 support is present") |
---|
| 99 | |
---|
[6ed0f4e] | 100 | try: |
---|
| 101 | for x in t: t.extract(x) |
---|
| 102 | finally: |
---|
| 103 | t.close() |
---|
[653ac08] | 104 | |
---|
[904702d] | 105 | for x in ('Tools', 'extras'): |
---|
[653ac08] | 106 | os.chmod(join('waflib',x), 493) |
---|
| 107 | |
---|
| 108 | if sys.hexversion<0x300000f: |
---|
| 109 | sys.path = [join(dir, 'waflib')] + sys.path |
---|
| 110 | import fixpy2 |
---|
| 111 | fixpy2.fixdir(dir) |
---|
| 112 | |
---|
[c101fe1] | 113 | os.remove(tmp) |
---|
[653ac08] | 114 | os.chdir(cwd) |
---|
| 115 | |
---|
| 116 | try: dir = unicode(dir, 'mbcs') |
---|
| 117 | except: pass |
---|
| 118 | try: |
---|
| 119 | from ctypes import windll |
---|
| 120 | windll.kernel32.SetFileAttributesW(dir, 2) |
---|
| 121 | except: |
---|
| 122 | pass |
---|
| 123 | |
---|
| 124 | def test(dir): |
---|
| 125 | try: |
---|
| 126 | os.stat(join(dir, 'waflib')) |
---|
| 127 | return os.path.abspath(dir) |
---|
| 128 | except OSError: |
---|
| 129 | pass |
---|
| 130 | |
---|
| 131 | def find_lib(): |
---|
[904702d] | 132 | src = os.path.abspath(inspect.getfile(inspect.getmodule(err))) |
---|
| 133 | base, name = os.path.split(src) |
---|
[653ac08] | 134 | |
---|
| 135 | #devs use $WAFDIR |
---|
| 136 | w=test(os.environ.get('WAFDIR', '')) |
---|
| 137 | if w: return w |
---|
| 138 | |
---|
| 139 | #waf-light |
---|
| 140 | if name.endswith('waf-light'): |
---|
| 141 | w = test(base) |
---|
| 142 | if w: return w |
---|
| 143 | err('waf-light requires waflib -> export WAFDIR=/folder') |
---|
| 144 | |
---|
| 145 | dirname = '%s-%s-%s' % (WAF, VERSION, REVISION) |
---|
[904702d] | 146 | for i in (INSTALL,'/usr','/usr/local','/opt'): |
---|
[653ac08] | 147 | w = test(i + '/lib/' + dirname) |
---|
| 148 | if w: return w |
---|
| 149 | |
---|
| 150 | #waf-local |
---|
| 151 | dir = join(base, (sys.platform != 'win32' and '.' or '') + dirname) |
---|
| 152 | w = test(dir) |
---|
| 153 | if w: return w |
---|
| 154 | |
---|
| 155 | #unpack |
---|
[904702d] | 156 | unpack_wafdir(dir, src) |
---|
[653ac08] | 157 | return dir |
---|
| 158 | |
---|
| 159 | wafdir = find_lib() |
---|
| 160 | sys.path.insert(0, wafdir) |
---|
| 161 | |
---|
| 162 | if __name__ == '__main__': |
---|
[6ed0f4e] | 163 | |
---|
[653ac08] | 164 | from waflib import Scripting |
---|
| 165 | Scripting.waf_entry_point(cwd, VERSION, wafdir) |
---|
| 166 | |
---|