Merge pull request #20639 from jketema/swift-trace

Swift: Make tracer config handle resource-dirs passed to clang
This commit is contained in:
Jeroen Ketema
2025-10-15 13:16:15 +02:00
committed by GitHub

View File

@@ -57,17 +57,27 @@ function RegisterExtractorPack(id)
-- xcodebuild does not always specify the -resource-dir in which case the compiler falls back
-- to a resource-dir based on its path. We want to know what is the original resource-dir in
-- all cases so that we can patch it with out own
-- all cases so that we can patch it with out own. When we see a -resource-dir preceded by
-- -Xcc this will be a resource-dir that is passed to clang. We can still obtain the swift
-- resource-dir in this case by skipping over the -Xcc that follows it and stripping off the
-- clang suffix from the path.
function find_original_resource_dir(compilerPath, args)
local resource_dir_index = indexOf(args, '-resource-dir')
if resource_dir_index and args[resource_dir_index + 1] then
return args[resource_dir_index + 1]
end
-- derive -resource-dir based on the compilerPath
-- e.g.: /usr/bin/swift-frontend -> /usr/bin/../lib/swift
local second_last_slash_index = string.find(compilerPath, "/[^/]*/[^/]*$")
local usr_dir = string.sub(compilerPath, 1, second_last_slash_index)
return usr_dir .. '/lib/swift'
local found = indexOf(args, '-resource-dir')
if found and args[found + 1] then
if args[found - 1] ~= '-Xcc' then
return args[found + 1]
elseif args[found + 1] == '-Xcc' and args[found + 2] then
local clang_index = string.find(args[found + 2], "/clang$")
if clang_index and clang_index - 1 > 0 then
return string.sub(args[found + 2], 1, clang_index - 1)
end
end
end
-- derive -resource-dir based on the compilerPath
-- e.g.: /usr/bin/swift-frontend -> /usr/bin/../lib/swift
local second_last_slash_index = string.find(compilerPath, "/[^/]*/[^/]*$")
local usr_dir = string.sub(compilerPath, 1, second_last_slash_index)
return usr_dir .. 'lib/swift'
end
-- replace or add our own resource directory