1*7c3d14c8STreehugger Robot# -*- Python -*- 2*7c3d14c8STreehugger Robot 3*7c3d14c8STreehugger Robotimport os 4*7c3d14c8STreehugger Robot 5*7c3d14c8STreehugger Robotdef get_required_attr(config, attr_name): 6*7c3d14c8STreehugger Robot attr_value = getattr(config, attr_name, None) 7*7c3d14c8STreehugger Robot if attr_value == None: 8*7c3d14c8STreehugger Robot lit_config.fatal( 9*7c3d14c8STreehugger Robot "No attribute %r in test configuration! You may need to run " 10*7c3d14c8STreehugger Robot "tests from your build directory or add this attribute " 11*7c3d14c8STreehugger Robot "to lit.site.cfg " % attr_name) 12*7c3d14c8STreehugger Robot return attr_value 13*7c3d14c8STreehugger Robot 14*7c3d14c8STreehugger Robot# Setup config name. 15*7c3d14c8STreehugger Robotconfig.name = 'Profile-' + config.target_arch 16*7c3d14c8STreehugger Robot 17*7c3d14c8STreehugger Robot# Setup source root. 18*7c3d14c8STreehugger Robotconfig.test_source_root = os.path.dirname(__file__) 19*7c3d14c8STreehugger Robot 20*7c3d14c8STreehugger Robot# Setup executable root. 21*7c3d14c8STreehugger Robotif hasattr(config, 'profile_lit_binary_dir') and \ 22*7c3d14c8STreehugger Robot config.profile_lit_binary_dir is not None: 23*7c3d14c8STreehugger Robot config.test_exec_root = os.path.join(config.profile_lit_binary_dir, config.name) 24*7c3d14c8STreehugger Robot 25*7c3d14c8STreehugger Robot# If the above check didn't work, we're probably in the source tree. Use some 26*7c3d14c8STreehugger Robot# magic to re-execute from the build tree. 27*7c3d14c8STreehugger Robotif config.test_exec_root is None: 28*7c3d14c8STreehugger Robot # The magic relies on knowing compilerrt_site_basedir. 29*7c3d14c8STreehugger Robot compilerrt_basedir = lit_config.params.get('compilerrt_site_basedir', None) 30*7c3d14c8STreehugger Robot if compilerrt_basedir: 31*7c3d14c8STreehugger Robot site_cfg = os.path.join(compilerrt_basedir, 'profile', 'lit.site.cfg') 32*7c3d14c8STreehugger Robot if os.path.exists(site_cfg): 33*7c3d14c8STreehugger Robot lit_config.load_config(config, site_cfg) 34*7c3d14c8STreehugger Robot raise SystemExit 35*7c3d14c8STreehugger Robot 36*7c3d14c8STreehugger Robotif config.host_os in ['Linux']: 37*7c3d14c8STreehugger Robot extra_linkflags = ["-ldl"] 38*7c3d14c8STreehugger Robotelse: 39*7c3d14c8STreehugger Robot extra_linkflags = [] 40*7c3d14c8STreehugger Robot 41*7c3d14c8STreehugger Robot# Test suffixes. 42*7c3d14c8STreehugger Robotconfig.suffixes = ['.c', '.cc', '.cpp', '.m', '.mm', '.ll', '.test'] 43*7c3d14c8STreehugger Robot 44*7c3d14c8STreehugger Robot# What to exclude. 45*7c3d14c8STreehugger Robotconfig.excludes = ['Inputs'] 46*7c3d14c8STreehugger Robot 47*7c3d14c8STreehugger Robot# Clang flags. 48*7c3d14c8STreehugger Robottarget_cflags=[get_required_attr(config, "target_cflags")] 49*7c3d14c8STreehugger Robotclang_cflags = target_cflags + extra_linkflags 50*7c3d14c8STreehugger Robotclang_cxxflags = config.cxx_mode_flags + clang_cflags 51*7c3d14c8STreehugger Robot 52*7c3d14c8STreehugger Robotdef build_invocation(compile_flags): 53*7c3d14c8STreehugger Robot return " " + " ".join([config.clang] + compile_flags) + " " 54*7c3d14c8STreehugger Robot 55*7c3d14c8STreehugger Robot# Add clang substitutions. 56*7c3d14c8STreehugger Robotconfig.substitutions.append( ("%clang ", build_invocation(clang_cflags)) ) 57*7c3d14c8STreehugger Robotconfig.substitutions.append( ("%clangxx ", build_invocation(clang_cxxflags)) ) 58*7c3d14c8STreehugger Robotconfig.substitutions.append( ("%clang_profgen ", build_invocation(clang_cflags) + " -fprofile-instr-generate ") ) 59*7c3d14c8STreehugger Robotconfig.substitutions.append( ("%clang_profgen=", build_invocation(clang_cflags) + " -fprofile-instr-generate=") ) 60*7c3d14c8STreehugger Robotconfig.substitutions.append( ("%clang_profuse=", build_invocation(clang_cflags) + " -fprofile-instr-use=") ) 61*7c3d14c8STreehugger Robotconfig.substitutions.append( ("%clangxx_profgen ", build_invocation(clang_cxxflags) + " -fprofile-instr-generate ") ) 62*7c3d14c8STreehugger Robotconfig.substitutions.append( ("%clangxx_profuse=", build_invocation(clang_cxxflags) + " -fprofile-instr-use=") ) 63*7c3d14c8STreehugger Robotconfig.substitutions.append( ("%clang_profgen_gcc=", build_invocation(clang_cflags) + " -fprofile-generate=") ) 64*7c3d14c8STreehugger Robotconfig.substitutions.append( ("%clang_profuse_gcc=", build_invocation(clang_cflags) + " -fprofile-use=") ) 65*7c3d14c8STreehugger Robot 66*7c3d14c8STreehugger Robotif config.host_os not in ['Darwin', 'FreeBSD', 'Linux']: 67*7c3d14c8STreehugger Robot config.unsupported = True 68*7c3d14c8STreehugger Robot 69*7c3d14c8STreehugger Robotif config.target_arch in ['armv7l']: 70*7c3d14c8STreehugger Robot config.unsupported = True 71