blob: 450b6149223c08da72058e641f5d85bcdc27004c [file] [log] [blame]
Daniel Dunbar3667b992009-07-31 05:54:17 +00001# -*- Python -*-
2
Daniel Dunbarb5cbf772009-09-22 05:16:02 +00003import os
Daniel Dunbarbe4253a2009-09-08 16:39:23 +00004
Daniel Dunbar3667b992009-07-31 05:54:17 +00005# Configuration file for the 'lit' test runner.
6
Daniel Dunbarb5cbf772009-09-22 05:16:02 +00007# name: The name of this test suite.
8config.name = 'Clang'
Daniel Dunbarbe4253a2009-09-08 16:39:23 +00009
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000010# testFormat: The test format to use to interpret tests.
Daniel Dunbar3667b992009-07-31 05:54:17 +000011#
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000012# For now we require '&&' between commands, until they get globally killed and
13# the test runner updated.
14config.test_format = lit.formats.ShTest(execute_external = True,
15 require_and_and = True)
Daniel Dunbarf87be552009-09-06 01:31:12 +000016
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000017# suffixes: A list of file extensions to treat as test files.
18config.suffixes = ['.c', '.cpp', '.m', '.mm']
19
20# test_source_root: The root path where tests are located.
21config.test_source_root = os.path.dirname(__file__)
22
23# test_exec_root: The root path where tests should be run.
24clang_obj_root = getattr(config, 'clang_obj_root', None)
25if clang_obj_root is not None:
26 config.test_exec_root = os.path.join(clang_obj_root, 'test')
27
28# Set llvm_{src,obj}_root for use by others.
29config.llvm_src_root = getattr(config, 'llvm_src_root', None)
30config.llvm_obj_root = getattr(config, 'llvm_obj_root', None)
31
32# Tweak the PATH to include the tools dir and the scripts dir.
33if clang_obj_root is not None:
34 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
35 if not llvm_tools_dir:
36 lit.fatal('No LLVM tools dir set!')
37 path = os.path.pathsep.join((llvm_tools_dir,
38 os.path.join(config.llvm_src_root,
39 'test', 'Scripts'),
40 config.environment['PATH']))
41 config.environment['PATH'] = path
42
43###
44
45# Check that the object root is known.
46if config.test_exec_root is None:
47 # Otherwise, we haven't loaded the site specific configuration (the user is
48 # probably trying to run on a test file directly, and either the site
49 # configuration hasn't been created by the build system, or we are in an
50 # out-of-tree build situation).
51
52 # Try to detect the situation where we are using an out-of-tree build by
53 # looking for 'llvm-config'.
54 #
55 # FIXME: I debated (i.e., wrote and threw away) adding logic to
56 # automagically generate the lit.site.cfg if we are in some kind of fresh
57 # build situation. This means knowing how to invoke the build system
58 # though, and I decided it was too much magic.
59
60 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
61 if not llvm_config:
62 lit.fatal('No site specific configuration available!')
63
64 # Get the source and object roots.
65 llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
66 llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
67 clang_src_root = os.path.join(llvm_src_root, "tools", "clang")
68 clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang")
69
70 # Validate that we got a tree which points to here, using the standard
71 # tools/clang layout.
72 this_src_root = os.path.dirname(config.test_source_root)
73 if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root):
74 lit.fatal('No site specific configuration available!')
75
76 # Check that the site specific configuration exists.
77 site_cfg = os.path.join(clang_obj_root, 'test', 'lit.site.cfg')
78 if not os.path.exists(site_cfg):
79 lit.fatal('No site specific configuration available!')
80
81 # Okay, that worked. Notify the user of the automagic, and reconfigure.
82 lit.note('using out-of-tree build at %r' % clang_obj_root)
83 lit.load_config(config, site_cfg)
84 raise SystemExit
85
86###
87
88# Discover the 'clang' and 'clangcc' to use.
89
90import os
91
92def inferClang(PATH):
93 # Determine which clang to use.
94 clang = os.getenv('CLANG')
95
96 # If the user set clang in the environment, definitely use that and don't
97 # try to validate.
98 if clang:
99 return clang
100
101 # Otherwise look in the path.
102 clang = lit.util.which('clang', PATH)
103
104 if not clang:
105 lit.fatal("couldn't find 'clang' program, try setting "
106 "CLANG in your environment")
107
108 return clang
109
110def inferClangCC(clang, PATH):
111 clangcc = os.getenv('CLANGCC')
112
113 # If the user set clang in the environment, definitely use that and don't
114 # try to validate.
115 if clangcc:
116 return clangcc
117
118 # Otherwise try adding -cc since we expect to be looking in a build
119 # directory.
120 if clang.endswith('.exe'):
121 clangccName = clang[:-4] + '-cc.exe'
122 else:
123 clangccName = clang + '-cc'
124 clangcc = lit.util.which(clangccName, PATH)
125 if not clangcc:
126 # Otherwise ask clang.
127 res = lit.util.capture([clang, '-print-prog-name=clang-cc'])
128 res = res.strip()
129 if res and os.path.exists(res):
130 clangcc = res
131
132 if not clangcc:
133 lit.fatal("couldn't find 'clang-cc' program, try setting "
134 "CLANGCC in your environment")
135
136 return clangcc
137
138config.clang = inferClang(config.environment['PATH'])
139if not lit.quiet:
140 lit.note('using clang: %r' % config.clang)
141config.substitutions.append( (' clang ', ' ' + config.clang + ' ') )
142
143config.clang_cc = inferClangCC(config.clang, config.environment['PATH'])
144if not lit.quiet:
145 lit.note('using clang-cc: %r' % config.clang_cc)
146config.substitutions.append( (' clang-cc ', ' ' + config.clang_cc + ' ') )