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