From 2c6b3b9a3593e9eeb5da0af54dfff3b0810dcea6 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Tue, 21 Aug 2018 00:30:46 +0800 Subject: g-ir-tool-template.in: Don't hardcode /usr/bin/env For Visual Studio builds, it is likely that we specify a specific Python installation as there may well be multiple Python installations, but _giscanner.pyd gets tied to the particular Python DLL that it was built with. So, we cannot just use /usr/bin/env python3 in such a case on Visual Studio, but instead we use the full path to the Python executable in the shebang so that the correct Python installation is used, when running the installed scripts. This is necessary as Meson could bump the Python version it requires but _giscanner.pyd could not be used on the newer Python that is required due to differences in the Python version and the CRT Python itself is linked to, for instance. We continue to use /usr/bin/env python[2|3] for other builds. --- Makefile-tools.am | 2 +- tools/g-ir-tool-template.in | 2 +- tools/meson.build | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Makefile-tools.am b/Makefile-tools.am index 8c4a069b..c70d9850 100644 --- a/Makefile-tools.am +++ b/Makefile-tools.am @@ -9,7 +9,7 @@ EXTRA_DIST += \ tools/g-ir-tool-template.in \ tools/meson.build -TOOL_SUBSTITUTIONS = -e s,@libdir\@,$(libdir), -e s,@datarootdir\@,$(datarootdir), -e s,@PYTHON\@,$(PYTHON), +TOOL_SUBSTITUTIONS = -e s,@libdir\@,$(libdir), -e s,@datarootdir\@,$(datarootdir), -e s,@PYTHON_CMD\@,\/usr\/bin\/env\ $(PYTHON), g-ir-scanner: tools/g-ir-tool-template.in _giscanner.la Makefile $(AM_V_GEN) sed $(TOOL_SUBSTITUTIONS) -e s,@TOOL_MODULE\@,scannermain, -e s,@TOOL_FUNCTION\@,scanner_main, $< > $@.tmp && mv $@.tmp $@ diff --git a/tools/g-ir-tool-template.in b/tools/g-ir-tool-template.in index 83279bd4..fb6b665b 100755 --- a/tools/g-ir-tool-template.in +++ b/tools/g-ir-tool-template.in @@ -1,4 +1,4 @@ -#!/usr/bin/env @PYTHON@ +#!@PYTHON_CMD@ # -*- Mode: Python -*- # GObject-Introspection - a framework for introspecting GObject libraries # Copyright (C) 2008 Johan Dahlin diff --git a/tools/meson.build b/tools/meson.build index 73472664..912eb6ba 100644 --- a/tools/meson.build +++ b/tools/meson.build @@ -9,13 +9,18 @@ if get_option('doctool') tools += [['g-ir-doc-tool', 'docmain', 'doc_main']] endif -python_name = 'python@0@'.format(python.language_version().split('.')[0]) +if cc.get_id() == 'msvc' + python_cmd = python.get_variable('prefix') + '\\python.exe' +else + python_cmd = '/usr/bin/env python@0@'.format(python.language_version().split('.')[0]) +endif + tool_output = [] foreach tool : tools tools_conf = configuration_data() tools_conf.set('libdir', libdir_abs) tools_conf.set('datarootdir', datadir_abs) - tools_conf.set('PYTHON', python_name) + tools_conf.set('PYTHON_CMD', python_cmd) tools_conf.set('TOOL_MODULE', tool[1]) tools_conf.set('TOOL_FUNCTION', tool[2]) -- cgit v1.2.1 From 032eac543d7aa44dbc4af3f4fd94be1dc4a93caf Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Tue, 21 Aug 2018 09:14:23 +0800 Subject: Revert "scanner: remove some unnecessary Windows includes" We need those includes and defines as we need to revert the commit that revert the hacks on Windows, as they are still necessary in the cases where we are using a Python installation that is not linked to the CRT that the currently used compiler targets to, such as on Visual Studio 2012 and 2013, where no official Python release is linked to their respective CRTs. This reverts commit e36350e3fdcb18a21089256b63298d6e3a49212b. --- giscanner/giscannermodule.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/giscanner/giscannermodule.c b/giscanner/giscannermodule.c index a024f1a0..5fc2fd4d 100644 --- a/giscanner/giscannermodule.c +++ b/giscanner/giscannermodule.c @@ -24,7 +24,15 @@ #endif #include #include "sourcescanner.h" -#include + +#ifdef _WIN32 +#include +#include +#define WIN32_LEAN_AND_MEAN +#define STRICT +#include +#endif + #include #ifndef Py_TYPE -- cgit v1.2.1 From 2a6fc83276e9ced066ea08aed591f40bba0409eb Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Tue, 21 Aug 2018 09:04:08 +0800 Subject: Revert "scanner: remove hacks to make mingw g-i work with msvc Python" Unfortunately, this is still needed for Visual Studio versions that do not have an official CPython release that uses the CRT which the compiler targets to, such as Visual Studio 2012 and 2013 This reverts commit a6a479af1bbe7c0d17766f1408c9fcb720df78dc. --- giscanner/giscannermodule.c | 84 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/giscanner/giscannermodule.c b/giscanner/giscannermodule.c index 5fc2fd4d..c37357bd 100644 --- a/giscanner/giscannermodule.c +++ b/giscanner/giscannermodule.c @@ -447,6 +447,90 @@ pygi_source_scanner_parse_file (PyGISourceScanner *self, if (!PyArg_ParseTuple (args, "i:SourceScanner.parse_file", &fd)) return NULL; +#ifdef _WIN32 + /* The file descriptor passed to us is from the C library Python + * uses. That is msvcr71.dll for Python 2.5 and msvcr90.dll for + * Python 2.6, 2.7, 3.2 etc; and msvcr100.dll for Python 3.3 and 3.4. + * Python 3.5 and later is built with Visual Studio 2015, which uses + * the universal CRT, so we need to deal with urtbase.dll here instead. + * This code, at least if compiled with mingw, uses + * msvcrt.dll, so we cannot use the file descriptor directly. So + * perform appropriate magic. + */ + + /* If we are using the following combinations, + * we can use the file descriptors directly + * (Not if a build using WDK is used): + * Python 2.6.x/2.7.x with Visual C++ 2008 + * Python 3.1.x/3.2.x with Visual C++ 2008 + * Python 3.3.x/3.4.x with Visual C++ 2010 + */ + + /* XXX: Somehow we cannot use the FD directly on Python 3.5+ even when + * using Visual Studio 2015, so we currently need to use _get_osfhandle() when + * in all cases on Python 3.5+ + */ + +#if (defined(_MSC_VER) && !defined(USE_WIN_DDK)) +#if (PY_MAJOR_VERSION==2 && PY_MINOR_VERSION>=6 && (_MSC_VER >= 1500 && _MSC_VER < 1600)) +#define MSVC_USE_FD_DIRECTLY 1 +#elif (PY_MAJOR_VERSION==3 && PY_MINOR_VERSION<=2 && (_MSC_VER >= 1500 && _MSC_VER < 1600)) +#define MSVC_USE_FD_DIRECTLY 1 +#elif (PY_MAJOR_VERSION==3 && PY_MINOR_VERSION<=4 && (_MSC_VER >= 1600 && _MSC_VER < 1700)) +#define MSVC_USE_FD_DIRECTLY 1 +#endif +#endif + +#if !defined(MSVC_USE_FD_DIRECTLY) && !defined(__MINGW64_VERSION_MAJOR) + { +#if defined(PY_MAJOR_VERSION) && PY_MAJOR_VERSION==2 && PY_MINOR_VERSION==5 +#define PYTHON_MSVCRXX_DLL "msvcr71.dll" +#elif defined(PY_MAJOR_VERSION) && PY_MAJOR_VERSION==2 && PY_MINOR_VERSION==7 +#define PYTHON_MSVCRXX_DLL "msvcr90.dll" +#elif defined(PY_MAJOR_VERSION) && PY_MAJOR_VERSION==3 && PY_MINOR_VERSION<=2 +#define PYTHON_MSVCRXX_DLL "msvcr90.dll" +#elif defined(PY_MAJOR_VERSION) && PY_MAJOR_VERSION==3 && PY_MINOR_VERSION<=4 +#define PYTHON_MSVCRXX_DLL "msvcr100.dll" +#elif defined(PY_MAJOR_VERSION) && PY_MAJOR_VERSION==3 && PY_MINOR_VERSION>=5 +#define PYTHON_MSVCRXX_DLL "ucrtbase.dll" +#else +#error This Python version not handled +#endif + HMODULE msvcrxx; + intptr_t (*p__get_osfhandle) (int); + HANDLE handle; + + msvcrxx = GetModuleHandle (PYTHON_MSVCRXX_DLL); + if (!msvcrxx) + { + g_print ("No " PYTHON_MSVCRXX_DLL " loaded.\n"); + return NULL; + } + + p__get_osfhandle = (intptr_t (*) (int)) GetProcAddress (msvcrxx, "_get_osfhandle"); + if (!p__get_osfhandle) + { + g_print ("No _get_osfhandle found in " PYTHON_MSVCRXX_DLL ".\n"); + return NULL; + } + + handle = (HANDLE) p__get_osfhandle (fd); + if (!p__get_osfhandle) + { + g_print ("Could not get OS handle from " PYTHON_MSVCRXX_DLL " fd.\n"); + return NULL; + } + + fd = _open_osfhandle ((intptr_t) handle, _O_RDONLY); + if (fd == -1) + { + g_print ("Could not open C fd from OS handle.\n"); + return NULL; + } + } +#endif +#endif + fp = fdopen (fd, "r"); if (!fp) { -- cgit v1.2.1