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