mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
C#: Fix tracer issue with dotnet dotnet.
This commit is contained in:
@@ -5,20 +5,40 @@ function RegisterExtractorPack(id)
|
|||||||
|
|
||||||
local extractor = Exify(GetPlatformToolsDirectory() .. 'Semmle.Extraction.CSharp.Driver')
|
local extractor = Exify(GetPlatformToolsDirectory() .. 'Semmle.Extraction.CSharp.Driver')
|
||||||
|
|
||||||
|
local function isDotnet(name)
|
||||||
|
return name == 'dotnet' or name == 'dotnet.exe'
|
||||||
|
end
|
||||||
|
|
||||||
|
local function isDotnetPath(path)
|
||||||
|
return path:match('dotnet[.]exe$') or path:match('dotnet$')
|
||||||
|
end
|
||||||
|
|
||||||
|
local function isPossibleDotnetSubcommand(arg)
|
||||||
|
-- dotnet options start with either - or / (both are legal)
|
||||||
|
-- It is possible to run dotnet with dotnet, e.g., `dotnet dotnet build`
|
||||||
|
-- but we shouldn't consider `dotnet` to be a subcommand.
|
||||||
|
local firstCharacter = string.sub(arg, 1, 1)
|
||||||
|
return not (firstCharacter == '-') and
|
||||||
|
not (firstCharacter == '/') and
|
||||||
|
not isDotnetPath(arg)
|
||||||
|
end
|
||||||
|
|
||||||
function DotnetMatcherBuild(compilerName, compilerPath, compilerArguments,
|
function DotnetMatcherBuild(compilerName, compilerPath, compilerArguments,
|
||||||
_languageId)
|
_languageId)
|
||||||
if compilerName ~= 'dotnet' and compilerName ~= 'dotnet.exe' then
|
if not isDotnet(compilerName) then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- The dotnet CLI has the following usage instructions:
|
-- The dotnet CLI has the following usage instructions:
|
||||||
-- dotnet [sdk-options] [command] [command-options] [arguments]
|
-- dotnet [sdk-options] [command] [command-options] [arguments] OR
|
||||||
|
-- dotnet [runtime-options] [path-to-application] [arguments]
|
||||||
-- we are interested in dotnet build, which has the following usage instructions:
|
-- we are interested in dotnet build, which has the following usage instructions:
|
||||||
-- dotnet [options] build [<PROJECT | SOLUTION>...]
|
-- dotnet [options] build [<PROJECT | SOLUTION>...]
|
||||||
-- For now, parse the command line as follows:
|
-- For now, parse the command line as follows:
|
||||||
-- Everything that starts with `-` (or `/`) will be ignored.
|
-- Everything that starts with `-` (or `/`) will be ignored.
|
||||||
-- The first non-option argument is treated as the command.
|
-- The first non-option argument is treated as the command (except if it is dotnet itself).
|
||||||
-- if that's `build`, we append `-p:UseSharedCompilation=false` to the command line,
|
-- if that's `build` or similar, we append `-p:UseSharedCompilation=false`
|
||||||
|
-- and `-p:EmitCompilerGeneratedFiles=true` to the command line,
|
||||||
-- otherwise we do nothing.
|
-- otherwise we do nothing.
|
||||||
local match = false
|
local match = false
|
||||||
local testMatch = false
|
local testMatch = false
|
||||||
@@ -36,9 +56,7 @@ function RegisterExtractorPack(id)
|
|||||||
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)
|
if isPossibleDotnetSubcommand(arg) then
|
||||||
local firstCharacter = string.sub(arg, 1, 1)
|
|
||||||
if not (firstCharacter == '-') and not (firstCharacter == '/') then
|
|
||||||
if (not match) and inSubCommandPosition then
|
if (not match) and inSubCommandPosition then
|
||||||
Log(1, 'Dotnet subcommand detected: %s', arg)
|
Log(1, 'Dotnet subcommand detected: %s', arg)
|
||||||
end
|
end
|
||||||
@@ -80,7 +98,7 @@ function RegisterExtractorPack(id)
|
|||||||
end
|
end
|
||||||
-- if we see an option to `dotnet run` (e.g., `--project`), inject just prior
|
-- if we see an option to `dotnet run` (e.g., `--project`), inject just prior
|
||||||
-- to the last option
|
-- to the last option
|
||||||
if firstCharacter == '-' then
|
if string.sub(arg, 1, 1) == '-' then
|
||||||
dotnetRunNeedsSeparator = false
|
dotnetRunNeedsSeparator = false
|
||||||
dotnetRunInjectionIndex = i
|
dotnetRunInjectionIndex = i
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user