1# -*- Python -*-
2
3from lit import Test
4import lit.formats
5import lit.util
6import subprocess
7
8def getSysrootFlagsOnDarwin(config, lit_config):
9    # On Darwin, support relocatable SDKs by providing Clang with a
10    # default system root path.
11    if 'darwin' in config.target_triple:
12        try:
13            out = subprocess.check_output(['xcrun', '--show-sdk-path']).strip().decode()
14            res = 0
15        except OSError:
16            res = -1
17        if res == 0 and out:
18            sdk_path = out
19            lit_config.note('using SDKROOT: %r' % sdk_path)
20            return '-isysroot %s' % sdk_path
21    return ''
22
23sysroot_flags = getSysrootFlagsOnDarwin(config, lit_config)
24
25config.clang = lit.util.which('clang', config.clang_tools_dir).replace('\\', '/')
26
27config.name = 'Clang Perf Training'
28config.suffixes = ['.c', '.cpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s', '.S', '.modulemap']
29
30cc1_wrapper = '%s %s/perf-helper.py cc1' % (config.python_exe, config.perf_helper_dir)
31
32use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
33config.test_format = lit.formats.ShTest(use_lit_shell == "0")
34config.substitutions.append( ('%clang_cpp_skip_driver', ' %s %s %s ' % (cc1_wrapper, config.clang, sysroot_flags)))
35config.substitutions.append( ('%clang_cpp', ' %s --driver-mode=g++ %s ' % (config.clang, sysroot_flags)))
36config.substitutions.append( ('%clang_skip_driver', ' %s %s %s ' % (cc1_wrapper, config.clang, sysroot_flags)))
37config.substitutions.append( ('%clang', ' %s %s ' % (config.clang, sysroot_flags) ) )
38config.substitutions.append( ('%test_root', config.test_exec_root ) )
39
40config.environment['LLVM_PROFILE_FILE'] = 'perf-training-%4m.profraw'
41
42