14
14
import lit .util
15
15
16
16
17
- def get_path_from_clang (args , allow_failure ):
18
- clang_cmd = [
19
- config .clang .strip (),
20
- f"--target={ config .target_triple } " ,
21
- * args ,
22
- ]
23
- path = None
24
- try :
25
- result = subprocess .run (
26
- clang_cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE , check = True
27
- )
28
- path = result .stdout .decode ().strip ()
29
- except subprocess .CalledProcessError as e :
30
- msg = f"Failed to run { clang_cmd } \n rc:{ e .returncode } \n stdout:{ e .stdout } \n e.stderr{ e .stderr } "
31
- if allow_failure :
32
- lit_config .warning (msg )
33
- else :
34
- lit_config .fatal (msg )
35
- return path , clang_cmd
36
-
37
-
38
17
def find_compiler_libdir ():
39
18
"""
40
19
Returns the path to library resource directory used
@@ -47,6 +26,26 @@ def find_compiler_libdir():
47
26
# TODO: Support other compilers.
48
27
return None
49
28
29
+ def get_path_from_clang (args , allow_failure ):
30
+ clang_cmd = [
31
+ config .clang .strip (),
32
+ f"--target={ config .target_triple } " ,
33
+ ]
34
+ clang_cmd .extend (args )
35
+ path = None
36
+ try :
37
+ result = subprocess .run (
38
+ clang_cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE , check = True
39
+ )
40
+ path = result .stdout .decode ().strip ()
41
+ except subprocess .CalledProcessError as e :
42
+ msg = f"Failed to run { clang_cmd } \n rc:{ e .returncode } \n stdout:{ e .stdout } \n e.stderr{ e .stderr } "
43
+ if allow_failure :
44
+ lit_config .warning (msg )
45
+ else :
46
+ lit_config .fatal (msg )
47
+ return path , clang_cmd
48
+
50
49
# Try using `-print-runtime-dir`. This is only supported by very new versions of Clang.
51
50
# so allow failure here.
52
51
runtime_dir , clang_cmd = get_path_from_clang (
@@ -169,51 +168,10 @@ def push_dynamic_library_lookup_path(config, new_path):
169
168
r"/i386(?=-[^/]+$)" , "/x86_64" , config .compiler_rt_libdir
170
169
)
171
170
172
-
173
- # Check if the test compiler resource dir matches the local build directory
174
- # (which happens with -DLLVM_ENABLE_PROJECTS=clang;compiler-rt) or if we are
175
- # using an installed clang to test compiler-rt standalone. In the latter case
176
- # we may need to override the resource dir to match the path of the just-built
177
- # compiler-rt libraries.
178
- test_cc_resource_dir , _ = get_path_from_clang (
179
- shlex .split (config .target_cflags ) + ["-print-resource-dir" ], allow_failure = True
180
- )
181
- # Normalize the path for comparison
182
- if test_cc_resource_dir is not None :
183
- test_cc_resource_dir = os .path .realpath (test_cc_resource_dir )
184
- if lit_config .debug :
185
- lit_config .note (f"Resource dir for { config .clang } is { test_cc_resource_dir } " )
186
- local_build_resource_dir = os .path .realpath (config .compiler_rt_output_dir )
187
- if test_cc_resource_dir != local_build_resource_dir and config .test_standalone_build_libs :
188
- if config .compiler_id == "Clang" :
189
- if lit_config .debug :
190
- lit_config .note (
191
- f"Overriding test compiler resource dir to use "
192
- f'libraries in "{ config .compiler_rt_libdir } "'
193
- )
194
- # Ensure that we use the just-built static libraries when linking by
195
- # overriding the Clang resource directory. Additionally, we want to use
196
- # the builtin headers shipped with clang (e.g. stdint.h), so we
197
- # explicitly add this as an include path (since the headers are not
198
- # going to be in the current compiler-rt build directory).
199
- # We also tell the linker to add an RPATH entry for the local library
200
- # directory so that the just-built shared libraries are used.
201
- config .target_cflags += f" -nobuiltininc"
202
- config .target_cflags += f" -I{ config .compiler_rt_src_root } /include"
203
- config .target_cflags += f" -idirafter { test_cc_resource_dir } /include"
204
- config .target_cflags += f" -resource-dir={ config .compiler_rt_output_dir } "
205
- config .target_cflags += f" -Wl,-rpath,{ config .compiler_rt_libdir } "
206
- else :
207
- lit_config .warning (
208
- f"Cannot override compiler-rt library directory with non-Clang "
209
- f"compiler: { config .compiler_id } "
210
- )
211
-
212
-
213
171
# Ask the compiler for the path to libraries it is going to use. If this
214
172
# doesn't match config.compiler_rt_libdir then it means we might be testing the
215
173
# compiler's own runtime libraries rather than the ones we just built.
216
- # Warn about this and handle appropriately.
174
+ # Warn about about this and handle appropriately.
217
175
compiler_libdir = find_compiler_libdir ()
218
176
if compiler_libdir :
219
177
compiler_rt_libdir_real = os .path .realpath (config .compiler_rt_libdir )
@@ -224,7 +182,7 @@ def push_dynamic_library_lookup_path(config, new_path):
224
182
f'compiler-rt libdir: "{ compiler_rt_libdir_real } "'
225
183
)
226
184
if config .test_standalone_build_libs :
227
- # Use just built runtime libraries, i.e. the libraries this build just built.
185
+ # Use just built runtime libraries, i.e. the the libraries this built just built.
228
186
if not config .test_suite_supports_overriding_runtime_lib_path :
229
187
# Test suite doesn't support this configuration.
230
188
# TODO(dliew): This should be an error but it seems several bots are
0 commit comments