blob: 0a99aa4ee9dd3e5e3165db6cd6b1ecbad7018410 [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.
Daniel Dunbara173d9b2009-09-20 19:04:35 +000030 config.llvm_src_root = getattr(config, 'llvm_src_root', None)
31 config.llvm_obj_root = getattr(config, 'llvm_obj_root', None)
Daniel Dunbarf47fd5842009-09-16 01:39:52 +000032
Daniel Dunbarecac0a42009-09-17 19:55:53 +000033 # Tweak the PATH to include the tools dir and the scripts dir.
34 if clang_obj_root is not None:
35 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
36 if not llvm_tools_dir:
37 lit.fatal('No LLVM tools dir set!')
38 path = os.path.pathsep.join((llvm_tools_dir,
39 os.path.join(config.llvm_src_root,
40 'test', 'Scripts'),
41 config.environment['PATH']))
42 config.environment['PATH'] = path
43
Daniel Dunbar8c10ff8f2009-09-10 23:00:15 +000044 ###
45
46 # Check that the object root is known.
47 if config.test_exec_root is None:
48 # Otherwise, we haven't loaded the site specific configuration (the user is
49 # probably trying to run on a test file directly, and either the site
50 # configuration hasn't been created by the build system, or we are in an
51 # out-of-tree build situation).
52
53 # Try to detect the situation where we are using an out-of-tree build by
54 # looking for 'llvm-config'.
55 #
56 # FIXME: I debated (i.e., wrote and threw away) adding logic to
57 # automagically generate the lit.site.cfg if we are in some kind of fresh
58 # build situation. This means knowing how to invoke the build system
59 # though, and I decided it was too much magic.
60
61 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
62 if not llvm_config:
63 lit.fatal('No site specific configuration available!')
64
65 # Get the source and object roots.
66 llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
67 llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
68 clang_src_root = os.path.join(llvm_src_root, "tools", "clang")
69 clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang")
70
71 # Validate that we got a tree which points to here, using the standard
72 # tools/clang layout.
73 this_src_root = os.path.dirname(config.test_source_root)
74 if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root):
75 lit.fatal('No site specific configuration available!')
76
77 # Check that the site specific configuration exists.
78 site_cfg = os.path.join(clang_obj_root, 'test', 'lit.site.cfg')
79 if not os.path.exists(site_cfg):
80 lit.fatal('No site specific configuration available!')
81
82 # Okay, that worked. Notify the user of the automagic, and reconfigure.
83 lit.note('using out-of-tree build at %r' % clang_obj_root)
84 lit.load_config(config, site_cfg)
85 raise SystemExit
86
Daniel Dunbarbe4253a2009-09-08 16:39:23 +000087 ###
88
89 # Discover the 'clang' and 'clangcc' to use.
90
91 import os
92
93 def inferClang(PATH):
94 # Determine which clang to use.
95 clang = os.getenv('CLANG')
96
97 # If the user set clang in the environment, definitely use that and don't
98 # try to validate.
99 if clang:
100 return clang
101
102 # Otherwise look in the path.
103 clang = lit.util.which('clang', PATH)
104
105 if not clang:
106 lit.fatal("couldn't find 'clang' program, try setting "
107 "CLANG in your environment")
108
109 return clang
110
111 def inferClangCC(clang, PATH):
112 clangcc = os.getenv('CLANGCC')
113
114 # If the user set clang in the environment, definitely use that and don't
115 # try to validate.
116 if clangcc:
117 return clangcc
118
119 # Otherwise try adding -cc since we expect to be looking in a build
120 # directory.
121 if clang.endswith('.exe'):
122 clangccName = clang[:-4] + '-cc.exe'
123 else:
124 clangccName = clang + '-cc'
125 clangcc = lit.util.which(clangccName, PATH)
126 if not clangcc:
127 # Otherwise ask clang.
128 res = lit.util.capture([clang, '-print-prog-name=clang-cc'])
129 res = res.strip()
130 if res and os.path.exists(res):
131 clangcc = res
132
133 if not clangcc:
134 lit.fatal("couldn't find 'clang-cc' program, try setting "
135 "CLANGCC in your environment")
136
137 return clangcc
138
Daniel Dunbarf47fd5842009-09-16 01:39:52 +0000139 config.clang = inferClang(config.environment['PATH'])
Daniel Dunbarbe4253a2009-09-08 16:39:23 +0000140 if not lit.quiet:
Daniel Dunbarf47fd5842009-09-16 01:39:52 +0000141 lit.note('using clang: %r' % config.clang)
142 config.substitutions.append( (' clang ', ' ' + config.clang + ' ') )
Daniel Dunbarbe4253a2009-09-08 16:39:23 +0000143
Daniel Dunbarf47fd5842009-09-16 01:39:52 +0000144 config.clang_cc = inferClangCC(config.clang, config.environment['PATH'])
Daniel Dunbarbe4253a2009-09-08 16:39:23 +0000145 if not lit.quiet:
Daniel Dunbarf47fd5842009-09-16 01:39:52 +0000146 lit.note('using clang-cc: %r' % config.clang_cc)
147 config.substitutions.append( (' clang-cc ', ' ' + config.clang_cc + ' ') )
Daniel Dunbarbe4253a2009-09-08 16:39:23 +0000148
149if 'config' in globals():
150 config_new()
151 raise SystemExit # End configuration.
152
Daniel Dunbar3667b992009-07-31 05:54:17 +0000153# Configuration file for the 'lit' test runner.
154
155# suffixes: A list of file extensions to treat as test files.
Daniel Dunbar20a8d482009-07-31 05:57:11 +0000156suffixes = ['.c', '.cpp', '.m', '.mm']
Daniel Dunbarbe4253a2009-09-08 16:39:23 +0000157
Daniel Dunbar3667b992009-07-31 05:54:17 +0000158# environment: The base environment to use when running test commands.
159#
160# The 'PATH' and 'SYSTEMROOT' variables will be set automatically from the lit
161# command line variables.
162environment = {}
Daniel Dunbarf87be552009-09-06 01:31:12 +0000163
164# requireAndAnd: Require '&&' between commands, until they get globally killed
165# and the test runner updated.
166requireAndAnd = True