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