@@ -224,6 +224,18 @@ def __init__(self, verbose=0, dry_run=0, force=0):
224224 self .plat_name = None
225225 self .initialized = False
226226
227+ @classmethod
228+ def _configure (cls , vc_env ):
229+ """
230+ Set class-level include/lib dirs.
231+ """
232+ cls .include_dirs = cls ._parse_path (vc_env .get ('include' , '' ))
233+ cls .library_dirs = cls ._parse_path (vc_env .get ('lib' , '' ))
234+
235+ @staticmethod
236+ def _parse_path (val ):
237+ return [dir .rstrip (os .sep ) for dir in val .split (os .pathsep ) if dir ]
238+
227239 def initialize (self , plat_name = None ):
228240 # multi-init means we would need to check platform same each time...
229241 assert not self .initialized , "don't init multiple times"
@@ -243,6 +255,7 @@ def initialize(self, plat_name=None):
243255 raise DistutilsPlatformError (
244256 "Unable to find a compatible " "Visual Studio installation."
245257 )
258+ self ._configure (vc_env )
246259
247260 self ._paths = vc_env .get ('path' , '' )
248261 paths = self ._paths .split (os .pathsep )
@@ -253,16 +266,6 @@ def initialize(self, plat_name=None):
253266 self .mc = _find_exe ("mc.exe" , paths ) # message compiler
254267 self .mt = _find_exe ("mt.exe" , paths ) # message compiler
255268
256- self .__include_dirs = [
257- dir .rstrip (os .sep )
258- for dir in vc_env .get ('include' , '' ).split (os .pathsep )
259- if dir
260- ]
261-
262- self .__library_dirs = [
263- dir .rstrip (os .sep ) for dir in vc_env .get ('lib' , '' ).split (os .pathsep ) if dir
264- ]
265-
266269 self .preprocess_options = None
267270 # bpo-38597: Always compile with dynamic linking
268271 # Future releases of Python 3.x will include all past
@@ -559,26 +562,6 @@ def _fallback_spawn(self, cmd, env):
559562 with mock .patch .dict ('os.environ' , env ):
560563 bag .value = super ().spawn (cmd )
561564
562- def _fix_compile_args (self , output_dir , macros , include_dirs ):
563- """Corrects arguments to the compile() method and add compiler-specific dirs"""
564- fixed_args = super ()._fix_compile_args (output_dir , macros , include_dirs )
565- return (
566- fixed_args [0 ], # output_dir
567- fixed_args [1 ], # macros
568- fixed_args [2 ] + self .__include_dirs ,
569- )
570-
571- def _fix_lib_args (self , libraries , library_dirs , runtime_library_dirs ):
572- """Corrects arguments to the link_*() methods and add linker-specific dirs"""
573- fixed_args = super ()._fix_lib_args (
574- libraries , library_dirs , runtime_library_dirs
575- )
576- return (
577- fixed_args [0 ], # libraries
578- fixed_args [1 ] + self .__library_dirs ,
579- fixed_args [2 ], # runtime_library_dirs
580- )
581-
582565 # -- Miscellaneous methods -----------------------------------------
583566 # These are all used by the 'gen_lib_options() function, in
584567 # ccompiler.py.
0 commit comments