| 1 |
|
| 2 |
from __future__ import print_function |
| 3 |
import sys |
| 4 |
import os |
| 5 |
import subprocess |
| 6 |
import tempfile |
| 7 |
|
| 8 |
mydir = os.path.dirname(os.path.abspath(__file__)) |
| 9 |
TAR_OPTIONS = '-x -v --strip-components=2' |
| 10 |
TAR = 'tar {options} -f {tarfile} {files}' |
| 11 |
UNZIP_OPTIONS = '-j' |
| 12 |
UNZIP = 'unzip {options} {zipfile} {files}' |
| 13 |
|
| 14 |
def untar(tarfile, files): |
| 15 |
if tarfile.endswith('zip'): |
| 16 |
cmd = UNZIP.format(options=UNZIP_OPTIONS, zipfile=tarfile, files=files) |
| 17 |
else: |
| 18 |
cmd = TAR.format(options=TAR_OPTIONS, tarfile=tarfile, files=files) |
| 19 |
os.system(cmd) |
| 20 |
|
| 21 |
tarbz = 'tar.bz2' |
| 22 |
if sys.platform.startswith('linux'): |
| 23 |
arch = 'linux' |
| 24 |
cmd = 'wget "%s"' |
| 25 |
TAR_OPTIONS += ' --wildcards' |
| 26 |
binfiles = "'*/bin/pypy3*' '*/bin/libpypy3-c.so*'" |
| 27 |
if os.uname()[-1].startswith('arm'): |
| 28 |
arch += '-armhf-raspbian' |
| 29 |
elif sys.platform.startswith('darwin'): |
| 30 |
arch = 'osx' |
| 31 |
cmd = 'curl -O "%s"' |
| 32 |
binfiles = "'*/bin/pypy3'" |
| 33 |
elif sys.platform == 'win32': |
| 34 |
arch = 'win' |
| 35 |
cmd = 'wget "%s"' |
| 36 |
binfiles = "'pypy*.exe' '*.dll'" |
| 37 |
tarbz = "zip" |
| 38 |
else: |
| 39 |
print('Cannot determine the platform, please update this script') |
| 40 |
sys.exit(1) |
| 41 |
|
| 42 |
if sys.maxsize == 2**63 - 1: |
| 43 |
arch += '64' |
| 44 |
|
| 45 |
branch = subprocess.check_output('git rev-parse --abbrev-ref HEAD'.split()).strip().decode('utf-8') |
| 46 |
if branch == 'default': |
| 47 |
branch = 'main' |
| 48 |
|
| 49 |
if '--nojit' in sys.argv: |
| 50 |
kind = 'nojit' |
| 51 |
else: |
| 52 |
kind = 'jit' |
| 53 |
|
| 54 |
filename = 'pypy-c-%s-latest-%s.%s' % (kind, arch, tarbz) |
| 55 |
url = 'http://buildbot.pypy.org/nightly/%s/%s' % (branch, filename) |
| 56 |
tmp = tempfile.mkdtemp() |
| 57 |
pypy_latest = os.path.join(tmp, filename) |
| 58 |
olddir = os.getcwd() |
| 59 |
os.chdir(tmp) |
| 60 |
print('Downloading pypy to', tmp) |
| 61 |
if os.system(cmd % url) != 0: |
| 62 |
sys.exit(1) |
| 63 |
|
| 64 |
print('Extracting pypy binary to', mydir) |
| 65 |
os.chdir(mydir) |
| 66 |
untar(pypy_latest, binfiles) |
| 67 |
include_dir = os.path.join(mydir, '..', '..', 'include') |
| 68 |
lib_dir = os.path.join(mydir, '..', 'lib') |
| 69 |
if os.path.isdir(include_dir): |
| 70 |
os.chdir(include_dir) |
| 71 |
untar(pypy_latest, '*/include/*') |
| 72 |
else: |
| 73 |
print('WARNING: could not find the include/ dir') |
| 74 |
os.chdir(olddir) |
| 75 |
if not os.path.exists(lib_dir): |
| 76 |
os.mkdir(lib_dir) |
| 77 |
os.chdir(lib_dir) |
| 78 |
untar(pypy_latest, '*/lib/*') |
| 79 |
os.chdir(olddir) |
| 80 |
|