]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45582: Fix test_embed failure during a PGO build on Windows (GH-30014)
authorneonene <53406459+neonene@users.noreply.github.com>
Fri, 10 Dec 2021 17:13:55 +0000 (02:13 +0900)
committerGitHub <noreply@github.com>
Fri, 10 Dec 2021 17:13:55 +0000 (17:13 +0000)
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
Lib/test/test_embed.py
Modules/getpath.py
PCbuild/_freeze_module.vcxproj
PCbuild/python.props
PCbuild/pythoncore.vcxproj
Python/sysmodule.c

index da918b7ba1904172ef9380acfb71ccf583301c92..ef335c69421f5ea0d6b1358cb995d9173cd95060 100644 (file)
@@ -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
index 8012d80bf3e55e1ce8bd86cf96e36e15cfffd1fc..879952413374ecf7e8e466802d33b1577b43a6d4 100644 (file)
@@ -1300,11 +1300,16 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
     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:
index 84c9760b112488a7feeb0e59f2ee4980ca93a6f7..77f951dbedef3c7e18fb381514beccaa6dfc7ee4 100644 (file)
@@ -187,7 +187,7 @@ if os_name == 'posix' or os_name == 'darwin':
 
 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']
index 2c06a8956ae4518f32c8480438532ac556bca8c5..2beb425647407a117fe511c34bd1dcec8424d3ca 100644 (file)
     <ClCompile Include="..\Python\structmember.c" />
     <ClCompile Include="..\Python\suggestions.c" />
     <ClCompile Include="..\Python\symtable.c" />
-    <ClCompile Include="..\Python\sysmodule.c" />
+    <ClCompile Include="..\Python\sysmodule.c">
+      <PreprocessorDefinitions>VPATH="$(PyVPath)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </ClCompile>
     <ClCompile Include="..\Python\thread.c" />
     <ClCompile Include="..\Python\traceback.c" />
   </ItemGroup>
index 7b85ad1c94f16ea3c63f9ec5b0ead8f60292bde2..ce860764e445fb838162301bfdd6e4693fbab6f7 100644 (file)
     <BuildPath Condition="!HasTrailingSlash($(BuildPath))">$(BuildPath)\</BuildPath>
     <BuildPath Condition="$(Configuration) == 'PGInstrument'">$(BuildPath)instrumented\</BuildPath>
     
+    <!-- VPATH definition (escaped) -->
+    <PyVPath Condition="$(Configuration) != 'PGInstrument'">..\\..</PyVPath>
+    <PyVPath Condition="$(Configuration) == 'PGInstrument'">..\\..\\..</PyVPath>
+
     <!-- Directories of external projects. tcltk is handled in tcltk.props -->
     <ExternalsDir>$(EXTERNALS_DIR)</ExternalsDir>
     <ExternalsDir Condition="$(ExternalsDir) == ''">$([System.IO.Path]::GetFullPath(`$(PySourcePath)externals`))</ExternalsDir>
index e3a71ca645143e3dc78941f0235bcb72fd2f0e4d..33abfaf53652f9e70e699c3cdb54dd93688e6f73 100644 (file)
         PREFIX=NULL;
         EXEC_PREFIX=NULL;
         VERSION=NULL;
-        VPATH="..\\..";
+        VPATH="$(PyVPath)";
         PYDEBUGEXT="$(PyDebugExt)";
         PLATLIBDIR="DLLs";
         %(PreprocessorDefinitions)
     <ClCompile Include="..\Python\suggestions.c" />
     <ClCompile Include="..\Python\structmember.c" />
     <ClCompile Include="..\Python\symtable.c" />
-    <ClCompile Include="..\Python\sysmodule.c" />
+    <ClCompile Include="..\Python\sysmodule.c">
+      <PreprocessorDefinitions>VPATH="$(PyVPath)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </ClCompile>
     <ClCompile Include="..\Python\thread.c" />
     <ClCompile Include="..\Python\traceback.c" />
   </ItemGroup>
index af4f926f0e4080379b4ac10700fa901557da7c85..f912115560704c17e8dca9f44bc5042407b08f7e 100644 (file)
@@ -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) */