tildefriends/tools/update-deps

81 lines
2.2 KiB
Python
Executable File

#!/usr/bin/python -u
import multiprocessing
import os
import platform
import shutil
import stat
import subprocess
import sys
# Disable buffering.
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
if len(sys.argv) == 1:
kWork = os.path.join('deps', sys.platform)
elif len(sys.argv) == 2:
kWork = sys.argv[1]
if not os.path.isdir(kWork):
os.makedirs(kWork)
os.chdir(kWork)
kUvRepository = 'https://github.com/libuv/libuv.git'
kUvBranch = 'v1.33.1'
kUvWork = 'uv'
cores = multiprocessing.cpu_count()
if platform.machine() == 'armv7l':
cores = 1
print 'Using', cores, 'cores.'
def run(*args, **kw):
print 'Running:', args
subprocess.check_call(*args, **kw)
def makeWritableAndRetry(function, path, exc_info):
if not os.access(path, os.W_OK):
os.chmod(path, stat.S_IWUSR)
function(path)
else:
raise
def updateUv():
print 'libuv'
print
clean = False
if os.path.exists(os.path.join(kUvWork, '.update-deps-branch')):
haveBranch = open(os.path.join(kUvWork, '.update-deps-branch'), 'r').read().strip()
if kUvBranch != haveBranch:
print haveBranch, '=>', kUvBranch
clean = True
else:
clean = True
if clean:
if os.path.isdir(os.path.join(kUvWork)):
print 'Cleaning', kUvWork
shutil.rmtree(os.path.join(kUvWork), onerror=makeWritableAndRetry)
if not os.path.isdir(kUvWork):
run(['git', 'clone', '--branch', kUvBranch, kUvRepository, kUvWork])
open(os.path.join(kUvWork, '.update-deps-branch'), 'w').write(kUvBranch)
if sys.platform in ('darwin', 'win32'):
if not os.path.isdir(os.path.join(kUvWork, 'build', 'gyp')):
run(['git', 'clone', 'https://chromium.googlesource.com/external/gyp.git', 'build/gyp'], cwd=kUvWork)
if sys.platform == 'linux2':
run(['./gyp_uv.py', '-f', 'make'], cwd=kUvWork)
run(['make', '-j' + str(cores), '-C', 'out'], cwd=kUvWork)
elif sys.platform == 'darwin':
run(['./gyp_uv.py', '-f', 'xcode'], cwd=kUvWork)
run(['xcodebuild', '-ARCHS="x86_64"', '-project', 'uv.xcodeproj', '-configuration', 'Release', '-target', 'All'], cwd=kUvWork)
elif sys.platform == 'win32':
env = os.environ.copy()
env['VCINSTALLDIR'] = ''
env['WINDOWSSDKDIR'] = ''
run(['cmd', '/C', 'call', 'vcbuild.bat', 'release', 'x64'], cwd=kUvWork, env=env)
if __name__ == '__main__':
updateUv()