From b6b376746097c81c9842afdab4ebbbbc7dfdac2d Mon Sep 17 00:00:00 2001 From: Jeroen Ketema Date: Tue, 14 Oct 2025 13:50:36 +0200 Subject: [PATCH 1/2] Swift: Make tracer config handle resource-dirs passed to clang --- swift/tools/tracing-config.lua | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/swift/tools/tracing-config.lua b/swift/tools/tracing-config.lua index b52c5f03a45a..85a4d561ddfb 100644 --- a/swift/tools/tracing-config.lua +++ b/swift/tools/tracing-config.lua @@ -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 resource_dir_index = indexOf(args, '-resource-dir') + if resource_dir_index then + if args[resource_dir_index + 1] and args[resource_dir_index + 1] ~= '-Xcc' then + return args[resource_dir_index + 1] + elseif args[resource_dir_index + 2] then + local clang_index = string.find(args[resource_dir_index + 2], "/clang$") + if clang_index and clang_index - 1 > 0 then + return string.sub(args[resource_dir_index + 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 From 9fc8faa0486f74368e026fc299d1eda803b328cb Mon Sep 17 00:00:00 2001 From: Jeroen Ketema Date: Wed, 15 Oct 2025 10:09:13 +0200 Subject: [PATCH 2/2] Swift: Address review comments --- swift/tools/tracing-config.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/swift/tools/tracing-config.lua b/swift/tools/tracing-config.lua index 85a4d561ddfb..15effc0140b5 100644 --- a/swift/tools/tracing-config.lua +++ b/swift/tools/tracing-config.lua @@ -62,14 +62,14 @@ function RegisterExtractorPack(id) -- 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 then - if args[resource_dir_index + 1] and args[resource_dir_index + 1] ~= '-Xcc' then - return args[resource_dir_index + 1] - elseif args[resource_dir_index + 2] then - local clang_index = string.find(args[resource_dir_index + 2], "/clang$") + 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[resource_dir_index + 2], 1, clang_index - 1) + return string.sub(args[found + 2], 1, clang_index - 1) end end end