@@ -3,6 +3,53 @@ function RegisterExtractorPack(id)
3
3
local relativeSwiftExtractor = extractorDirectory .. ' extractor'
4
4
local swiftExtractor = AbsolutifyExtractorPath (id , relativeSwiftExtractor )
5
5
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
+
6
53
function SwiftMatcher (compilerName , compilerPath , compilerArguments , lang )
7
54
-- Only match binaries names `swift-frontend`
8
55
if compilerName ~= ' swift-frontend' then return nil end
@@ -14,15 +61,18 @@ function RegisterExtractorPack(id)
14
61
15
62
-- Skip "info" queries in case there is nothing to extract
16
63
if compilerArguments .argv [1 ] == ' -print-target-info' then
17
- return nil
64
+ return nil
18
65
end
19
66
if compilerArguments .argv [1 ] == ' -emit-supported-features' then
20
- return nil
67
+ return nil
21
68
end
22
69
23
70
-- Skip actions in which we cannot extract anything
24
71
if compilerArguments .argv [1 ] == ' -merge-modules' then return nil end
25
72
73
+ strip_unsupported_args (compilerArguments .argv )
74
+ insert_resource_dir_if_needed (compilerPath , compilerArguments .argv )
75
+
26
76
return {
27
77
trace = true ,
28
78
replace = false ,
0 commit comments