Pillow/winbuild/build.py

161 lines
4.3 KiB
Python
Raw Normal View History

#/usr/bin/env python3
import subprocess
import shutil
2015-06-20 06:43:14 +03:00
import sys
import getopt
import os
2014-04-05 00:01:07 +04:00
from config import *
2015-06-20 06:43:14 +03:00
2014-04-05 00:01:07 +04:00
def setup_vms():
ret = []
for py in pythons.keys():
for arch in ('', X64_EXT):
2015-06-26 10:39:13 +03:00
ret.append("virtualenv -p c:/Python%s%s/python.exe --clear %s%s%s"
% (py, arch, VIRT_BASE, py, arch))
2014-08-23 08:35:01 +04:00
ret.append("%s%s%s\Scripts\pip.exe install nose" %
(VIRT_BASE, py, arch))
if py == '26':
ret.append("%s%s%s\Scripts\pip.exe install unittest2" %
(VIRT_BASE, py, arch))
2014-04-05 00:01:07 +04:00
return "\n".join(ret)
2015-06-20 06:43:14 +03:00
def run_script(params):
(version, script) = params
try:
2015-06-20 06:43:14 +03:00
print("Running %s" % version)
filename = 'build_pillow_%s.cmd' % version
with open(filename, 'w') as f:
f.write(script)
2015-06-20 06:43:14 +03:00
command = ['powershell', "./%s" % filename]
proc = subprocess.Popen(command,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
(trace, stderr) = proc.communicate()
status = proc.returncode
2016-05-06 18:54:35 +03:00
print("-- stderr --")
2015-06-20 06:43:14 +03:00
print(stderr)
2016-05-06 18:54:35 +03:00
print("-- stdout --")
print(trace)
2015-06-20 06:43:14 +03:00
print("Done with %s: %s" % (version, status))
return (version, status, trace, stderr)
except Exception as msg:
2015-06-20 06:43:14 +03:00
print("Error with %s: %s" % (version, str(msg)))
return (version, -1, "", str(msg))
2015-06-20 06:43:14 +03:00
2014-04-05 00:01:07 +04:00
def header(op):
2015-06-20 04:34:34 +03:00
return r"""
2014-04-05 00:01:07 +04:00
setlocal
set MPLSRC=%%~dp0\..
set INCLIB=%%~dp0\depends
set BLDOPT=%s
cd /D %%MPLSRC%%
2015-06-20 06:43:14 +03:00
""" % (op)
2014-04-05 00:01:07 +04:00
def footer():
return """endlocal
exit
"""
2015-06-20 06:43:14 +03:00
2014-04-05 00:01:07 +04:00
def build_one(py_ver, compiler):
# UNDONE virtual envs if we're not running on appveyor
2014-04-05 00:01:07 +04:00
args = {}
args.update(compiler)
2015-06-16 19:24:51 +03:00
if 'PYTHON' in os.environ:
2015-06-20 06:43:14 +03:00
args['python_path'] = "%PYTHON%"
2015-06-16 19:24:51 +03:00
else:
args['python_path'] = "%s%s\\Scripts" % (VIRT_BASE, py_ver)
2014-04-05 00:01:07 +04:00
args['py_ver'] = py_ver
2016-05-06 18:54:35 +03:00
if '34' in py_ver:
2016-05-10 14:35:47 +03:00
args['tcl_ver'] = '86'
2015-06-20 02:27:42 +03:00
else:
args['tcl_ver'] = '85'
2015-06-20 06:43:14 +03:00
2014-04-05 00:01:07 +04:00
return r"""
setlocal EnableDelayedExpansion
call "%%ProgramFiles%%\Microsoft SDKs\Windows\%(env_version)s\Bin\SetEnv.Cmd" /Release %(env_flags)s
set DISTUTILS_USE_SDK=1
set LIB=%%LIB%%;%%INCLIB%%\%(inc_dir)s
2015-06-20 02:27:42 +03:00
set INCLUDE=%%INCLUDE%%;%%INCLIB%%\%(inc_dir)s;%%INCLIB%%\tcl%(tcl_ver)s\include
2014-04-05 00:01:07 +04:00
setlocal
set LIB=%%LIB%%;C:\Python%(py_ver)s\tcl
2015-06-16 19:24:51 +03:00
call %(python_path)s\python.exe setup.py %%BLDOPT%%
2014-04-05 00:01:07 +04:00
endlocal
endlocal
""" % args
2015-06-20 06:43:14 +03:00
def clean():
try:
shutil.rmtree('../build')
except:
# could already be removed
pass
run_script(('virtualenvs', setup_vms()))
2015-06-20 06:43:14 +03:00
def main(op):
scripts = []
for py_version, compiler_version in pythons.items():
2015-06-20 06:43:14 +03:00
scripts.append((py_version,
"\n".join([header(op),
2015-06-20 06:43:14 +03:00
build_one(py_version,
2015-06-26 10:39:13 +03:00
compilers[(compiler_version,
32)]),
footer()])))
2015-06-20 06:43:14 +03:00
scripts.append(("%s%s" % (py_version, X64_EXT),
2015-06-20 06:43:14 +03:00
"\n".join([header(op),
build_one("%sx64" % py_version,
2015-06-26 10:39:13 +03:00
compilers[(compiler_version,
64)]),
footer()])))
2015-06-20 06:43:14 +03:00
results = map(run_script, scripts)
2015-06-20 06:43:14 +03:00
for (version, status, trace, err) in results:
2015-06-20 06:43:14 +03:00
print("Compiled %s: %s" % (version, status and 'ERR' or 'OK'))
def run_one(op):
2015-06-20 06:43:14 +03:00
2015-06-11 23:11:26 +03:00
compiler = compiler_fromEnv()
py_version = pyversion_fromEnv()
run_script((py_version,
"\n".join([header(op),
2015-06-11 23:11:26 +03:00
build_one(py_version, compiler),
footer()])
2015-06-20 06:43:14 +03:00
))
2014-04-05 00:01:07 +04:00
2015-06-20 06:43:14 +03:00
if __name__ == '__main__':
2016-05-24 13:20:54 +03:00
opts, args = getopt.getopt(sys.argv[1:], '', ['clean', 'dist', 'wheel'])
2015-06-20 06:43:14 +03:00
opts = dict(opts)
2014-04-05 00:01:07 +04:00
if '--clean' in opts:
clean()
2015-06-20 06:43:14 +03:00
op = 'install'
if '--dist' in opts:
op = "bdist_wininst --user-access-control=auto"
2016-05-24 13:20:54 +03:00
elif '--wheel' in opts:
op = "bdist_wheel"
if 'PYTHON' in os.environ:
run_one(op)
else:
main(op)