[pywin32-checkins] pywin32 setup.py,1.65,1.66
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2008-02-10 10:02:08
|
Update of /cvsroot/pywin32/pywin32 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29622 Modified Files: setup.py Log Message: Much saner handling of the SDK include/lib paths - gets things building from 2.2->2.6 again Index: setup.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/setup.py,v retrieving revision 1.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** setup.py 7 Feb 2008 05:43:13 -0000 1.65 --- setup.py 10 Feb 2008 10:02:09 -0000 1.66 *************** *** 218,222 **** # dead ends so we only consider the job done if we find the "windows.h" # landmark. ! DEBUG = False landmark = "include\\windows.h" # 1. The use might have their current environment setup for the --- 218,222 ---- # dead ends so we only consider the job done if we find the "windows.h" # landmark. ! DEBUG = False # can't use log.debug - not setup yet landmark = "include\\windows.h" # 1. The use might have their current environment setup for the *************** *** 410,413 **** --- 410,467 ---- return result + def finalize_options(self, build_ext): + # distutils doesn't define this function for an Extension - it is + # our own invention, and called just before the extension is built. + if not build_ext.mingw32: + if self.pch_header: + self.extra_compile_args = self.extra_compile_args or [] + # /YX doesn't work in vs2008 + if is_32bit and get_build_version() < 9.0: + self.extra_compile_args.append("/YX"+self.pch_header) + pch_name = os.path.join(build_ext.build_temp, self.name) + ".pch" + self.extra_compile_args.append("/Fp"+pch_name) + + # Put our DLL base address in. + base = self.base_address + if not base: + base = dll_base_addresses[self.name] + self.extra_link_args.append("/BASE:0x%x" % (base,)) + + # like Python, always use debug info, even in release builds + # (note the compiler doesn't include debug info, so you only get + # basic info - but its better than nothing!) + # For now use the temp dir - later we may package them, so should + # maybe move them next to the output file. + # ack - but fails with obscure errors in py23 :( + if sys.version_info > (2,4): + pch_dir = os.path.join(build_ext.build_temp) + if not build_ext.debug: + self.extra_compile_args.append("/Zi") + self.extra_compile_args.append("/Fd%s\%s_vc.pdb" % + (pch_dir, self.name)) + self.extra_link_args.append("/DEBUG") + self.extra_link_args.append("/PDB:%s\%s.pdb" % + (pch_dir, self.name)) + # enable unwind semantics - some stuff needs it and I can't see + # it hurting + self.extra_compile_args.append("/EHsc") + + # Try and find the MFC source code, so we can reach inside for + # some of the ActiveX support we need. We need to do this late, so + # the environment is setup correctly. + # Only used by the win32uiole extensions, but I can't be + # bothered making a subclass just for this - so they all get it! + found_mfc = False + for incl in os.environ.get("INCLUDE", "").split(os.pathsep): + # first is a "standard" MSVC install, second is the Vista SDK. + for candidate in ("..\src\occimpl.h", "..\..\src\mfc\occimpl.h"): + check = os.path.join(incl, candidate) + if os.path.isfile(check): + self.extra_compile_args.append('/DMFC_OCC_IMPL_H=\\"%s\\"' % candidate) + found_mfc = True + break + if found_mfc: + break + class WinExt_pythonwin(WinExt): def __init__ (self, name, **kw): *************** *** 515,523 **** if self.mingw32: self.libraries.append("stdc++") ! # Try and locate the platform SDK - this prevents the user from needing ! # to manually add these directories via the MSVC UI. # (Note that just having them in INCLUDE/LIB does *not* work - ! # distutils thinks it knows better, and resets those vars. ! # Note: sdk_dir is a global. if 'DISTUTILS_USE_SDK' in os.environ: # theoretically, this means the environment is already setup --- 569,615 ---- if self.mingw32: self.libraries.append("stdc++") ! ! self.excluded_extensions = [] # list of (ext, why) ! self.swig_cpp = True # hrm - deprecated - should use swig_opts=-c++?? ! ! def _fixup_sdk_dirs(self): ! # Adjust paths etc for the platform SDK - this prevents the user from ! # needing to manually add these directories via the MSVC UI. Note ! # that we currently ensure the SDK dirs are before the compiler ! # dirs, so its no problem if they have added these dirs to the UI) ! # (Note that just having them in INCLUDE/LIB does *not* work - ! # distutils thinks it knows better, and resets those vars (see notes ! # below about how the paths are put together) ! ! # Called after the compiler is initialized, but before the extensions ! # are built. NOTE: this means setting self.include_dirs etc will ! # have no effect, so we poke our path changes directly into the ! # compiler (we can't call this *before* the compiler is setup, as ! # then our environment changes would have no effect - see below) ! ! # distutils puts the path together like so: ! # * compiler command line includes /I entries for each dir in ! # ext.include_dir + build_ext.include_dir (ie, extension's come first) ! # * The compiler initialization sets the INCLUDE/LIB etc env vars to the ! # values read from the registry (ignoring anything that was there) ! ! # We are also at the mercy of how MSVC processes command-line ! # includes vs env vars (presumably environment comes last) - so, ! # moral of the story: ! # * To get a path at the start, it must be at the start of ! # ext.includes ! # * To get a path at the end, it must be at the end of ! # os.environ("INCLUDE") ! # Note however that the environment tweaking can only be done after ! # the compiler has set these vars, which is quite late - ! # build_ext.run() - so global environment hacks are done in our ! # build_extensions() override) ! # ! # Also note that none of our extensions have individual include files ! # that must be first - so for practical purposes, any entry in ! # build_ext.include_dirs should 'win' over the compiler's dirs. ! assert self.compiler.initialized # if not, our env changes will be lost! ! if 'DISTUTILS_USE_SDK' in os.environ: # theoretically, this means the environment is already setup *************** *** 525,551 **** pass elif sdk_dir: - # hrm - this should probably go down in build_ext with the - # other manipulation of the include/lib dirs... extra = os.path.join(sdk_dir, 'include') ! if extra not in self.include_dirs and os.path.isdir(extra): ! self.include_dirs.append(extra) extra = os.path.join(sdk_dir, 'lib') - assert os.path.isdir(extra) if is_64bit: extra = os.path.join(extra, 'x64') assert os.path.isdir(extra), extra ! if extra not in self.library_dirs and os.path.isdir(extra): ! self.library_dirs.insert(0, extra) else: print "Warning - can't find an installed platform SDK" ! # Python 2.2 distutils doesn't handle the 'PC'/PCBuild directory for ! # us (it only exists if building from the source tree) ! extra = os.path.join(sys.exec_prefix, 'PC') ! if extra not in self.include_dirs and os.path.isdir(extra): ! self.include_dirs.append(extra) ! extra = os.path.join(sys.exec_prefix, 'PCBuild') ! if extra not in self.library_dirs and os.path.isdir(extra): ! self.library_dirs.append(os.path.join(extra)) ! self.excluded_extensions = [] # list of (ext, why) def _why_cant_build_extension(self, ext): --- 617,664 ---- pass elif sdk_dir: extra = os.path.join(sdk_dir, 'include') ! # should not be possible for the SDK dirs to already be in our ! # include_dirs - they may be in the registry etc from MSVC, but ! # those aren't reflected here... ! assert extra not in self.include_dirs ! # and we will not work as expected if the dirs don't exist ! assert os.path.isdir(extra), "%s doesn't exist!" % (extra,) ! self.compiler.add_include_dir(extra) ! # and again for lib dirs. extra = os.path.join(sdk_dir, 'lib') if is_64bit: extra = os.path.join(extra, 'x64') assert os.path.isdir(extra), extra ! assert extra not in self.library_dirs # see above ! 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) ! ! # Vista SDKs have a 'VC' directory with headers and libs for older ! # compilers. We need to hack the support in here so that the ! # directories are after the compiler's own. As noted above, the ! # only way to ensure they are after the compiler's is to put them ! # in the environment, which has the nice side-effect of working ! # for the rc executable. ! # We know its not needed on vs9... ! if get_build_version() < 9.0: ! if os.path.isdir(os.path.join(sdk_dir, 'VC', 'INCLUDE')): ! os.environ["INCLUDE"] += ";" + os.path.join(sdk_dir, 'VC', 'INCLUDE') ! log.debug("Vista SDK found: %%INCLUDE%% now %s", os.environ["INCLUDE"]) ! if os.path.isdir(os.path.join(sdk_dir, 'VC', 'LIB')): ! os.environ["LIB"] += ";" + os.path.join(sdk_dir, 'VC', 'LIB') ! log.debug("Vista SDK found: %%LIB%% now %s", os.environ["LIB"]) else: print "Warning - can't find an installed platform SDK" ! if sys.hexversion < 0x02030000: ! # Python 2.2 distutils doesn't handle the 'PC'/PCBuild directory for ! # us (it only exists if building from the source tree) ! extra = os.path.join(sys.exec_prefix, 'PC') ! if extra not in self.include_dirs and os.path.isdir(extra): ! self.compiler.add_include_dir(extra) ! extra = os.path.join(sys.exec_prefix, 'PCBuild') ! if extra not in self.library_dirs and os.path.isdir(extra): ! self.compiler.add_library_dir(os.path.join(extra)) def _why_cant_build_extension(self, ext): *************** *** 554,560 **** include_dirs = self.compiler.include_dirs + \ os.environ.get("INCLUDE", "").split(os.pathsep) ! # new platform SDKs stick the version in sdkddkver.h ! for header in ('WINDOWS.H', 'SDKDDKVER.H'): ! for d in include_dirs: look = os.path.join(d, header) if os.path.isfile(look): --- 667,673 ---- include_dirs = self.compiler.include_dirs + \ os.environ.get("INCLUDE", "").split(os.pathsep) ! for d in include_dirs: ! # new platform SDKs stick the version in sdkddkver.h ! for header in ('WINDOWS.H', 'SDKDDKVER.H'): look = os.path.join(d, header) if os.path.isfile(look): *************** *** 596,599 **** --- 709,713 ---- break else: + log.debug("Looked for %s in %s", h, look_dirs) return "The header '%s' can not be located" % (h,) *************** *** 608,611 **** --- 722,726 ---- found = self.compiler.find_library_file(look_dirs, lib, self.debug) if not found: + log.debug("Looked for %s in %s", lib, look_dirs) return "No library '%s'" % lib self.found_libraries[lib.lower()] = found *************** *** 665,676 **** def build_extensions(self): - # Is there a better way than this? - # Just one GUIDS.CPP and it gives trouble on mainwin too - # Maybe I should just rename the file, but a case-only rename is likely to be - # worse! - if ".CPP" not in self.compiler.src_extensions: - self.compiler._cpp_extensions.append(".CPP") - self.compiler.src_extensions.append(".CPP") - # First, sanity-check the 'extensions' list self.check_extensions_list(self.extensions) --- 780,783 ---- *************** *** 678,681 **** --- 785,797 ---- self.found_libraries = {} + if not hasattr(self.compiler, 'initialized'): + # 2.3 and earlier initialized at construction + self.compiler.initialized = True + else: + assert not self.compiler.initialized + self.compiler.initialize() + + 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 *************** *** 841,863 **** self.current_extension = ext ! if not self.mingw32: ! if ext.pch_header: ! ext.extra_compile_args = ext.extra_compile_args or [] ! # /YX doesn't work in vs2008 ! if is_32bit and get_build_version() < 9.0: ! ext.extra_compile_args.append("/YX"+ext.pch_header) ! pch_name = os.path.join(self.build_temp, ext.name) + ".pch" ! ext.extra_compile_args.append("/Fp"+pch_name) ! ! # It gets uglier and uglier: {mssdk}/vc/include and /lib must ! # be stuck on the path. /include must get used for both cl.exe ! # and rc.exe, so its impossible to so here - so we do it in ! # _setup_compile() below. /lib can't be set there, so we do it ! # here. Will someone please put this out of its misery? ! # actually, we don't need this for 2.4+ (but I won't actually ! # kill 2.4- stuff yet.) ! if 0 and sdk_dir and get_build_version() < 9.0: ! if os.path.isdir(os.path.join(sdk_dir, 'VC', 'LIB')): ! ext.library_dirs.append(os.path.join(sdk_dir, 'VC', 'LIB')) # some source files are compiled for different extensions --- 957,961 ---- self.current_extension = ext ! ext.finalize_options(self) # some source files are compiled for different extensions *************** *** 869,915 **** self.build_temp = os.path.join(self.build_temp, ext.name) - if not self.mingw32: - # Put our DLL base address in. - base = ext.base_address - if not base: - base = dll_base_addresses[ext.name] - ext.extra_link_args.append("/BASE:0x%x" % (base,)) - - # like Python, always use debug info, even in release builds - # (note the compiler doesn't include debug info, so you only get - # basic info - but its better than nothing!) - # For now use the temp dir - later we may package them, so should - # maybe move them next to the output file. - # ack - but fails with obscure errors in py23 :( - if sys.version_info > (2,4): - pch_dir = os.path.join(self.build_temp) - if not self.debug: - ext.extra_compile_args.append("/Zi") - ext.extra_compile_args.append("/Fd%s\%s_vc.pdb" % - (pch_dir, ext.name)) - ext.extra_link_args.append("/DEBUG") - ext.extra_link_args.append("/PDB:%s\%s.pdb" % - (pch_dir, ext.name)) - # enable unwind semantics - some stuff needs it and I can't see - # it hurting - ext.extra_compile_args.append("/EHsc") - - # Try and find the MFC source code, so we can reach inside for - # some of the ActiveX support we need. We need to do this late, so - # the environment is setup correctly. - # Only used by the win32uiole extensions, but we pass it to all - # extensions just to make our life easier - found_mfc = False - for incl in os.environ.get("INCLUDE", "").split(os.pathsep): - # first is a "standard" MSVC install, second is the Vista SDK. - for candidate in ("..\src\occimpl.h", "..\..\src\mfc\occimpl.h"): - check = os.path.join(incl, candidate) - if os.path.isfile(check): - ext.extra_compile_args.append('/DMFC_OCC_IMPL_H=\\"%s\\"' % candidate) - break - if found_mfc: - break - - self.swig_cpp = True try: build_ext.build_extension(self, ext) --- 967,970 ---- *************** *** 1103,1107 **** ccompiler.new_compiler = my_new_compiler ! class my_compiler(msvccompiler.MSVCCompiler): def link(self, target_desc, --- 1158,1171 ---- ccompiler.new_compiler = my_new_compiler ! base_compiler = msvccompiler.MSVCCompiler ! ! class my_compiler(base_compiler): ! # Just one GUIDS.CPP and it gives trouble on mainwin too. Maybe I ! # should just rename the file, but a case-only rename is likely to be ! # worse! This can probably go away once we kill the VS project files ! # though, as we can just specify the lowercase name in the module def. ! _cpp_extensions = base_compiler._cpp_extensions + [".CPP"] ! src_extensions = base_compiler.src_extensions + [".CPP"] ! def link(self, target_desc, *************** *** 1199,1215 **** build = OnlyItems(items) - # Vista SDKs have a 'VC' directory with headers and libs for older - # compilers. We need to hack the support in here so that the - # directories are after the compiler's own (where simply seeing - # ext.include_dirs means they end up before) and so they apply - # to the 'rc' executable (where tricks like ext.extra_compile_args - # don't work) - # We know its not needed on vs9... - if sdk_dir and get_build_version() < 9.0: - x = os.path.join(sdk_dir, 'VC', 'INCLUDE') - pp_opts.append("-I" + x.encode("mbcs")) - # *sob* - can't do the .lib dir here - see build_extension() - # above. - return macros, objects, extra, pp_opts, build --- 1263,1266 ---- *************** *** 1356,1359 **** --- 1407,1413 ---- if sdk_dir and os.path.exists(os.path.join(sdk_dir, "Lib", "bufferoverflowu.lib")): win32help_libs += " bufferoverflowu" + # but of-course the Vista SDK does it differently... + elif sdk_dir and os.path.exists(os.path.join(sdk_dir, "VC", "Lib", "RunTmChk.lib")): + win32help_libs += " RunTmChk" win32_extensions += [ WinExt_win32('win32help', *************** *** 1704,1708 **** 'win32comext.directsound', 'win32comext.authorization', ! 'pythonwin.pywin', 'pythonwin.pywin.debugger', --- 1758,1762 ---- 'win32comext.directsound', 'win32comext.authorization', ! 'pythonwin.pywin', 'pythonwin.pywin.debugger', |