mirror of
https://github.com/github/codeql.git
synced 2026-04-28 18:25:24 +02:00
Merge pull request #9592 from github/alexdenisov/extend-lua-tracer-config
Swift: extend tracer config to handle -resource-dir and drop unsupported CLI args
This commit is contained in:
@@ -3,6 +3,53 @@ function RegisterExtractorPack(id)
|
||||
local relativeSwiftExtractor = extractorDirectory .. 'extractor'
|
||||
local swiftExtractor = AbsolutifyExtractorPath(id, relativeSwiftExtractor)
|
||||
|
||||
function indexOf(array, value)
|
||||
for i, v in ipairs(array) do
|
||||
if v == value then
|
||||
return i
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- removes upsupported CLI arg including the following how_many args
|
||||
function strip_unsupported_arg(args, arg, how_many)
|
||||
local index = indexOf(args, arg)
|
||||
if index then
|
||||
table.remove(args, index)
|
||||
while (how_many > 0)
|
||||
do
|
||||
table.remove(args, index)
|
||||
how_many = how_many - 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function strip_unsupported_args(args)
|
||||
strip_unsupported_arg(args, '-emit-localized-strings', 0)
|
||||
strip_unsupported_arg(args, '-emit-localized-strings-path', 1)
|
||||
strip_unsupported_arg(args, '-stack-check', 0)
|
||||
end
|
||||
|
||||
-- xcodebuild does not always specify the -resource-dir in which case the compiler falls back
|
||||
-- to a resource-dir based on its path
|
||||
-- here we mimic this behavior externally
|
||||
-- without a proper -resource-dir compiler-specific headers cannot be found which leads to
|
||||
-- broken extraction
|
||||
function insert_resource_dir_if_needed(compilerPath, args)
|
||||
local resource_dir_index = indexOf(args, '-resource-dir')
|
||||
if resource_dir_index then
|
||||
return
|
||||
end
|
||||
-- derive -resource-dir based on the compilerPath
|
||||
-- e.g.: /usr/bin/swift-frontend -> /usr/bin/../lib/swift
|
||||
local last_slash_index = string.find(compilerPath, "/[^/]*$")
|
||||
local compiler_dir = string.sub(compilerPath, 1, last_slash_index)
|
||||
local resource_dir = compiler_dir .. '../lib/swift'
|
||||
table.insert(args, '-resource-dir')
|
||||
table.insert(args, resource_dir)
|
||||
end
|
||||
|
||||
function SwiftMatcher(compilerName, compilerPath, compilerArguments, lang)
|
||||
-- Only match binaries names `swift-frontend`
|
||||
if compilerName ~= 'swift-frontend' then return nil end
|
||||
@@ -14,15 +61,18 @@ function RegisterExtractorPack(id)
|
||||
|
||||
-- Skip "info" queries in case there is nothing to extract
|
||||
if compilerArguments.argv[1] == '-print-target-info' then
|
||||
return nil
|
||||
return nil
|
||||
end
|
||||
if compilerArguments.argv[1] == '-emit-supported-features' then
|
||||
return nil
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Skip actions in which we cannot extract anything
|
||||
if compilerArguments.argv[1] == '-merge-modules' then return nil end
|
||||
|
||||
strip_unsupported_args(compilerArguments.argv)
|
||||
insert_resource_dir_if_needed(compilerPath, compilerArguments.argv)
|
||||
|
||||
return {
|
||||
trace = true,
|
||||
replace = false,
|
||||
|
||||
Reference in New Issue
Block a user