173173 lit_config .note ("\t Unset " + var )
174174 llvm_config .with_environment (var , "" )
175175
176+
177+ # Temporarily modify environment to be the same that we use when running tests
178+ class test_env :
179+ def __enter__ (self ):
180+ self .old_environ = dict (os .environ )
181+ os .environ .clear ()
182+ os .environ .update (config .environment )
183+
184+ def __exit__ (self , exc_type , exc_value , exc_traceback ):
185+ os .environ .clear ()
186+ os .environ .update (self .old_environ )
187+
188+
176189config .substitutions .append (("%sycl_libs_dir" , config .sycl_libs_dir ))
177190if platform .system () == "Windows" :
178191 config .substitutions .append (
@@ -263,10 +276,11 @@ def open_check_file(file_name):
263276
264277# check if compiler supports CL command line options
265278cl_options = False
266- sp = subprocess .getstatusoutput (config .dpcpp_compiler + " /help" )
267- if sp [0 ] == 0 :
268- cl_options = True
269- config .available_features .add ("cl_options" )
279+ with test_env ():
280+ sp = subprocess .getstatusoutput (config .dpcpp_compiler + " /help" )
281+ if sp [0 ] == 0 :
282+ cl_options = True
283+ config .available_features .add ("cl_options" )
270284
271285# check if the compiler was built in NDEBUG configuration
272286has_ndebug = False
@@ -321,14 +335,15 @@ def open_check_file(file_name):
321335
322336config .substitutions .append (("%level_zero_options" , level_zero_options ))
323337
324- sp = subprocess .getstatusoutput (
325- config .dpcpp_compiler + " -fsycl " + check_l0_file + level_zero_options
326- )
327- if sp [0 ] == 0 :
328- config .available_features .add ("level_zero_dev_kit" )
329- config .substitutions .append (("%level_zero_options" , level_zero_options ))
330- else :
331- config .substitutions .append (("%level_zero_options" , "" ))
338+ with test_env ():
339+ sp = subprocess .getstatusoutput (
340+ config .dpcpp_compiler + " -fsycl " + check_l0_file + level_zero_options
341+ )
342+ if sp [0 ] == 0 :
343+ config .available_features .add ("level_zero_dev_kit" )
344+ config .substitutions .append (("%level_zero_options" , level_zero_options ))
345+ else :
346+ config .substitutions .append (("%level_zero_options" , "" ))
332347
333348if lit_config .params .get ("test-preview-mode" , False ):
334349 config .available_features .add ("preview-mode" )
@@ -349,13 +364,14 @@ def open_check_file(file_name):
349364 file = fp ,
350365 )
351366
352- sp = subprocess .getstatusoutput (
353- config .dpcpp_compiler
354- + " -fsycl -fpreview-breaking-changes "
355- + check_preview_breaking_changes_file
356- )
357- if sp [0 ] == 0 :
358- config .available_features .add ("preview-breaking-changes-supported" )
367+ with test_env ():
368+ sp = subprocess .getstatusoutput (
369+ config .dpcpp_compiler
370+ + " -fsycl -fpreview-breaking-changes "
371+ + check_preview_breaking_changes_file
372+ )
373+ if sp [0 ] == 0 :
374+ config .available_features .add ("preview-breaking-changes-supported" )
359375
360376# Check if clang is built with ZSTD and compression support.
361377fPIC_opt = "-fPIC" if platform .system () != "Windows" else ""
@@ -418,14 +434,15 @@ def open_check_file(file_name):
418434
419435config .substitutions .append (("%cuda_options" , cuda_options ))
420436
421- sp = subprocess .getstatusoutput (
422- config .dpcpp_compiler + " -fsycl " + check_cuda_file + cuda_options
423- )
424- if sp [0 ] == 0 :
425- config .available_features .add ("cuda_dev_kit" )
426- config .substitutions .append (("%cuda_options" , cuda_options ))
427- else :
428- config .substitutions .append (("%cuda_options" , "" ))
437+ with test_env ():
438+ sp = subprocess .getstatusoutput (
439+ config .dpcpp_compiler + " -fsycl " + check_cuda_file + cuda_options
440+ )
441+ if sp [0 ] == 0 :
442+ config .available_features .add ("cuda_dev_kit" )
443+ config .substitutions .append (("%cuda_options" , cuda_options ))
444+ else :
445+ config .substitutions .append (("%cuda_options" , "" ))
429446
430447# Check for OpenCL ICD
431448if config .opencl_libs_dir :
0 commit comments