Skip to content

Commit 4f6854a

Browse files
bpo-35299: Fixed sysconfig and distutils during PGO profiling (GH-11744)
(cherry picked from commit 85e102a) Co-authored-by: Steve Dower <[email protected]>
1 parent 44467e8 commit 4f6854a

File tree

6 files changed

+40
-14
lines changed

6 files changed

+40
-14
lines changed

Lib/distutils/command/build_ext.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,10 @@ def finalize_options(self):
161161

162162
# Put the Python "system" include dir at the end, so that
163163
# any local include dirs take precedence.
164-
self.include_dirs.append(py_include)
164+
self.include_dirs.extend(py_include.split(os.path.pathsep))
165165
if plat_py_include != py_include:
166-
self.include_dirs.append(plat_py_include)
166+
self.include_dirs.extend(
167+
plat_py_include.split(os.path.pathsep))
167168

168169
self.ensure_string_list('libraries')
169170
self.ensure_string_list('link_objects')

Lib/distutils/sysconfig.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
project_base = os.path.abspath(os.environ["_PYTHON_PROJECT_BASE"])
3030
else:
3131
project_base = os.path.dirname(os.path.abspath(sys.executable))
32-
if (os.name == 'nt' and
33-
project_base.lower().endswith(('\\pcbuild\\win32', '\\pcbuild\\amd64'))):
34-
project_base = os.path.dirname(os.path.dirname(project_base))
32+
3533

3634
# python_build: (Boolean) if true, we're either building Python or
3735
# building an extension with an un-installed Python, so we use
@@ -43,16 +41,26 @@ def _is_python_source_dir(d):
4341
if os.path.isfile(os.path.join(d, "Modules", fn)):
4442
return True
4543
return False
44+
4645
_sys_home = getattr(sys, '_home', None)
47-
if (_sys_home and os.name == 'nt' and
48-
_sys_home.lower().endswith(('\\pcbuild\\win32', '\\pcbuild\\amd64'))):
49-
_sys_home = os.path.dirname(os.path.dirname(_sys_home))
46+
47+
if os.name == 'nt':
48+
def _fix_pcbuild(d):
49+
if d and os.path.normcase(d).startswith(
50+
os.path.normcase(os.path.join(PREFIX, "PCbuild"))):
51+
return PREFIX
52+
return d
53+
project_base = _fix_pcbuild(project_base)
54+
_sys_home = _fix_pcbuild(_sys_home)
55+
5056
def _python_build():
5157
if _sys_home:
5258
return _is_python_source_dir(_sys_home)
5359
return _is_python_source_dir(project_base)
60+
5461
python_build = _python_build()
5562

63+
5664
# Calculate the build qualifier flags if they are defined. Adding the flags
5765
# to the include and lib directories only makes sense for an installation, not
5866
# an in-source build.
@@ -101,6 +109,11 @@ def get_python_inc(plat_specific=0, prefix=None):
101109
python_dir = 'python' + get_python_version() + build_flags
102110
return os.path.join(prefix, "include", python_dir)
103111
elif os.name == "nt":
112+
if python_build:
113+
# Include both the include and PC dir to ensure we can find
114+
# pyconfig.h
115+
return (os.path.join(prefix, "include") + os.path.pathsep +
116+
os.path.join(prefix, "PC"))
104117
return os.path.join(prefix, "include")
105118
else:
106119
raise DistutilsPlatformError(

Lib/distutils/tests/test_build_ext.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,12 @@ def test_finalize_options(self):
177177
cmd.finalize_options()
178178

179179
py_include = sysconfig.get_python_inc()
180-
self.assertIn(py_include, cmd.include_dirs)
180+
for p in py_include.split(os.path.pathsep):
181+
self.assertIn(p, cmd.include_dirs)
181182

182183
plat_py_include = sysconfig.get_python_inc(plat_specific=1)
183-
self.assertIn(plat_py_include, cmd.include_dirs)
184+
for p in plat_py_include.split(os.path.pathsep):
185+
self.assertIn(p, cmd.include_dirs)
184186

185187
# make sure cmd.libraries is turned into a list
186188
# if it's a string

Lib/sysconfig.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,16 @@ def _is_python_source_dir(d):
125125
return False
126126

127127
_sys_home = getattr(sys, '_home', None)
128-
if (_sys_home and os.name == 'nt' and
129-
_sys_home.lower().endswith(('\\pcbuild\\win32', '\\pcbuild\\amd64'))):
130-
_sys_home = os.path.dirname(os.path.dirname(_sys_home))
128+
129+
if os.name == 'nt':
130+
def _fix_pcbuild(d):
131+
if d and os.path.normcase(d).startswith(
132+
os.path.normcase(os.path.join(_PREFIX, "PCbuild"))):
133+
return _PREFIX
134+
return d
135+
_PROJECT_BASE = _fix_pcbuild(_PROJECT_BASE)
136+
_sys_home = _fix_pcbuild(_sys_home)
137+
131138
def is_python_build(check_home=False):
132139
if check_home and _sys_home:
133140
return _is_python_source_dir(_sys_home)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix sysconfig detection of the source directory and distutils handling of
2+
pyconfig.h during PGO profiling

Tools/msi/dev/dev.wixproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
<EmbeddedResource Include="*.wxl" />
2222
</ItemGroup>
2323
<ItemGroup>
24-
<InstallFiles Include="$(PySourcePath)include\**\*.h">
24+
<InstallFiles Include="$(PySourcePath)include\**\*.h"
25+
Exclude="$(PySourcePath)include\pyconfig.h">
2526
<SourceBase>$(PySourcePath)</SourceBase>
2627
<Source>!(bindpath.src)</Source>
2728
<TargetBase>$(PySourcePath)</TargetBase>

0 commit comments

Comments
 (0)