Skip to content

Commit c9eef0c

Browse files
authored
Merge pull request #9592 from github/alexdenisov/extend-lua-tracer-config
Swift: extend tracer config to handle -resource-dir and drop unsupported CLI args
2 parents 7020363 + 304f58b commit c9eef0c

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

swift/tools/tracing-config.lua

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,53 @@ function RegisterExtractorPack(id)
33
local relativeSwiftExtractor = extractorDirectory .. 'extractor'
44
local swiftExtractor = AbsolutifyExtractorPath(id, relativeSwiftExtractor)
55

6+
function indexOf(array, value)
7+
for i, v in ipairs(array) do
8+
if v == value then
9+
return i
10+
end
11+
end
12+
return nil
13+
end
14+
15+
-- removes upsupported CLI arg including the following how_many args
16+
function strip_unsupported_arg(args, arg, how_many)
17+
local index = indexOf(args, arg)
18+
if index then
19+
table.remove(args, index)
20+
while (how_many > 0)
21+
do
22+
table.remove(args, index)
23+
how_many = how_many - 1
24+
end
25+
end
26+
end
27+
28+
function strip_unsupported_args(args)
29+
strip_unsupported_arg(args, '-emit-localized-strings', 0)
30+
strip_unsupported_arg(args, '-emit-localized-strings-path', 1)
31+
strip_unsupported_arg(args, '-stack-check', 0)
32+
end
33+
34+
-- xcodebuild does not always specify the -resource-dir in which case the compiler falls back
35+
-- to a resource-dir based on its path
36+
-- here we mimic this behavior externally
37+
-- without a proper -resource-dir compiler-specific headers cannot be found which leads to
38+
-- broken extraction
39+
function insert_resource_dir_if_needed(compilerPath, args)
40+
local resource_dir_index = indexOf(args, '-resource-dir')
41+
if resource_dir_index then
42+
return
43+
end
44+
-- derive -resource-dir based on the compilerPath
45+
-- e.g.: /usr/bin/swift-frontend -> /usr/bin/../lib/swift
46+
local last_slash_index = string.find(compilerPath, "/[^/]*$")
47+
local compiler_dir = string.sub(compilerPath, 1, last_slash_index)
48+
local resource_dir = compiler_dir .. '../lib/swift'
49+
table.insert(args, '-resource-dir')
50+
table.insert(args, resource_dir)
51+
end
52+
653
function SwiftMatcher(compilerName, compilerPath, compilerArguments, lang)
754
-- Only match binaries names `swift-frontend`
855
if compilerName ~= 'swift-frontend' then return nil end
@@ -14,15 +61,18 @@ function RegisterExtractorPack(id)
1461

1562
-- Skip "info" queries in case there is nothing to extract
1663
if compilerArguments.argv[1] == '-print-target-info' then
17-
return nil
64+
return nil
1865
end
1966
if compilerArguments.argv[1] == '-emit-supported-features' then
20-
return nil
67+
return nil
2168
end
2269

2370
-- Skip actions in which we cannot extract anything
2471
if compilerArguments.argv[1] == '-merge-modules' then return nil end
2572

73+
strip_unsupported_args(compilerArguments.argv)
74+
insert_resource_dir_if_needed(compilerPath, compilerArguments.argv)
75+
2676
return {
2777
trace = true,
2878
replace = false,

0 commit comments

Comments
 (0)