@@ -10,35 +10,13 @@ import subprocess
1010
1111import lit .util
1212import lit .formats
13+ from lit .llvm import llvm_config
1314
1415# name: The name of this test suite.
1516config .name = 'LLVM'
1617
17- # Tweak PATH for Win32 to decide to use bash.exe or not.
18- if sys .platform in ['win32' ]:
19- # Seek sane tools in directories and set to $PATH.
20- path = getattr (config , 'lit_tools_dir' , None )
21- path = lit_config .getToolsPath (path ,
22- config .environment ['PATH' ],
23- ['cmp.exe' , 'grep.exe' , 'sed.exe' ])
24- if path is not None :
25- path = os .path .pathsep .join ((path ,
26- config .environment ['PATH' ]))
27- config .environment ['PATH' ] = path
28-
29- # Choose between lit's internal shell pipeline runner and a real shell. If
30- # LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
31- use_lit_shell = os .environ .get ("LIT_USE_INTERNAL_SHELL" )
32- if use_lit_shell :
33- # 0 is external, "" is default, and everything else is internal.
34- execute_external = (use_lit_shell == "0" )
35- else :
36- # Otherwise we default to internal on Windows and external elsewhere, as
37- # bash on Windows is usually very slow.
38- execute_external = (not sys .platform in ['win32' ])
39-
4018# testFormat: The test format to use to interpret tests.
41- config .test_format = lit .formats .ShTest (execute_external )
19+ config .test_format = lit .formats .ShTest (not llvm_config . use_lit_shell )
4220
4321# suffixes: A list of file extensions to treat as test files. This is overriden
4422# by individual lit.local.cfg files in the test subdirectories.
@@ -56,57 +34,27 @@ config.test_source_root = os.path.dirname(__file__)
5634config .test_exec_root = os .path .join (config .llvm_obj_root , 'test' )
5735
5836# Tweak the PATH to include the tools dir.
59- path = os .path .pathsep .join ((config .llvm_tools_dir , config .environment ['PATH' ]))
60- config .environment ['PATH' ] = path
61-
62- # Propagate 'HOME' through the environment.
63- if 'HOME' in os .environ :
64- config .environment ['HOME' ] = os .environ ['HOME' ]
37+ llvm_config .with_environment ('PATH' , config .llvm_tools_dir , append_path = True )
6538
66- # Propagate 'INCLUDE' through the environment.
67- if 'INCLUDE' in os .environ :
68- config .environment ['INCLUDE' ] = os .environ ['INCLUDE' ]
69-
70- # Propagate 'LIB' through the environment.
71- if 'LIB' in os .environ :
72- config .environment ['LIB' ] = os .environ ['LIB' ]
73-
74- # Propagate the temp directory. Windows requires this because it uses \Windows\
75- # if none of these are present.
76- if 'TMP' in os .environ :
77- config .environment ['TMP' ] = os .environ ['TMP' ]
78- if 'TEMP' in os .environ :
79- config .environment ['TEMP' ] = os .environ ['TEMP' ]
39+ # Propagate some variables from the host environment.
40+ llvm_config .with_system_environment (['HOME' , 'INCLUDE' , 'LIB' , 'TMP' , 'TEMP' , 'ASAN_SYMBOLIZER_PATH' , 'MSAN_SYMBOLIZER_PATH' ])
8041
8142# Propagate LLVM_SRC_ROOT into the environment.
8243config .environment ['LLVM_SRC_ROOT' ] = config .llvm_src_root
8344
84- # Propagate PYTHON_EXECUTABLE into the environment
85- config .environment ['PYTHON_EXECUTABLE' ] = getattr (config , 'python_executable' ,
86- '' )
87-
88- # Propagate path to symbolizer for ASan/MSan.
89- for symbolizer in ['ASAN_SYMBOLIZER_PATH' , 'MSAN_SYMBOLIZER_PATH' ]:
90- if symbolizer in os .environ :
91- config .environment [symbolizer ] = os .environ [symbolizer ]
92-
9345# Set up OCAMLPATH to include newly built OCaml libraries.
9446top_ocaml_lib = os .path .join (config .llvm_lib_dir , 'ocaml' )
9547llvm_ocaml_lib = os .path .join (top_ocaml_lib , 'llvm' )
96- ocamlpath = os .path .pathsep .join ((llvm_ocaml_lib , top_ocaml_lib ))
97- if 'OCAMLPATH' in os .environ :
98- ocamlpath = os .path .pathsep .join ((ocamlpath , os .environ ['OCAMLPATH' ]))
99- config .environment ['OCAMLPATH' ] = ocamlpath
100-
101- if 'CAML_LD_LIBRARY_PATH' in os .environ :
102- caml_ld_library_path = os .path .pathsep .join ((llvm_ocaml_lib ,
103- os .environ ['CAML_LD_LIBRARY_PATH' ]))
104- config .environment ['CAML_LD_LIBRARY_PATH' ] = caml_ld_library_path
105- else :
106- config .environment ['CAML_LD_LIBRARY_PATH' ] = llvm_ocaml_lib
48+
49+ llvm_config .with_system_environment ('OCAMLPATH' )
50+ llvm_config .with_environment ('OCAMLPATH' , top_ocaml_lib , append_path = True )
51+ llvm_config .with_environment ('OCAMLPATH' , llvm_ocaml_lib , append_path = True )
52+
53+ llvm_config .with_system_environment ('CAML_LD_LIBRARY_PATH' )
54+ llvm_config .with_environment ('CAML_LD_LIBRARY_PATH' , llvm_ocaml_lib , append_path = True )
10755
10856# Set up OCAMLRUNPARAM to enable backtraces in OCaml tests.
109- config . environment [ 'OCAMLRUNPARAM' ] = 'b'
57+ llvm_config . with_environment ( 'OCAMLRUNPARAM' , 'b' )
11058
11159# Provide the path to asan runtime lib 'libclang_rt.asan_osx_dynamic.dylib' if
11260# available. This is darwin specific since it's currently only needed on darwin.
@@ -300,10 +248,6 @@ for arch in config.targets_to_build.split():
300248
301249### Features
302250
303- # Shell execution
304- if execute_external :
305- config .available_features .add ('shell' )
306-
307251# Others/can-execute.txt
308252if sys .platform not in ['win32' ]:
309253 config .available_features .add ('can-execute' )
@@ -323,45 +267,14 @@ if loadable_module:
323267if not config .build_shared_libs :
324268 config .available_features .add ("static-libs" )
325269
326- # Sanitizers.
327- if 'Address' in config .llvm_use_sanitizer :
328- config .available_features .add ("asan" )
329- else :
330- config .available_features .add ("not_asan" )
331- if 'Memory' in config .llvm_use_sanitizer :
332- config .available_features .add ("msan" )
333- else :
334- config .available_features .add ("not_msan" )
335- if 'Undefined' in config .llvm_use_sanitizer :
336- config .available_features .add ("ubsan" )
337- else :
338- config .available_features .add ("not_ubsan" )
339-
340- # Check if we should run long running tests.
341- if lit_config .params .get ("run_long_tests" , None ) == "true" :
342- config .available_features .add ("long_tests" )
343-
344270# Direct object generation
345271if not 'hexagon' in config .target_triple :
346272 config .available_features .add ("object-emission" )
347273
348- if config .have_zlib :
349- config .available_features .add ("zlib" )
350- else :
351- config .available_features .add ("nozlib" )
352-
353274# LLVM can be configured with an empty default triple
354275# Some tests are "generic" and require a valid default triple
355276if config .target_triple :
356277 config .available_features .add ("default_triple" )
357- if re .match (r'^x86_64.*-linux' , config .target_triple ):
358- config .available_features .add ("x86_64-linux" )
359-
360- # Native compilation: host arch == default triple arch
361- # FIXME: Consider cases that target can be executed
362- # even if host_triple were different from target_triple.
363- if config .host_triple == config .target_triple :
364- config .available_features .add ("native" )
365278
366279import subprocess
367280
@@ -416,19 +329,9 @@ def have_ld64_plugin_support():
416329if have_ld64_plugin_support ():
417330 config .available_features .add ('ld64_plugin' )
418331
419- # Ask llvm-config about assertion mode.
420- try :
421- llvm_config_cmd = subprocess .Popen (
422- [os .path .join (config .llvm_tools_dir , 'llvm-config' ), '--assertion-mode' ],
423- stdout = subprocess .PIPE ,
424- env = config .environment )
425- except OSError :
426- print ("Could not find llvm-config in " + config .llvm_tools_dir )
427- exit (42 )
428-
429- if re .search (r'ON' , llvm_config_cmd .stdout .read ().decode ('ascii' )):
430- config .available_features .add ('asserts' )
431- llvm_config_cmd .wait ()
332+ # Ask llvm-config about asserts and global-isel.
333+ llvm_config .feature_config ('--assertion-mode' , 'asserts' )
334+ llvm_config .feature_config ('--has-global-isel' , 'global-isel' )
432335
433336if 'darwin' == sys .platform :
434337 try :
@@ -441,56 +344,12 @@ if 'darwin' == sys.platform:
441344 config .available_features .add ('fma3' )
442345 sysctl_cmd .wait ()
443346
444- if platform .system () in ['Windows' ]:
445- if re .match (r'.*-win32$' , config .target_triple ):
446- config .available_features .add ('target-windows' )
447- # For tests that require Windows to run.
448- config .available_features .add ('system-windows' )
449-
450347# .debug_frame is not emitted for targeting Windows x64.
451348if not re .match (r'^x86_64.*-(mingw32|windows-gnu|win32)' , config .target_triple ):
452349 config .available_features .add ('debug_frame' )
453350
454- # Check if we should use gmalloc.
455- use_gmalloc_str = lit_config .params .get ('use_gmalloc' , None )
456- if use_gmalloc_str is not None :
457- if use_gmalloc_str .lower () in ('1' , 'true' ):
458- use_gmalloc = True
459- elif use_gmalloc_str .lower () in ('' , '0' , 'false' ):
460- use_gmalloc = False
461- else :
462- lit_config .fatal ('user parameter use_gmalloc should be 0 or 1' )
463- else :
464- # Default to not using gmalloc
465- use_gmalloc = False
466-
467- # Allow use of an explicit path for gmalloc library.
468- # Will default to '/usr/lib/libgmalloc.dylib' if not set.
469- gmalloc_path_str = lit_config .params .get ('gmalloc_path' ,
470- '/usr/lib/libgmalloc.dylib' )
471-
472- if use_gmalloc :
473- config .environment .update ({'DYLD_INSERT_LIBRARIES' : gmalloc_path_str })
474-
475- # Ask llvm-config about global-isel.
476- try :
477- llvm_config_cmd = subprocess .Popen (
478- [os .path .join (config .llvm_tools_dir , 'llvm-config' ), '--has-global-isel' ],
479- stdout = subprocess .PIPE ,
480- env = config .environment )
481- except OSError :
482- print ("Could not find llvm-config in " + config .llvm_tools_dir )
483- exit (42 )
484-
485- if re .search (r'ON' , llvm_config_cmd .stdout .read ().decode ('ascii' )):
486- config .available_features .add ('global-isel' )
487- llvm_config_cmd .wait ()
488-
489351if config .have_libxar :
490352 config .available_features .add ('xar' )
491353
492- if config .enable_abi_breaking_checks == "1" :
493- config .available_features .add ('abi-breaking-checks' )
494-
495354if config .llvm_libxml2_enabled == "1" :
496355 config .available_features .add ('libxml2' )
0 commit comments