@@ -5,20 +5,40 @@ function RegisterExtractorPack(id)
5
5
6
6
local extractor = Exify (GetPlatformToolsDirectory () .. ' Semmle.Extraction.CSharp.Driver' )
7
7
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
+
8
26
function DotnetMatcherBuild (compilerName , compilerPath , compilerArguments ,
9
27
_languageId )
10
- if compilerName ~= ' dotnet ' and compilerName ~= ' dotnet.exe ' then
28
+ if not isDotnet ( compilerName ) then
11
29
return nil
12
30
end
13
31
14
32
-- 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]
16
35
-- we are interested in dotnet build, which has the following usage instructions:
17
36
-- dotnet [options] build [<PROJECT | SOLUTION>...]
18
37
-- For now, parse the command line as follows:
19
38
-- 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,
22
42
-- otherwise we do nothing.
23
43
local match = false
24
44
local testMatch = false
@@ -36,9 +56,7 @@ function RegisterExtractorPack(id)
36
56
NativeArgumentsToArgv (compilerArguments .nativeArgumentPointer )
37
57
end
38
58
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
42
60
if (not match ) and inSubCommandPosition then
43
61
Log (1 , ' Dotnet subcommand detected: %s' , arg )
44
62
end
@@ -80,7 +98,7 @@ function RegisterExtractorPack(id)
80
98
end
81
99
-- if we see an option to `dotnet run` (e.g., `--project`), inject just prior
82
100
-- to the last option
83
- if firstCharacter == ' -' then
101
+ if string.sub ( arg , 1 , 1 ) == ' -' then
84
102
dotnetRunNeedsSeparator = false
85
103
dotnetRunInjectionIndex = i
86
104
end
0 commit comments