-
Notifications
You must be signed in to change notification settings - Fork 152
Fix py27 vs2015 build and add patch mgmt #188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jcfr
merged 2 commits into
python-cmake-buildsystem:master
from
jcfr:fix-py27-vs2015-build-and-add-patch-mgmt
Aug 1, 2017
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
|
||
set(_x86 "(x86)") # Indirection required to avoid error related to CMP0053 | ||
find_program(PATCH_EXECUTABLE | ||
NAME patch | ||
PATHS "$ENV{ProgramFiles}/Git/usr/bin" | ||
"$ENV{ProgramFiles${_x86}}/Git/usr/bin" | ||
"$ENV{ProgramFiles}/GnuWin32/bin" | ||
"$ENV{ProgramFiles${_x86}}/GnuWin32/bin" | ||
"$ENV{ProgramFiles}/Git/bin" | ||
"$ENV{ProgramFiles${_x86}}/Git/bin" | ||
) | ||
if(NOT PATCH_EXECUTABLE) | ||
message(FATAL_ERROR "Could NOT find patch (missing: PATCH_EXECUTABLE)") | ||
endif() | ||
|
||
set(patches_dir "${Python_SOURCE_DIR}/patches") | ||
|
||
function(_apply_patches _subdir) | ||
if(NOT EXISTS ${patches_dir}/${_subdir}) | ||
message(STATUS "Skipping patches: Directory '${patches_dir}/${_subdir}' does not exist") | ||
return() | ||
endif() | ||
file(GLOB _patches RELATIVE ${patches_dir} "${patches_dir}/${_subdir}/*.patch") | ||
if(NOT _patches) | ||
return() | ||
endif() | ||
message(STATUS "") | ||
list(SORT _patches) | ||
foreach(patch IN LISTS _patches) | ||
set(msg "Applying '${patch}'") | ||
message(STATUS "${msg}") | ||
set(applied ${PROJECT_BINARY_DIR}/CMakeFiles/patches/${patch}.applied) | ||
if(EXISTS ${applied}) | ||
message(STATUS "${msg} - skipping (already applied)") | ||
continue() | ||
endif() | ||
execute_process( | ||
COMMAND ${PATCH_EXECUTABLE} --quiet -p1 -i ${patches_dir}/${patch} | ||
WORKING_DIRECTORY ${SRC_DIR} | ||
RESULT_VARIABLE result | ||
ERROR_VARIABLE error | ||
ERROR_STRIP_TRAILING_WHITESPACE | ||
OUTPUT_VARIABLE output | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
if(result EQUAL 0) | ||
message(STATUS "${msg} - done") | ||
get_filename_component(_dir ${applied} DIRECTORY) | ||
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${_dir}) | ||
execute_process(COMMAND ${CMAKE_COMMAND} -E touch ${applied}) | ||
else() | ||
message(STATUS "${msg} - failed") | ||
message(FATAL_ERROR "${output}\n${error}") | ||
endif() | ||
endforeach() | ||
message(STATUS "") | ||
endfunction() | ||
|
||
# Apply patches | ||
_apply_patches("${PY_VERSION}") | ||
_apply_patches("${PY_VERSION}/${CMAKE_SYSTEM_NAME}") | ||
_apply_patches("${PY_VERSION}/${CMAKE_SYSTEM_NAME}-${CMAKE_C_COMPILER_ID}") | ||
set(_version ${CMAKE_C_COMPILER_VERSION}) | ||
if(MSVC) | ||
set(_version ${MSVC_VERSION}) | ||
endif() | ||
_apply_patches("${PY_VERSION}/${CMAKE_SYSTEM_NAME}-${CMAKE_C_COMPILER_ID}/${_version}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
227 changes: 227 additions & 0 deletions
227
.../2.7.13/Windows-MSVC/1600/0001-VS2010-Support-Backport-Fix-13210.-Port-the-Windows-.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,227 @@ | ||
From 4988ea4f4ce6af0b567e6a2dc2c23aaf7cc5f12d Mon Sep 17 00:00:00 2001 | ||
From: Jean-Christophe Fillion-Robin <jchris.fillionr@kitware.com> | ||
Date: Mon, 31 Jul 2017 10:59:47 -0400 | ||
Subject: [PATCH 1/3] VS2010 Support: Backport "Fix #13210. Port the Windows | ||
build from VS2008 to VS2010." | ||
|
||
This commit is a partial backport of python/cpython@401f9f3. It was | ||
originally designed to work with python-cmake-buildsystem. | ||
|
||
The following modules have NOT been backported: | ||
|
||
* Tools/msi | ||
* Tools/buildbot | ||
* PCBuild | ||
--- | ||
Lib/distutils/command/build_ext.py | 2 +- | ||
Lib/distutils/msvc9compiler.py | 11 ++++++----- | ||
PC/dl_nt.c | 11 ++++++++++- | ||
PC/msvcrtmodule.c | 15 ++++++++++++++- | ||
PC/pyconfig.h | 9 +++++++-- | ||
Python/dynload_win.c | 8 ++++++++ | ||
6 files changed, 46 insertions(+), 10 deletions(-) | ||
|
||
diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py | ||
index 2c68be3..f1d184b 100644 | ||
--- a/Lib/distutils/command/build_ext.py | ||
+++ b/Lib/distutils/command/build_ext.py | ||
@@ -193,7 +193,7 @@ class build_ext (Command): | ||
# Append the source distribution include and library directories, | ||
# this allows distutils on windows to work in the source tree | ||
self.include_dirs.append(os.path.join(sys.exec_prefix, 'PC')) | ||
- if MSVC_VERSION == 9: | ||
+ if MSVC_VERSION >= 9: | ||
# Use the .lib files for the correct architecture | ||
if self.plat_name == 'win32': | ||
suffix = '' | ||
diff --git a/Lib/distutils/msvc9compiler.py b/Lib/distutils/msvc9compiler.py | ||
index 33d3e51..f6de11c 100644 | ||
--- a/Lib/distutils/msvc9compiler.py | ||
+++ b/Lib/distutils/msvc9compiler.py | ||
@@ -662,11 +662,12 @@ class MSVCCompiler(CCompiler) : | ||
if mfinfo is not None: | ||
mffilename, mfid = mfinfo | ||
out_arg = '-outputresource:%s;%s' % (output_filename, mfid) | ||
- try: | ||
- self.spawn(['mt.exe', '-nologo', '-manifest', | ||
- mffilename, out_arg]) | ||
- except DistutilsExecError, msg: | ||
- raise LinkError(msg) | ||
+ if self.__version < 10: | ||
+ try: | ||
+ self.spawn(['mt.exe', '-nologo', '-manifest', | ||
+ temp_manifest, out_arg]) | ||
+ except PackagingExecError as msg: | ||
+ raise LinkError(msg) | ||
else: | ||
log.debug("skipping %s (up-to-date)", output_filename) | ||
|
||
diff --git a/PC/dl_nt.c b/PC/dl_nt.c | ||
index ef1ce09..5ff07fd 100644 | ||
--- a/PC/dl_nt.c | ||
+++ b/PC/dl_nt.c | ||
@@ -18,7 +18,8 @@ char dllVersionBuffer[16] = ""; // a private buffer | ||
HMODULE PyWin_DLLhModule = NULL; | ||
const char *PyWin_DLLVersionString = dllVersionBuffer; | ||
|
||
-// Windows "Activation Context" work: | ||
+#if HAVE_SXS | ||
+// Windows "Activation Context" work. | ||
// Our .pyd extension modules are generally built without a manifest (ie, | ||
// those included with Python and those built with a default distutils. | ||
// This requires we perform some "activation context" magic when loading our | ||
@@ -29,6 +30,8 @@ const char *PyWin_DLLVersionString = dllVersionBuffer; | ||
// As an added complication, this magic only works on XP or later - we simply | ||
// use the existence (or not) of the relevant function pointers from kernel32. | ||
// See bug 4566 (http://python.org/sf/4566) for more details. | ||
+// In Visual Studio 2010, side by side assemblies are no longer used by | ||
+// default. | ||
|
||
typedef BOOL (WINAPI * PFN_GETCURRENTACTCTX)(HANDLE *); | ||
typedef BOOL (WINAPI * PFN_ACTIVATEACTCTX)(HANDLE, ULONG_PTR *); | ||
@@ -76,6 +79,8 @@ void _Py_DeactivateActCtx(ULONG_PTR cookie) | ||
OutputDebugString("Python failed to de-activate the activation context\n"); | ||
} | ||
|
||
+#endif /* HAVE_SXS */ | ||
+ | ||
BOOL WINAPI DllMain (HANDLE hInst, | ||
ULONG ul_reason_for_call, | ||
LPVOID lpReserved) | ||
@@ -87,17 +92,21 @@ BOOL WINAPI DllMain (HANDLE hInst, | ||
// 1000 is a magic number I picked out of the air. Could do with a #define, I spose... | ||
LoadString(hInst, 1000, dllVersionBuffer, sizeof(dllVersionBuffer)); | ||
|
||
+#if HAVE_SXS | ||
// and capture our activation context for use when loading extensions. | ||
_LoadActCtxPointers(); | ||
if (pfnGetCurrentActCtx && pfnAddRefActCtx) | ||
if ((*pfnGetCurrentActCtx)(&PyWin_DLLhActivationContext)) | ||
if (!(*pfnAddRefActCtx)(PyWin_DLLhActivationContext)) | ||
OutputDebugString("Python failed to load the default activation context\n"); | ||
+#endif | ||
break; | ||
|
||
case DLL_PROCESS_DETACH: | ||
+#if HAVE_SXS | ||
if (pfnReleaseActCtx) | ||
(*pfnReleaseActCtx)(PyWin_DLLhActivationContext); | ||
+#endif | ||
break; | ||
} | ||
return TRUE; | ||
diff --git a/PC/msvcrtmodule.c b/PC/msvcrtmodule.c | ||
index 44c82e4..68928dd 100644 | ||
--- a/PC/msvcrtmodule.c | ||
+++ b/PC/msvcrtmodule.c | ||
@@ -25,6 +25,8 @@ | ||
#ifdef _MSC_VER | ||
#if _MSC_VER >= 1500 && _MSC_VER < 1600 | ||
#include <crtassem.h> | ||
+#elif _MSC_VER >= 1600 | ||
+#include <crtversion.h> | ||
#endif | ||
#endif | ||
|
||
@@ -398,7 +400,7 @@ PyMODINIT_FUNC | ||
initmsvcrt(void) | ||
{ | ||
int st; | ||
- PyObject *d; | ||
+ PyObject *d, *version; | ||
PyObject *m = Py_InitModule("msvcrt", msvcrt_functions); | ||
if (m == NULL) | ||
return; | ||
@@ -412,6 +414,7 @@ initmsvcrt(void) | ||
insertint(d, "LK_UNLCK", _LK_UNLCK); | ||
|
||
/* constants for the crt versions */ | ||
+ (void)st; | ||
#ifdef _VC_ASSEMBLY_PUBLICKEYTOKEN | ||
st = PyModule_AddStringConstant(m, "VC_ASSEMBLY_PUBLICKEYTOKEN", | ||
_VC_ASSEMBLY_PUBLICKEYTOKEN); | ||
@@ -427,4 +430,14 @@ initmsvcrt(void) | ||
__LIBRARIES_ASSEMBLY_NAME_PREFIX); | ||
if (st < 0)return; | ||
#endif | ||
+ | ||
+/* constants for the 2010 crt versions */ | ||
+#if defined(_VC_CRT_MAJOR_VERSION) && defined (_VC_CRT_MINOR_VERSION) && defined(_VC_CRT_BUILD_VERSION) && defined(_VC_CRT_RBUILD_VERSION) | ||
+ version = PyUnicode_FromFormat("%d.%d.%d.%d", _VC_CRT_MAJOR_VERSION, | ||
+ _VC_CRT_MINOR_VERSION, | ||
+ _VC_CRT_BUILD_VERSION, | ||
+ _VC_CRT_RBUILD_VERSION); | ||
+ st = PyModule_AddObject(m, "CRT_ASSEMBLY_VERSION", version); | ||
+ if (st < 0) return NULL; | ||
+#endif | ||
} | ||
diff --git a/PC/pyconfig.h b/PC/pyconfig.h | ||
index 5d1c90a..b60af1e 100644 | ||
--- a/PC/pyconfig.h | ||
+++ b/PC/pyconfig.h | ||
@@ -231,14 +231,19 @@ typedef int pid_t; | ||
#define hypot _hypot | ||
#endif | ||
|
||
-#endif /* _MSC_VER */ | ||
+/* Side by Side assemblies supported in VS 2005 and VS 2008 but not 2010*/ | ||
+#if _MSC_VER >= 1400 && _MSC_VER < 1600 | ||
+#define HAVE_SXS 1 | ||
+#endif | ||
|
||
/* define some ANSI types that are not defined in earlier Win headers */ | ||
-#if defined(_MSC_VER) && _MSC_VER >= 1200 | ||
+#if _MSC_VER >= 1200 | ||
/* This file only exists in VC 6.0 or higher */ | ||
#include <basetsd.h> | ||
#endif | ||
|
||
+#endif /* _MSC_VER */ | ||
+ | ||
/* ------------------------------------------------------------------------*/ | ||
/* The Borland compiler defines __BORLANDC__ */ | ||
/* XXX These defines are likely incomplete, but should be easy to fix. */ | ||
diff --git a/Python/dynload_win.c b/Python/dynload_win.c | ||
index 4e5555e..8626642 100644 | ||
--- a/Python/dynload_win.c | ||
+++ b/Python/dynload_win.c | ||
@@ -12,8 +12,10 @@ | ||
#include <windows.h> | ||
|
||
// "activation context" magic - see dl_nt.c... | ||
+#if HAVE_SXS | ||
extern ULONG_PTR _Py_ActivateActCtx(); | ||
void _Py_DeactivateActCtx(ULONG_PTR cookie); | ||
+#endif | ||
|
||
const struct filedescr _PyImport_DynLoadFiletab[] = { | ||
#ifdef _DEBUG | ||
@@ -176,7 +178,9 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, | ||
char pathbuf[260]; | ||
LPTSTR dummy; | ||
unsigned int old_mode; | ||
+#if HAVE_SXS | ||
ULONG_PTR cookie = 0; | ||
+#endif | ||
/* We use LoadLibraryEx so Windows looks for dependent DLLs | ||
in directory of pathname first. However, Windows95 | ||
can sometimes not work correctly unless the absolute | ||
@@ -190,11 +194,15 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, | ||
sizeof(pathbuf), | ||
pathbuf, | ||
&dummy)) { | ||
+#if HAVE_SXS | ||
ULONG_PTR cookie = _Py_ActivateActCtx(); | ||
+#endif | ||
/* XXX This call doesn't exist in Windows CE */ | ||
hDLL = LoadLibraryEx(pathname, NULL, | ||
LOAD_WITH_ALTERED_SEARCH_PATH); | ||
+#if HAVE_SXS | ||
_Py_DeactivateActCtx(cookie); | ||
+#endif | ||
} | ||
|
||
/* restore old error mode settings */ | ||
-- | ||
2.5.0 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because
PythonApplyPatches.cmake
usesPY_VERSION
, this block should come after the block below that extracts the version from the source.