Files

187 lines
9.2 KiB
Python
Raw Permalink Normal View History

2018-02-25 13:23:21 +01:00
# Copyright (C) 2015 Sebastian Herbord. All rights reserved.
2019-07-08 17:30:49 -05:00
# Copyright (C) 2016 - 2019 Mod Organizer contributors.
2015-09-26 22:00:59 +02:00
#
# This file is part of Mod Organizer.
#
# Mod Organizer is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Mod Organizer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
2017-09-21 16:34:22 +02:00
import errno
import os
2015-11-29 16:52:31 +01:00
import shutil
import patch
2015-11-29 16:52:31 +01:00
from glob import glob
2019-10-29 13:42:24 -05:00
from subprocess import Popen
import logging
2015-09-26 22:00:59 +02:00
2017-09-21 16:34:22 +02:00
from config import config
from unibuild.modules import build, github, msbuild, urldownload, sourceforge
2017-09-21 16:34:22 +02:00
from unibuild.project import Project
2019-10-29 13:42:24 -05:00
from unibuild.projects import openssl
from unibuild.utility.visualstudio import get_visual_studio
2019-05-10 07:02:25 +02:00
from unibuild.utility.config_utility import make_sure_path_exists
2015-09-26 22:00:59 +02:00
2018-03-06 22:27:38 +01:00
path_install = config["paths"]["install"]
python_version = config['python_version']
python_version_minor = config['python_version_minor']
bzip2_version = config['bzip2_version']
2019-10-29 13:42:24 -05:00
openssl_version = config['openssl_version']
build_path = config["paths"]["build"]
2015-09-26 22:00:59 +02:00
2017-09-21 16:34:22 +02:00
2019-12-13 03:02:22 -06:00
def bitness():
return "amd64" if config["architecture"] == "x86_64" else "win32"
2019-10-29 13:42:24 -05:00
def python_environment(context):
result = config['__environment'].copy()
2019-10-29 13:42:24 -05:00
result['PYTHONHOME'] = context["build_path"]
return result
2015-11-29 16:52:31 +01:00
def patch_openssl_props(context):
patch_file = os.path.join(config['__Umbrella_path'], "patches", "python_openssl_path.patch")
savedpath = os.getcwd()
tarpath = os.path.join(context["build_path"])
os.chdir(tarpath)
pset = patch.fromfile(patch_file)
pset.apply()
os.chdir(savedpath)
return True
def upgrade_args():
devenv_path = os.path.join(config['paths']['visual_studio_base'], "Common7", "IDE")
# MSVC2017 supports building with the MSVC2015 toolset though this will break here,
# Small work around to make sure devenv.exe exists
2017-09-21 16:34:22 +02:00
# If not try MSVC2017 instead
res = os.path.isfile(os.path.join(devenv_path, "devenv.exe"))
if res:
return [os.path.join(devenv_path, "devenv.exe"),
2017-09-21 16:34:22 +02:00
"PCBuild/pcbuild.sln",
"/upgrade"]
2020-09-29 19:22:00 -05:00
return [os.path.join(get_visual_studio(config["vs_version"]), "..", "..", "..", "Common7", "IDE", "devenv.exe"),
2018-03-06 22:27:38 +01:00
"PCBuild/pcbuild.sln", "/upgrade"]
def python_prepare(context):
shutil.copy(os.path.join(python['build_path'], "PC", "pyconfig.h"),
os.path.join(python['build_path'], "Include", "pyconfig.h"))
return True
2019-10-29 13:42:24 -05:00
class PydCompiler(build.Builder):
def __init__(self):
super(PydCompiler, self).__init__()
@property
def name(self):
return "pyd compiler"
def process(self, progress):
soutpath = os.path.join(self._context["build_path"], "stdout.log")
serrpath = os.path.join(self._context["build_path"], "stderr.log")
with open(soutpath, "w") as sout:
with open(serrpath, "w") as serr:
logging.debug("Packaging python files")
2019-10-29 13:42:24 -05:00
bp = self._context['build_path']
2019-12-13 03:02:22 -06:00
pyp = os.path.join(bp, "PCbuild", "{}".format(bitness()))
2019-10-29 13:42:24 -05:00
proc = Popen([os.path.join(bp, "python.bat"), "PC/layout",
"-vv",
"-s", bp,
"-b", pyp,
"-t", os.path.join(pyp, "pythoncore_temp"),
"--copy", os.path.join(pyp, "pythoncore"),
"--preset-embed"
],
env=python_environment(self._context),
cwd=bp,
shell=True,
stdout=sout, stderr=serr)
proc.communicate()
if proc.returncode != 0:
logging.error("failed to run cpython PC/layout gen (returncode %s), see %s and %s",
proc.returncode, soutpath, serrpath)
return False
return True
2018-03-06 22:27:38 +01:00
def install(context):
make_sure_path_exists(os.path.join(path_install, "libs"))
make_sure_path_exists(os.path.join(context["build_path"], "libs"))
2020-11-27 07:32:21 -05:00
make_sure_path_exists(os.path.join(path_install, "bin"))
2020-01-07 16:28:45 -06:00
make_sure_path_exists(os.path.join(path_install, "pdb"))
2019-12-13 03:02:22 -06:00
path_segments = [context['build_path'], "PCbuild", bitness()]
2019-10-29 13:42:24 -05:00
for f in glob(os.path.join(*path_segments, "*.lib")):
2018-03-06 22:27:38 +01:00
shutil.copy(f, os.path.join(path_install, "libs"))
for f in glob(os.path.join(*path_segments, "*.lib")):
shutil.copy(f, os.path.join(context["build_path"], "libs"))
2020-11-27 07:32:21 -05:00
shutil.copy(os.path.join(*path_segments, "python{}.dll".format(python_version.replace(".", ""))), os.path.join(path_install, "bin"))
shutil.copy(os.path.join(*path_segments, "python{}.dll".format(python_version.replace(".", ""))), os.path.join(context["build_path"], "libs"))
2020-06-12 10:43:25 -05:00
for f in glob(os.path.join(*path_segments, "libffi-*.dll")):
2020-11-27 07:32:21 -05:00
shutil.copy(f, os.path.join(path_install, "bin"))
shutil.copy(os.path.join(*path_segments, "python{}.pdb".format(python_version.replace(".", ""))), os.path.join(path_install, "pdb"))
2020-06-12 10:43:25 -05:00
for f in glob(os.path.join(*path_segments, "_*.pdb")):
2019-10-29 13:47:22 -05:00
shutil.copy(f, os.path.join(path_install, "pdb"))
2018-03-06 22:27:38 +01:00
return True
2017-09-21 16:34:22 +02:00
2015-11-29 16:52:31 +01:00
if config.get('Appveyor_Build', True):
python = Project("Python") \
.depend(build.Execute(install)
.depend(urldownload.URLDownload(
config.get('prebuilt_url') + "python-prebuilt-{}.7z"
.format(python_version + python_version_minor)).
set_destination("python-{}".format(python_version + python_version_minor))))
else:
2019-12-13 03:02:22 -06:00
Project("libffi").depend(github.Source("python", "cpython-bin-deps", "libffi", shallowclone=True).set_destination("libffi"))
python = Project("Python") \
.depend(build.Execute(install)
.depend(build.Execute(python_prepare)
2019-10-29 13:42:24 -05:00
.depend(PydCompiler()
.depend(msbuild.MSBuild("PCBuild/PCBuild.sln", "python,pythonw,python3dll,select,pyexpat,unicodedata,_queue,_bz2,_ssl,_overlapped",
2019-10-29 13:42:24 -05:00
project_PlatformToolset=config['vc_platformtoolset'],
reltarget="Release",
2019-10-29 13:42:24 -05:00
project_AdditionalParams=[
"/p:bz2Dir={}".format(os.path.join(build_path, "bzip2")),
"/p:zlibDir={}".format(os.path.join(build_path, "zlib-{}".format(config['zlib_version']))),
"/p:opensslIncludeDir={}".format(os.path.join(build_path, "openssl-{}".format(openssl_version), "include")),
2019-12-13 03:02:22 -06:00
"/p:opensslOutDir={}".format(os.path.join(build_path, "openssl-{}".format(openssl_version))),
"/p:libffiIncludeDir={}".format(os.path.join(build_path, "libffi", bitness(), "include")),
"/p:libffiOutDir={}".format(os.path.join(build_path, "libffi", bitness())),
2019-10-29 13:42:24 -05:00
]
)
.depend(build.Execute(patch_openssl_props)
.depend(build.Run(upgrade_args, name="upgrade python project")
.depend(github.Source("python", "cpython", "v{}{}"
.format(config['python_version'],
config['python_version_minor'])
, shallowclone=True)
.set_destination("python-{}".format(python_version + python_version_minor))
.depend(sourceforge.Release("bzip2","bzip2-{0}.tar.gz"
.format(bzip2_version), tree_depth=1)
.set_destination("bzip2")
)
2019-10-29 13:42:24 -05:00
)
)
)
.depend("openssl")
2019-12-13 03:02:22 -06:00
.depend("libffi")
2019-10-29 13:42:24 -05:00
)
)
)
)