Skip to content

Commit 129c8bf

Browse files
authored
Merge pull request #20639 from jketema/swift-trace
Swift: Make tracer config handle resource-dirs passed to clang
2 parents f57526e + 9fc8faa commit 129c8bf

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

swift/tools/tracing-config.lua

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,27 @@ function RegisterExtractorPack(id)
5757

5858
-- xcodebuild does not always specify the -resource-dir in which case the compiler falls back
5959
-- to a resource-dir based on its path. We want to know what is the original resource-dir in
60-
-- all cases so that we can patch it with out own
60+
-- all cases so that we can patch it with out own. When we see a -resource-dir preceded by
61+
-- -Xcc this will be a resource-dir that is passed to clang. We can still obtain the swift
62+
-- resource-dir in this case by skipping over the -Xcc that follows it and stripping off the
63+
-- clang suffix from the path.
6164
function find_original_resource_dir(compilerPath, args)
62-
local resource_dir_index = indexOf(args, '-resource-dir')
63-
if resource_dir_index and args[resource_dir_index + 1] then
64-
return args[resource_dir_index + 1]
65-
end
66-
-- derive -resource-dir based on the compilerPath
67-
-- e.g.: /usr/bin/swift-frontend -> /usr/bin/../lib/swift
68-
local second_last_slash_index = string.find(compilerPath, "/[^/]*/[^/]*$")
69-
local usr_dir = string.sub(compilerPath, 1, second_last_slash_index)
70-
return usr_dir .. '/lib/swift'
65+
local found = indexOf(args, '-resource-dir')
66+
if found and args[found + 1] then
67+
if args[found - 1] ~= '-Xcc' then
68+
return args[found + 1]
69+
elseif args[found + 1] == '-Xcc' and args[found + 2] then
70+
local clang_index = string.find(args[found + 2], "/clang$")
71+
if clang_index and clang_index - 1 > 0 then
72+
return string.sub(args[found + 2], 1, clang_index - 1)
73+
end
74+
end
75+
end
76+
-- derive -resource-dir based on the compilerPath
77+
-- e.g.: /usr/bin/swift-frontend -> /usr/bin/../lib/swift
78+
local second_last_slash_index = string.find(compilerPath, "/[^/]*/[^/]*$")
79+
local usr_dir = string.sub(compilerPath, 1, second_last_slash_index)
80+
return usr_dir .. 'lib/swift'
7181
end
7282

7383
-- replace or add our own resource directory

0 commit comments

Comments
 (0)