@@ -5,20 +5,40 @@ function RegisterExtractorPack(id)
55
66 local extractor = Exify (GetPlatformToolsDirectory () .. ' Semmle.Extraction.CSharp.Driver' )
77
8+ local function isDotnet (name )
9+ return name == ' dotnet' or name == ' dotnet.exe'
10+ end
11+
12+ local function isDotnetPath (path )
13+ return path :match (' dotnet[.]exe$' ) or path :match (' dotnet$' )
14+ end
15+
16+ local function isPossibleDotnetSubcommand (arg )
17+ -- dotnet options start with either - or / (both are legal)
18+ -- It is possible to run dotnet with dotnet, e.g., `dotnet dotnet build`
19+ -- but we shouldn't consider `dotnet` to be a subcommand.
20+ local firstCharacter = string.sub (arg , 1 , 1 )
21+ return not (firstCharacter == ' -' ) and
22+ not (firstCharacter == ' /' ) and
23+ not isDotnetPath (arg )
24+ end
25+
826 function DotnetMatcherBuild (compilerName , compilerPath , compilerArguments ,
927 _languageId )
10- if compilerName ~= ' dotnet ' and compilerName ~= ' dotnet.exe ' then
28+ if not isDotnet ( compilerName ) then
1129 return nil
1230 end
1331
1432 -- The dotnet CLI has the following usage instructions:
15- -- dotnet [sdk-options] [command] [command-options] [arguments]
33+ -- dotnet [sdk-options] [command] [command-options] [arguments] OR
34+ -- dotnet [runtime-options] [path-to-application] [arguments]
1635 -- we are interested in dotnet build, which has the following usage instructions:
1736 -- dotnet [options] build [<PROJECT | SOLUTION>...]
1837 -- For now, parse the command line as follows:
1938 -- Everything that starts with `-` (or `/`) will be ignored.
20- -- The first non-option argument is treated as the command.
21- -- if that's `build`, we append `-p:UseSharedCompilation=false` to the command line,
39+ -- The first non-option argument is treated as the command (except if it is dotnet itself).
40+ -- if that's `build` or similar, we append `-p:UseSharedCompilation=false`
41+ -- and `-p:EmitCompilerGeneratedFiles=true` to the command line,
2242 -- otherwise we do nothing.
2343 local match = false
2444 local testMatch = false
@@ -36,9 +56,7 @@ function RegisterExtractorPack(id)
3656 NativeArgumentsToArgv (compilerArguments .nativeArgumentPointer )
3757 end
3858 for i , arg in ipairs (argv ) do
39- -- dotnet options start with either - or / (both are legal)
40- local firstCharacter = string.sub (arg , 1 , 1 )
41- if not (firstCharacter == ' -' ) and not (firstCharacter == ' /' ) then
59+ if isPossibleDotnetSubcommand (arg ) then
4260 if (not match ) and inSubCommandPosition then
4361 Log (1 , ' Dotnet subcommand detected: %s' , arg )
4462 end
@@ -80,7 +98,7 @@ function RegisterExtractorPack(id)
8098 end
8199 -- if we see an option to `dotnet run` (e.g., `--project`), inject just prior
82100 -- to the last option
83- if firstCharacter == ' -' then
101+ if string.sub ( arg , 1 , 1 ) == ' -' then
84102 dotnetRunNeedsSeparator = false
85103 dotnetRunInjectionIndex = i
86104 end
0 commit comments