Skip to content

Commit

Permalink
Remove obsolete _fixup_sdk_dirs() mechanism in setup.py
Browse files Browse the repository at this point in the history
Newer distutils / setuptools versions already use and expose
the MSVC & SDK dirs - taken from vcvarsall.bat . We need and
should not use a different mechanism anymore.
(Include & lib dirs of 2 different SDK kits were seen on
compiler command lines at the same time on github CI)
  • Loading branch information
kxrob committed Aug 21, 2022
1 parent 676a85c commit e055b3b
Showing 1 changed file with 0 additions and 86 deletions.
86 changes: 0 additions & 86 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,73 +86,6 @@
# dll_base_address later in this file...
dll_base_address = 0x1E200000

# We need to know the platform SDK dir before we can list the extensions.
def find_platform_sdk_dir():
# The user might have their current environment setup for the
# SDK, in which case "MSSDK_INCLUDE" and "MSSDK_LIB" vars must be set.
if "MSSDK_INCLUDE" in os.environ and "MSSDK_LIB" in os.environ:
print("Using SDK as specified in the environment")
return {
"include": os.environ["MSSDK_INCLUDE"].split(os.path.pathsep),
"lib": os.environ["MSSDK_LIB"].split(os.path.pathsep),
}

# Find the win 10 SDKs installed.
installedVersions = []
try:
key = winreg.OpenKey(
winreg.HKEY_LOCAL_MACHINE,
r"SOFTWARE\Microsoft\Windows Kits\Installed Roots",
0,
winreg.KEY_READ | winreg.KEY_WOW64_32KEY,
)
installRoot = winreg.QueryValueEx(key, "KitsRoot10")[0]
keyNo = 0
while 1:
try:
installedVersions.append(winreg.EnumKey(key, keyNo))
keyNo += 1
except winreg.error:
break
except EnvironmentError:
pass
if not installedVersions:
print("Can't find a windows 10 sdk")
return None

# We don't want to automatically used the latest as that's going to always
# be a moving target. Github's automation has "10.0.16299.0", so we target
# that if it exists, otherwise we use the earliest installed version.
ver = "10.0.16299.0"
if ver not in installedVersions:
print("Windows 10 SDK version", ver, "is preferred, but that's not installed")
print("Installed versions are", installedVersions)
ver = installedVersions[0]
print("Using", ver)
# no idea what these 'um' and 'winv6.3' paths actually mean and whether
# hard-coding them is appropriate, but here we are...
include = [os.path.join(installRoot, "include", ver, "um")]
if not os.path.exists(os.path.join(include[0], "windows.h")):
print(
"Found Windows sdk in", include, "but it doesn't appear to have windows.h"
)
return None
include.append(os.path.join(installRoot, "include", ver, "shared"))
lib = [os.path.join(installRoot, "lib", ver, "um")]
return {"include": include, "lib": lib}


sdk_info = find_platform_sdk_dir()
if not sdk_info:
print()
print("It looks like you are trying to build pywin32 in an environment without")
print("the necessary tools installed. It's much easier to grab binaries!")
print()
print("Please read the docstring at the top of this file, or read README.md")
print("for more information.")
print()
raise RuntimeError("Can't find the Windows SDK")


def find_visual_studio_file(pattern):
try:
Expand Down Expand Up @@ -491,23 +424,6 @@ def finalize_options(self):
self.excluded_extensions = [] # list of (ext, why)
self.swig_cpp = True # hrm - deprecated - should use swig_opts=-c++??

def _fixup_sdk_dirs(self):
assert self.compiler.initialized # if not, our env changes will be lost!

for extra in sdk_info["include"]:
if extra not in self.compiler.include_dirs:
log.warn("distutils should meanwhile provide SDK include dir %s", extra)
assert os.path.isdir(extra), "%s doesn't exist!" % (extra,)
self.compiler.add_include_dir(extra)
for extra in sdk_info["lib"]:
extra = os.path.join(extra, self.plat_dir)
if extra not in self.compiler.library_dirs:
assert os.path.isdir(extra), "%s doesn't exist!" % (extra,)
self.compiler.add_library_dir(extra)

log.debug("After SDK processing, includes are %s", self.compiler.include_dirs)
log.debug("After SDK processing, libs are %s", self.compiler.library_dirs)

def _why_cant_build_extension(self, ext):
# Return None, or a reason it can't be built.
# Exclude exchange 32-bit utility libraries from 64-bit
Expand Down Expand Up @@ -663,8 +579,6 @@ def build_extensions(self):
else:
print("-- FIX ME ! distutils may expose complete inc/lib dirs again")

self._fixup_sdk_dirs()

# Here we hack a "pywin32" directory (one of 'win32', 'win32com',
# 'pythonwin' etc), as distutils doesn't seem to like the concept
# of multiple top-level directories.
Expand Down

0 comments on commit e055b3b

Please sign in to comment.