Skip to content

Commit 3f398a7

Browse files
authored
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.
1 parent 036bbb1 commit 3f398a7

File tree

7 files changed

+23
-7
lines changed

7 files changed

+23
-7
lines changed

Lib/sysconfig.py

+1
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ def get_config_vars(*args):
616616

617617
if os.name == 'nt':
618618
_init_non_posix(_CONFIG_VARS)
619+
_CONFIG_VARS['VPATH'] = sys._vpath
619620
if os.name == 'posix':
620621
_init_posix(_CONFIG_VARS)
621622
# For backward compatibility, see issue19555

Lib/test/test_embed.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1300,11 +1300,16 @@ def test_init_pybuilddir(self):
13001300
def test_init_pybuilddir_win32(self):
13011301
# Test path configuration with pybuilddir.txt configuration file
13021302

1303-
with self.tmpdir_with_python(r'PCbuild\arch') as tmpdir:
1303+
vpath = sysconfig.get_config_var("VPATH")
1304+
subdir = r'PCbuild\arch'
1305+
if os.path.normpath(vpath).count(os.sep) == 2:
1306+
subdir = os.path.join(subdir, 'instrumented')
1307+
1308+
with self.tmpdir_with_python(subdir) as tmpdir:
13041309
# The prefix is dirname(executable) + VPATH
1305-
prefix = os.path.normpath(os.path.join(tmpdir, r'..\..'))
1310+
prefix = os.path.normpath(os.path.join(tmpdir, vpath))
13061311
# The stdlib dir is dirname(executable) + VPATH + 'Lib'
1307-
stdlibdir = os.path.normpath(os.path.join(tmpdir, r'..\..\Lib'))
1312+
stdlibdir = os.path.normpath(os.path.join(tmpdir, vpath, 'Lib'))
13081313

13091314
filename = os.path.join(tmpdir, 'pybuilddir.txt')
13101315
with open(filename, "w", encoding="utf8") as fp:

Modules/getpath.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187

188188
elif os_name == 'nt':
189189
BUILDDIR_TXT = 'pybuilddir.txt'
190-
BUILD_LANDMARK = r'..\..\Modules\Setup.local'
190+
BUILD_LANDMARK = f'{VPATH}\\Modules\\Setup.local'
191191
DEFAULT_PROGRAM_NAME = f'python'
192192
STDLIB_SUBDIR = 'Lib'
193193
STDLIB_LANDMARKS = [f'{STDLIB_SUBDIR}\\os.py', f'{STDLIB_SUBDIR}\\os.pyc']

PCbuild/_freeze_module.vcxproj

+3-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@
226226
<ClCompile Include="..\Python\structmember.c" />
227227
<ClCompile Include="..\Python\suggestions.c" />
228228
<ClCompile Include="..\Python\symtable.c" />
229-
<ClCompile Include="..\Python\sysmodule.c" />
229+
<ClCompile Include="..\Python\sysmodule.c">
230+
<PreprocessorDefinitions>VPATH="$(PyVPath)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
231+
</ClCompile>
230232
<ClCompile Include="..\Python\thread.c" />
231233
<ClCompile Include="..\Python\traceback.c" />
232234
</ItemGroup>

PCbuild/python.props

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
<BuildPath Condition="!HasTrailingSlash($(BuildPath))">$(BuildPath)\</BuildPath>
5454
<BuildPath Condition="$(Configuration) == 'PGInstrument'">$(BuildPath)instrumented\</BuildPath>
5555

56+
<!-- VPATH definition (escaped) -->
57+
<PyVPath Condition="$(Configuration) != 'PGInstrument'">..\\..</PyVPath>
58+
<PyVPath Condition="$(Configuration) == 'PGInstrument'">..\\..\\..</PyVPath>
59+
5660
<!-- Directories of external projects. tcltk is handled in tcltk.props -->
5761
<ExternalsDir>$(EXTERNALS_DIR)</ExternalsDir>
5862
<ExternalsDir Condition="$(ExternalsDir) == ''">$([System.IO.Path]::GetFullPath(`$(PySourcePath)externals`))</ExternalsDir>

PCbuild/pythoncore.vcxproj

+4-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
PREFIX=NULL;
116116
EXEC_PREFIX=NULL;
117117
VERSION=NULL;
118-
VPATH="..\\..";
118+
VPATH="$(PyVPath)";
119119
PYDEBUGEXT="$(PyDebugExt)";
120120
PLATLIBDIR="DLLs";
121121
%(PreprocessorDefinitions)
@@ -519,7 +519,9 @@
519519
<ClCompile Include="..\Python\suggestions.c" />
520520
<ClCompile Include="..\Python\structmember.c" />
521521
<ClCompile Include="..\Python\symtable.c" />
522-
<ClCompile Include="..\Python\sysmodule.c" />
522+
<ClCompile Include="..\Python\sysmodule.c">
523+
<PreprocessorDefinitions>VPATH="$(PyVPath)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
524+
</ClCompile>
523525
<ClCompile Include="..\Python\thread.c" />
524526
<ClCompile Include="..\Python\traceback.c" />
525527
</ItemGroup>

Python/sysmodule.c

+2
Original file line numberDiff line numberDiff line change
@@ -2823,6 +2823,8 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
28232823
goto type_init_failed;
28242824
}
28252825
}
2826+
2827+
SET_SYS_FROM_STRING("_vpath", VPATH);
28262828
#endif
28272829

28282830
/* float repr style: 0.03 (short) vs 0.029999999999999999 (legacy) */

0 commit comments

Comments
 (0)