@@ -54,7 +54,9 @@ config.excludes = ['Inputs']
5454config .test_source_root = os .path .dirname (__file__ )
5555
5656# test_exec_root: The root path where tests should be run.
57- config .test_exec_root = os .path .join (config .clang_tools_binary_dir , 'test' )
57+ clang_tools_binary_dir = getattr (config , 'clang_tools_binary_dir' , None )
58+ if clang_tools_binary_dir is not None :
59+ config .test_exec_root = os .path .join (clang_tools_binary_dir , 'test' )
5860
5961# Clear some environment variables that might affect Clang.
6062#
@@ -86,19 +88,92 @@ for name in possibly_dangerous_env_vars:
8688 del config .environment [name ]
8789
8890# Tweak the PATH to include the tools dir and the scripts dir.
89- path = os .path .pathsep .join ((
90- config .clang_tools_dir , config .llvm_tools_dir , config .environment ['PATH' ]))
91- config .environment ['PATH' ] = path
91+ if clang_tools_binary_dir is not None :
92+ clang_tools_dir = getattr (config , 'clang_tools_dir' , None )
93+ if not clang_tools_dir :
94+ lit_config .fatal ('No Clang tools dir set!' )
95+ llvm_tools_dir = getattr (config , 'llvm_tools_dir' , None )
96+ if not llvm_tools_dir :
97+ lit_config .fatal ('No LLVM tools dir set!' )
98+ path = os .path .pathsep .join ((
99+ clang_tools_dir , llvm_tools_dir , config .environment ['PATH' ]))
100+ config .environment ['PATH' ] = path
101+
102+ clang_libs_dir = getattr (config , 'clang_libs_dir' , None )
103+ if not clang_libs_dir :
104+ lit_config .fatal ('No Clang libs dir set!' )
105+ llvm_libs_dir = getattr (config , 'llvm_libs_dir' , None )
106+ if not llvm_libs_dir :
107+ lit_config .fatal ('No LLVM libs dir set!' )
108+ path = os .path .pathsep .join ((clang_libs_dir , llvm_libs_dir ,
109+ config .environment .get ('LD_LIBRARY_PATH' ,'' )))
110+ config .environment ['LD_LIBRARY_PATH' ] = path
111+
112+ ###
113+
114+ # Check that the object root is known.
115+ if config .test_exec_root is None :
116+ # Otherwise, we haven't loaded the site specific configuration (the user is
117+ # probably trying to run on a test file directly, and either the site
118+ # configuration hasn't been created by the build system, or we are in an
119+ # out-of-tree build situation).
120+
121+ # Check for 'clang_site_config' user parameter, and use that if available.
122+ site_cfg = lit_config .params .get ('clang_tools_extra_site_config' , None )
123+ if site_cfg and os .path .exists (site_cfg ):
124+ lit_config .load_config (config , site_cfg )
125+ raise SystemExit
126+
127+ # Try to detect the situation where we are using an out-of-tree build by
128+ # looking for 'llvm-config'.
129+ #
130+ # FIXME: I debated (i.e., wrote and threw away) adding logic to
131+ # automagically generate the lit.site.cfg if we are in some kind of fresh
132+ # build situation. This means knowing how to invoke the build system though,
133+ # and I decided it was too much magic. We should solve this by just having
134+ # the .cfg files generated during the configuration step.
135+
136+ llvm_config = lit .util .which ('llvm-config' , config .environment ['PATH' ])
137+ if not llvm_config :
138+ lit_config .fatal ('No site specific configuration available!' )
139+
140+ # Get the source and object roots.
141+ llvm_src_root = lit .util .capture (['llvm-config' , '--src-root' ]).strip ()
142+ llvm_obj_root = lit .util .capture (['llvm-config' , '--obj-root' ]).strip ()
143+ clang_src_root = os .path .join (llvm_src_root , "tools" , "clang" )
144+ clang_obj_root = os .path .join (llvm_obj_root , "tools" , "clang" )
145+
146+ clang_tools_extra_src_root = os .path .join (clang_src_root , "tools" , "extra" )
147+ clang_tools_extra_obj_root = os .path .join (clang_obj_root , "tools" , "extra" )
148+ # Validate that we got a tree which points to here, using the standard
149+ # tools/clang layout.
150+ this_src_root = os .path .dirname (config .test_source_root )
151+ if os .path .realpath (clang_tools_extra_src_root ) != os .path .realpath (this_src_root ):
152+ lit_config .fatal ('No site specific configuration available!' )
153+
154+ # Check that the site specific configuration exists.
155+ site_cfg = os .path .join (clang_tools_extra_obj_root , 'test' , 'lit.site.cfg' )
156+ if not os .path .exists (site_cfg ):
157+ lit_config .fatal (
158+ 'No site specific configuration available! You may need to '
159+ 'run "make test" in your Clang build directory.' )
160+
161+ # Okay, that worked. Notify the user of the automagic, and reconfigure.
162+ lit_config .note ('using out-of-tree build at %r' % clang_obj_root )
163+ lit_config .load_config (config , site_cfg )
164+ raise SystemExit
165+
166+ ###
92167
93- path = os .path .pathsep .join ((config .clang_libs_dir , config .llvm_libs_dir ,
94- config .environment .get ('LD_LIBRARY_PATH' ,'' )))
95- config .environment ['LD_LIBRARY_PATH' ] = path
168+ import os
96169
97170# When running under valgrind, we mangle '-vg' onto the end of the triple so we
98171# can check it with XFAIL and XTARGET.
99172if lit_config .useValgrind :
100173 config .target_triple += '-vg'
101174
175+ ###
176+
102177# Set available features we allow tests to conditionalize on.
103178#
104179# As of 2011.08, crash-recovery tests still do not pass on FreeBSD.
0 commit comments