2016-08-29 15:06:48 +03:00
|
|
|
#!/usr/bin/env python3
|
2014-04-05 03:29:58 +04:00
|
|
|
|
2015-06-20 06:43:14 +03:00
|
|
|
import getopt
|
2015-06-11 20:55:42 +03:00
|
|
|
import os
|
2019-07-06 23:40:53 +03:00
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2014-04-05 00:01:07 +04:00
|
|
|
|
2019-06-13 18:54:57 +03:00
|
|
|
from config import (
|
2019-07-06 23:40:53 +03:00
|
|
|
VIRT_BASE,
|
|
|
|
X64_EXT,
|
|
|
|
bit_from_env,
|
2019-06-13 18:54:57 +03:00
|
|
|
compiler_from_env,
|
2019-07-06 23:40:53 +03:00
|
|
|
compilers,
|
2019-06-13 18:54:57 +03:00
|
|
|
pythons,
|
|
|
|
pyversion_from_env,
|
|
|
|
)
|
2014-04-05 00:01:07 +04:00
|
|
|
|
2015-06-20 06:43:14 +03:00
|
|
|
|
2014-04-05 00:01:07 +04:00
|
|
|
def setup_vms():
|
|
|
|
ret = []
|
2017-05-28 19:34:41 +03:00
|
|
|
for py in pythons:
|
2019-06-13 18:54:57 +03:00
|
|
|
for arch in ("", X64_EXT):
|
|
|
|
ret.append(
|
|
|
|
"virtualenv -p c:/Python%s%s/python.exe --clear %s%s%s"
|
|
|
|
% (py, arch, VIRT_BASE, py, arch)
|
|
|
|
)
|
|
|
|
ret.append(
|
|
|
|
r"%s%s%s\Scripts\pip.exe install pytest pytest-cov"
|
|
|
|
% (VIRT_BASE, py, arch)
|
|
|
|
)
|
2014-04-05 00:01:07 +04:00
|
|
|
return "\n".join(ret)
|
|
|
|
|
2015-06-20 06:43:14 +03:00
|
|
|
|
2014-04-05 03:29:58 +04:00
|
|
|
def run_script(params):
|
|
|
|
(version, script) = params
|
|
|
|
try:
|
2015-06-20 06:43:14 +03:00
|
|
|
print("Running %s" % version)
|
2019-06-13 18:54:57 +03:00
|
|
|
filename = "build_pillow_%s.cmd" % version
|
|
|
|
with open(filename, "w") as f:
|
2014-04-05 03:29:58 +04:00
|
|
|
f.write(script)
|
|
|
|
|
2019-06-13 18:54:57 +03:00
|
|
|
command = ["powershell", "./%s" % filename]
|
|
|
|
proc = subprocess.Popen(
|
|
|
|
command,
|
|
|
|
stdin=subprocess.PIPE,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
)
|
2014-04-05 03:29:58 +04:00
|
|
|
(trace, stderr) = proc.communicate()
|
|
|
|
status = proc.returncode
|
2016-05-06 18:54:35 +03:00
|
|
|
print("-- stderr --")
|
2019-07-05 00:04:16 +03:00
|
|
|
print(stderr.decode())
|
2016-05-06 18:54:35 +03:00
|
|
|
print("-- stdout --")
|
2019-07-05 00:04:16 +03:00
|
|
|
print(trace.decode())
|
2019-09-30 17:56:31 +03:00
|
|
|
print("Done with {}: {}".format(version, status))
|
2014-04-05 03:29:58 +04:00
|
|
|
return (version, status, trace, stderr)
|
|
|
|
except Exception as msg:
|
2019-09-30 17:56:31 +03:00
|
|
|
print("Error with {}: {}".format(version, str(msg)))
|
2014-04-05 03:29:58 +04:00
|
|
|
return (version, -1, "", str(msg))
|
2015-06-20 06:43:14 +03:00
|
|
|
|
2014-04-05 03:29:58 +04: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%%
|
2019-06-13 18:54:57 +03:00
|
|
|
""" % (
|
|
|
|
op
|
|
|
|
)
|
2015-06-20 06:43:14 +03:00
|
|
|
|
2014-04-05 00:01:07 +04:00
|
|
|
|
|
|
|
def footer():
|
|
|
|
return """endlocal
|
|
|
|
exit
|
|
|
|
"""
|
|
|
|
|
2015-06-20 06:43:14 +03:00
|
|
|
|
2018-10-08 11:43:11 +03:00
|
|
|
def vc_setup(compiler, bit):
|
|
|
|
script = ""
|
2019-06-13 18:54:57 +03:00
|
|
|
if compiler["vc_version"] == "2015":
|
2018-10-08 11:43:11 +03:00
|
|
|
arch = "x86" if bit == 32 else "x86_amd64"
|
2019-06-13 18:54:57 +03:00
|
|
|
script = (
|
|
|
|
r"""
|
2019-09-21 21:03:24 +03:00
|
|
|
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %s
|
|
|
|
echo on"""
|
2019-06-13 18:54:57 +03:00
|
|
|
% arch
|
|
|
|
)
|
2018-10-08 11:43:11 +03:00
|
|
|
return script
|
|
|
|
|
2018-10-21 10:00:39 +03:00
|
|
|
|
2018-10-08 11:43:11 +03:00
|
|
|
def build_one(py_ver, compiler, bit):
|
2018-10-24 22:24:03 +03:00
|
|
|
# UNDONE virtual envs if we're not running on AppVeyor
|
2014-04-05 00:01:07 +04:00
|
|
|
args = {}
|
|
|
|
args.update(compiler)
|
2019-06-13 18:54:57 +03:00
|
|
|
if "PYTHON" in os.environ:
|
|
|
|
args["python_path"] = "%PYTHON%"
|
2015-06-16 19:24:51 +03:00
|
|
|
else:
|
2019-09-30 17:56:31 +03:00
|
|
|
args["python_path"] = "{}{}\\Scripts".format(VIRT_BASE, py_ver)
|
2017-07-03 23:51:39 +03:00
|
|
|
|
2019-06-13 18:54:57 +03:00
|
|
|
args["executable"] = "python.exe"
|
|
|
|
if "EXECUTABLE" in os.environ:
|
|
|
|
args["executable"] = "%EXECUTABLE%"
|
2017-10-29 16:11:00 +03:00
|
|
|
|
2019-06-13 18:54:57 +03:00
|
|
|
args["py_ver"] = py_ver
|
2019-09-26 15:12:28 +03:00
|
|
|
args["tcl_ver"] = "86"
|
2018-10-08 11:43:11 +03:00
|
|
|
|
2019-06-13 18:54:57 +03:00
|
|
|
if compiler["vc_version"] == "2015":
|
|
|
|
args["imaging_libs"] = " build_ext --add-imaging-libs=msvcrt"
|
2015-06-20 02:27:42 +03:00
|
|
|
else:
|
2019-06-13 18:54:57 +03:00
|
|
|
args["imaging_libs"] = ""
|
2015-06-20 06:43:14 +03:00
|
|
|
|
2019-06-13 18:54:57 +03:00
|
|
|
args["vc_setup"] = vc_setup(compiler, bit)
|
2018-10-24 22:24:03 +03:00
|
|
|
|
2018-10-08 11:43:11 +03:00
|
|
|
script = r"""
|
2014-04-05 00:01:07 +04:00
|
|
|
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
|
2018-10-24 22:24:03 +03:00
|
|
|
set LIB=%%LIB%%;C:\Python%(py_ver)s\tcl%(vc_setup)s
|
2018-10-08 11:43:11 +03:00
|
|
|
call %(python_path)s\%(executable)s setup.py %(imaging_libs)s %%BLDOPT%%
|
2019-09-24 09:41:30 +03:00
|
|
|
call %(python_path)s\%(executable)s -c "from PIL import _webp;import os, shutil;shutil.copy(r'%%INCLIB%%\freetype.dll', os.path.dirname(_webp.__file__));"
|
2014-04-05 00:01:07 +04:00
|
|
|
endlocal
|
|
|
|
|
|
|
|
endlocal
|
2018-11-11 23:50:12 +03:00
|
|
|
""" # noqa: E501
|
2018-10-08 11:43:11 +03:00
|
|
|
return script % args
|
2014-04-05 00:01:07 +04:00
|
|
|
|
2015-06-20 06:43:14 +03:00
|
|
|
|
2014-04-05 03:29:58 +04:00
|
|
|
def clean():
|
|
|
|
try:
|
2019-06-13 18:54:57 +03:00
|
|
|
shutil.rmtree("../build")
|
2018-11-17 00:51:52 +03:00
|
|
|
except Exception:
|
2014-04-05 03:29:58 +04:00
|
|
|
# could already be removed
|
|
|
|
pass
|
2019-06-13 18:54:57 +03:00
|
|
|
run_script(("virtualenvs", setup_vms()))
|
2014-04-05 03:29:58 +04:00
|
|
|
|
2015-06-20 06:43:14 +03:00
|
|
|
|
2014-04-05 03:29:58 +04:00
|
|
|
def main(op):
|
|
|
|
scripts = []
|
|
|
|
|
2018-10-08 11:43:11 +03:00
|
|
|
for py_version, py_info in pythons.items():
|
2019-06-13 18:54:57 +03:00
|
|
|
py_compilers = compilers[py_info["compiler"]][py_info["vc"]]
|
|
|
|
scripts.append(
|
|
|
|
(
|
|
|
|
py_version,
|
|
|
|
"\n".join(
|
|
|
|
[header(op), build_one(py_version, py_compilers[32], 32), footer()]
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
scripts.append(
|
|
|
|
(
|
2019-09-30 17:56:31 +03:00
|
|
|
"{}{}".format(py_version, X64_EXT),
|
2019-06-13 18:54:57 +03:00
|
|
|
"\n".join(
|
|
|
|
[
|
|
|
|
header(op),
|
|
|
|
build_one("%sx64" % py_version, py_compilers[64], 64),
|
|
|
|
footer(),
|
|
|
|
]
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
2015-06-20 06:43:14 +03:00
|
|
|
|
2015-06-19 07:20:52 +03:00
|
|
|
results = map(run_script, scripts)
|
2015-06-20 06:43:14 +03:00
|
|
|
|
2014-04-05 03:29:58 +04:00
|
|
|
for (version, status, trace, err) in results:
|
2019-09-30 17:56:31 +03:00
|
|
|
print("Compiled {}: {}".format(version, status and "ERR" or "OK"))
|
2015-06-20 06:43:14 +03:00
|
|
|
|
|
|
|
|
2015-06-11 20:55:42 +03:00
|
|
|
def run_one(op):
|
2015-06-20 06:43:14 +03:00
|
|
|
|
2016-08-29 15:06:48 +03:00
|
|
|
compiler = compiler_from_env()
|
|
|
|
py_version = pyversion_from_env()
|
2018-10-08 11:43:11 +03:00
|
|
|
bit = bit_from_env()
|
2015-06-11 20:55:42 +03:00
|
|
|
|
2019-06-13 18:54:57 +03:00
|
|
|
run_script(
|
|
|
|
(
|
|
|
|
py_version,
|
|
|
|
"\n".join([header(op), build_one(py_version, compiler, bit), footer()]),
|
|
|
|
)
|
|
|
|
)
|
2014-04-05 03:29:58 +04:00
|
|
|
|
2014-04-05 00:01:07 +04:00
|
|
|
|
2019-06-13 18:54:57 +03:00
|
|
|
if __name__ == "__main__":
|
2019-08-18 10:48:43 +03:00
|
|
|
opts, args = getopt.getopt(sys.argv[1:], "", ["clean", "wheel"])
|
2015-06-20 06:43:14 +03:00
|
|
|
opts = dict(opts)
|
2014-04-05 00:01:07 +04:00
|
|
|
|
2019-06-13 18:54:57 +03:00
|
|
|
if "--clean" in opts:
|
2014-04-05 03:29:58 +04:00
|
|
|
clean()
|
2015-06-20 06:43:14 +03:00
|
|
|
|
2019-06-13 18:54:57 +03:00
|
|
|
op = "install"
|
2019-08-18 10:48:43 +03:00
|
|
|
if "--wheel" in opts:
|
2016-05-24 13:20:54 +03:00
|
|
|
op = "bdist_wheel"
|
2016-08-29 15:06:48 +03:00
|
|
|
|
2019-06-13 18:54:57 +03:00
|
|
|
if "PYTHON" in os.environ:
|
2015-06-11 20:55:42 +03:00
|
|
|
run_one(op)
|
|
|
|
else:
|
|
|
|
main(op)
|