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