mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
C#: Handle dotnet exec csc.dll and the likes in the Lua tracer
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
function RegisterExtractorPack(id)
|
function RegisterExtractorPack(id)
|
||||||
local extractor = GetPlatformToolsDirectory() ..
|
local extractor = GetPlatformToolsDirectory() ..
|
||||||
'Semmle.Extraction.CSharp.Driver'
|
'Semmle.Extraction.CSharp.Driver'
|
||||||
if OperatingSystem == 'windows' then extractor = extractor .. '.exe' end
|
if OperatingSystem == 'windows' then extractor = extractor .. '.exe' end
|
||||||
|
|
||||||
function DotnetMatcherBuild(compilerName, compilerPath, compilerArguments,
|
function DotnetMatcherBuild(compilerName, compilerPath, compilerArguments,
|
||||||
@@ -24,7 +24,7 @@ function RegisterExtractorPack(id)
|
|||||||
-- let's hope that this split matches the escaping rules `dotnet` applies to command line arguments
|
-- let's hope that this split matches the escaping rules `dotnet` applies to command line arguments
|
||||||
-- or, at least, that it is close enough
|
-- or, at least, that it is close enough
|
||||||
argv =
|
argv =
|
||||||
NativeArgumentsToArgv(compilerArguments.nativeArgumentPointer)
|
NativeArgumentsToArgv(compilerArguments.nativeArgumentPointer)
|
||||||
end
|
end
|
||||||
for i, arg in ipairs(argv) do
|
for i, arg in ipairs(argv) do
|
||||||
-- dotnet options start with either - or / (both are legal)
|
-- dotnet options start with either - or / (both are legal)
|
||||||
@@ -39,8 +39,8 @@ function RegisterExtractorPack(id)
|
|||||||
return {
|
return {
|
||||||
order = ORDER_REPLACE,
|
order = ORDER_REPLACE,
|
||||||
invocation = BuildExtractorInvocation(id, compilerPath,
|
invocation = BuildExtractorInvocation(id, compilerPath,
|
||||||
compilerPath,
|
compilerPath,
|
||||||
compilerArguments, nil, {
|
compilerArguments, nil, {
|
||||||
'/p:UseSharedCompilation=false'
|
'/p:UseSharedCompilation=false'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -50,44 +50,96 @@ function RegisterExtractorPack(id)
|
|||||||
|
|
||||||
local windowsMatchers = {
|
local windowsMatchers = {
|
||||||
DotnetMatcherBuild,
|
DotnetMatcherBuild,
|
||||||
CreatePatternMatcher({'^dotnet%.exe$'}, MatchCompilerName, extractor, {
|
CreatePatternMatcher({ '^csc.*%.exe$' }, MatchCompilerName, extractor, {
|
||||||
prepend = {'--dotnetexec', '--cil'},
|
prepend = { '--cil', '--compiler', '"${compiler}"' },
|
||||||
order = ORDER_BEFORE
|
order = ORDER_BEFORE
|
||||||
}),
|
}),
|
||||||
CreatePatternMatcher({'^csc.*%.exe$'}, MatchCompilerName, extractor, {
|
CreatePatternMatcher({ '^fakes.*%.exe$', 'moles.*%.exe' },
|
||||||
prepend = {'--compiler', '"${compiler}"', '--cil'},
|
MatchCompilerName, nil, { trace = false }),
|
||||||
order = ORDER_BEFORE
|
function(compilerName, compilerPath, compilerArguments, _languageId)
|
||||||
}),
|
-- handle cases like `dotnet.exe exec csc.dll <args>`
|
||||||
CreatePatternMatcher({'^fakes.*%.exe$', 'moles.*%.exe'},
|
if compilerName ~= 'dotnet.exe' then
|
||||||
MatchCompilerName, nil, {trace = false})
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local seenCompilerCall = false
|
||||||
|
local argv = NativeArgumentsToArgv(compilerArguments.nativeArgumentPointer)
|
||||||
|
local extractorArgs = { '--cil', '--compiler' }
|
||||||
|
for _, arg in ipairs(argv) do
|
||||||
|
if arg:match('csc%.dll$') then
|
||||||
|
seenCompilerCall = true
|
||||||
|
end
|
||||||
|
if seenCompilerCall then
|
||||||
|
table.insert(extractorArgs, '"' .. arg .. '"')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if seenCompilerCall then
|
||||||
|
return {
|
||||||
|
order = ORDER_BEFORE,
|
||||||
|
invocation = {
|
||||||
|
path = AbsolutifyExtractorPath(id, extractor),
|
||||||
|
arguments = {
|
||||||
|
commandLineString = table.concat(extractorArgs, " ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
}
|
}
|
||||||
local posixMatchers = {
|
local posixMatchers = {
|
||||||
DotnetMatcherBuild,
|
DotnetMatcherBuild,
|
||||||
CreatePatternMatcher({'^mono', '^dotnet$'}, MatchCompilerName,
|
CreatePatternMatcher({ '^mcs%.exe$', '^csc%.exe$' }, MatchCompilerName,
|
||||||
extractor, {
|
extractor, {
|
||||||
prepend = {'--dotnetexec', '--cil'},
|
prepend = { '--cil', '--compiler', '"${compiler}"' },
|
||||||
order = ORDER_BEFORE
|
|
||||||
}),
|
|
||||||
CreatePatternMatcher({'^mcs%.exe$', '^csc%.exe$'}, MatchCompilerName,
|
|
||||||
extractor, {
|
|
||||||
prepend = {'--compiler', '"${compiler}"', '--cil'},
|
|
||||||
order = ORDER_BEFORE
|
order = ORDER_BEFORE
|
||||||
}), function(compilerName, compilerPath, compilerArguments, _languageId)
|
}), function(compilerName, compilerPath, compilerArguments, _languageId)
|
||||||
if MatchCompilerName('^msbuild$', compilerName, compilerPath,
|
if MatchCompilerName('^msbuild$', compilerName, compilerPath,
|
||||||
compilerArguments) or
|
compilerArguments) or
|
||||||
MatchCompilerName('^xbuild$', compilerName, compilerPath,
|
MatchCompilerName('^xbuild$', compilerName, compilerPath,
|
||||||
compilerArguments) then
|
compilerArguments) then
|
||||||
return {
|
return {
|
||||||
order = ORDER_REPLACE,
|
order = ORDER_REPLACE,
|
||||||
invocation = BuildExtractorInvocation(id, compilerPath,
|
invocation = BuildExtractorInvocation(id, compilerPath,
|
||||||
compilerPath,
|
compilerPath,
|
||||||
compilerArguments,
|
compilerArguments,
|
||||||
nil, {
|
nil, {
|
||||||
'/p:UseSharedCompilation=false'
|
'/p:UseSharedCompilation=false'
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
end, function(compilerName, compilerPath, compilerArguments, _languageId)
|
||||||
|
-- handle cases like `dotnet exec csc.dll <args>` and `mono(-sgen64) csc.exe <args>`
|
||||||
|
if compilerName ~= 'dotnet' and not compilerName:match('^mono') then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local seenCompilerCall = false
|
||||||
|
local argv = compilerArguments.argv
|
||||||
|
local extractorArgs = { '--cil', '--compiler' }
|
||||||
|
for _, arg in ipairs(argv) do
|
||||||
|
if arg:match('csc%.dll$') or arg:match('csc%.exe$') or arg:match('mcs%.exe$') then
|
||||||
|
seenCompilerCall = true
|
||||||
|
end
|
||||||
|
if seenCompilerCall then
|
||||||
|
table.insert(extractorArgs, arg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if seenCompilerCall then
|
||||||
|
return {
|
||||||
|
order = ORDER_BEFORE,
|
||||||
|
invocation = {
|
||||||
|
path = AbsolutifyExtractorPath(id, extractor),
|
||||||
|
arguments = {
|
||||||
|
argv = extractorArgs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
return nil
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
if OperatingSystem == 'windows' then
|
if OperatingSystem == 'windows' then
|
||||||
@@ -99,4 +151,4 @@ end
|
|||||||
|
|
||||||
-- Return a list of minimum supported versions of the configuration file format
|
-- Return a list of minimum supported versions of the configuration file format
|
||||||
-- return one entry per supported major version.
|
-- return one entry per supported major version.
|
||||||
function GetCompatibleVersions() return {'1.0.0'} end
|
function GetCompatibleVersions() return { '1.0.0' } end
|
||||||
|
|||||||
Reference in New Issue
Block a user