1import os 2 3import lit.formats 4import lit.util 5 6# python 2.7 backwards compatibility 7try: 8 from shlex import quote as shell_quote 9except ImportError: 10 from pipes import quote as shell_quote 11 12 13def add_update_script_substitution( 14 name, python_exe=config.python_executable, extra_args="" 15): 16 assert name.startswith("%") 17 script_path = os.path.join(config.llvm_src_root, "utils", name[1:] + ".py") 18 assert os.path.isfile(script_path) 19 # Specify an explicit default version in UTC tests, so that the --version 20 # embedded in UTC_ARGS does not change in all test expectations every time 21 # the default is bumped. 22 if name != "%update_test_body": 23 extra_args += " --version=1" 24 config.substitutions.append( 25 (name, "'%s' %s %s" % (python_exe, script_path, extra_args)) 26 ) 27 28 29config.test_format = lit.formats.ShTest(execute_external=False) 30config.suffixes = [".test"] 31 32llc_path = os.path.join(config.llvm_tools_dir, "llc") 33if os.path.isfile(llc_path): 34 config.available_features.add("llc-binary") 35 llc_arg = "--llc-binary " + shell_quote(llc_path) 36 add_update_script_substitution("%update_llc_test_checks", extra_args=llc_arg) 37 add_update_script_substitution("%update_mir_test_checks", extra_args=llc_arg) 38 39opt_path = os.path.join(config.llvm_tools_dir, "opt") 40if os.path.isfile(opt_path): 41 config.available_features.add("opt-binary") 42 opt_arg = "--opt-binary " + shell_quote(opt_path) 43 add_update_script_substitution("%update_test_checks", extra_args=opt_arg) 44 add_update_script_substitution("%update_analyze_test_checks", extra_args=opt_arg) 45 46llvm_mca_path = os.path.join(config.llvm_tools_dir, "llvm-mca") 47if os.path.isfile(llvm_mca_path): 48 config.available_features.add("llvm-mca-binary") 49 mca_arg = "--llvm-mca-binary " + shell_quote(llvm_mca_path) 50 add_update_script_substitution("%update_test_checks", extra_args=mca_arg) 51 52split_file_path = os.path.join(config.llvm_tools_dir, "split-file") 53if os.path.isfile(split_file_path): 54 add_update_script_substitution("%update_test_body") 55 56llvm_mc_path = os.path.join(config.llvm_tools_dir, "llvm-mc") 57if os.path.isfile(llvm_mc_path): 58 add_update_script_substitution("%update_mc_test_checks") 59