From 3f398a77d37b5dfd51dabbc362d482a482fa885a Mon Sep 17 00:00:00 2001
From: neonene <53406459+neonene@users.noreply.github.com>
Date: Sat, 11 Dec 2021 02:13:55 +0900
Subject: [PATCH] bpo-45582: Fix test_embed failure during a PGO build on
Windows (GH-30014)
This defines VPATH differently in PGO instrumentation builds, to account for a different default output directory. It also adds sys._vpath on Windows to make the value available to sysconfig so that it can be used in tests.
---
Lib/sysconfig.py | 1 +
Lib/test/test_embed.py | 11 ++++++++---
Modules/getpath.py | 2 +-
PCbuild/_freeze_module.vcxproj | 4 +++-
PCbuild/python.props | 4 ++++
PCbuild/pythoncore.vcxproj | 6 ++++--
Python/sysmodule.c | 2 ++
7 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py
index da918b7ba19041..ef335c69421f5e 100644
--- a/Lib/sysconfig.py
+++ b/Lib/sysconfig.py
@@ -616,6 +616,7 @@ def get_config_vars(*args):
if os.name == 'nt':
_init_non_posix(_CONFIG_VARS)
+ _CONFIG_VARS['VPATH'] = sys._vpath
if os.name == 'posix':
_init_posix(_CONFIG_VARS)
# For backward compatibility, see issue19555
diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py
index 8012d80bf3e55e..879952413374ec 100644
--- a/Lib/test/test_embed.py
+++ b/Lib/test/test_embed.py
@@ -1300,11 +1300,16 @@ def test_init_pybuilddir(self):
def test_init_pybuilddir_win32(self):
# Test path configuration with pybuilddir.txt configuration file
- with self.tmpdir_with_python(r'PCbuild\arch') as tmpdir:
+ vpath = sysconfig.get_config_var("VPATH")
+ subdir = r'PCbuild\arch'
+ if os.path.normpath(vpath).count(os.sep) == 2:
+ subdir = os.path.join(subdir, 'instrumented')
+
+ with self.tmpdir_with_python(subdir) as tmpdir:
# The prefix is dirname(executable) + VPATH
- prefix = os.path.normpath(os.path.join(tmpdir, r'..\..'))
+ prefix = os.path.normpath(os.path.join(tmpdir, vpath))
# The stdlib dir is dirname(executable) + VPATH + 'Lib'
- stdlibdir = os.path.normpath(os.path.join(tmpdir, r'..\..\Lib'))
+ stdlibdir = os.path.normpath(os.path.join(tmpdir, vpath, 'Lib'))
filename = os.path.join(tmpdir, 'pybuilddir.txt')
with open(filename, "w", encoding="utf8") as fp:
diff --git a/Modules/getpath.py b/Modules/getpath.py
index 84c9760b112488..77f951dbedef3c 100644
--- a/Modules/getpath.py
+++ b/Modules/getpath.py
@@ -187,7 +187,7 @@
elif os_name == 'nt':
BUILDDIR_TXT = 'pybuilddir.txt'
- BUILD_LANDMARK = r'..\..\Modules\Setup.local'
+ BUILD_LANDMARK = f'{VPATH}\\Modules\\Setup.local'
DEFAULT_PROGRAM_NAME = f'python'
STDLIB_SUBDIR = 'Lib'
STDLIB_LANDMARKS = [f'{STDLIB_SUBDIR}\\os.py', f'{STDLIB_SUBDIR}\\os.pyc']
diff --git a/PCbuild/_freeze_module.vcxproj b/PCbuild/_freeze_module.vcxproj
index 2c06a8956ae451..2beb425647407a 100644
--- a/PCbuild/_freeze_module.vcxproj
+++ b/PCbuild/_freeze_module.vcxproj
@@ -226,7 +226,9 @@
-
+
+ VPATH="$(PyVPath)";%(PreprocessorDefinitions)
+
diff --git a/PCbuild/python.props b/PCbuild/python.props
index 7b85ad1c94f16e..ce860764e445fb 100644
--- a/PCbuild/python.props
+++ b/PCbuild/python.props
@@ -53,6 +53,10 @@
$(BuildPath)\
$(BuildPath)instrumented\
+
+ ..\\..
+ ..\\..\\..
+
$(EXTERNALS_DIR)
$([System.IO.Path]::GetFullPath(`$(PySourcePath)externals`))
diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj
index e3a71ca645143e..33abfaf53652f9 100644
--- a/PCbuild/pythoncore.vcxproj
+++ b/PCbuild/pythoncore.vcxproj
@@ -115,7 +115,7 @@
PREFIX=NULL;
EXEC_PREFIX=NULL;
VERSION=NULL;
- VPATH="..\\..";
+ VPATH="$(PyVPath)";
PYDEBUGEXT="$(PyDebugExt)";
PLATLIBDIR="DLLs";
%(PreprocessorDefinitions)
@@ -519,7 +519,9 @@
-
+
+ VPATH="$(PyVPath)";%(PreprocessorDefinitions)
+
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index af4f926f0e4080..f912115560704c 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -2823,6 +2823,8 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
goto type_init_failed;
}
}
+
+ SET_SYS_FROM_STRING("_vpath", VPATH);
#endif
/* float repr style: 0.03 (short) vs 0.029999999999999999 (legacy) */