1
1
function RegisterExtractorPack (id )
2
2
local extractor = GetPlatformToolsDirectory () ..
3
- ' Semmle.Extraction.CSharp.Driver'
3
+ ' Semmle.Extraction.CSharp.Driver'
4
4
if OperatingSystem == ' windows' then extractor = extractor .. ' .exe' end
5
5
6
6
function DotnetMatcherBuild (compilerName , compilerPath , compilerArguments ,
@@ -24,7 +24,7 @@ function RegisterExtractorPack(id)
24
24
-- let's hope that this split matches the escaping rules `dotnet` applies to command line arguments
25
25
-- or, at least, that it is close enough
26
26
argv =
27
- NativeArgumentsToArgv (compilerArguments .nativeArgumentPointer )
27
+ NativeArgumentsToArgv (compilerArguments .nativeArgumentPointer )
28
28
end
29
29
for i , arg in ipairs (argv ) do
30
30
-- dotnet options start with either - or / (both are legal)
@@ -39,8 +39,8 @@ function RegisterExtractorPack(id)
39
39
return {
40
40
order = ORDER_REPLACE ,
41
41
invocation = BuildExtractorInvocation (id , compilerPath ,
42
- compilerPath ,
43
- compilerArguments , nil , {
42
+ compilerPath ,
43
+ compilerArguments , nil , {
44
44
' /p:UseSharedCompilation=false'
45
45
})
46
46
}
@@ -50,44 +50,96 @@ function RegisterExtractorPack(id)
50
50
51
51
local windowsMatchers = {
52
52
DotnetMatcherBuild ,
53
- CreatePatternMatcher ({' ^dotnet %.exe$' }, MatchCompilerName , extractor , {
54
- prepend = {' --dotnetexec ' , ' --cil ' },
53
+ CreatePatternMatcher ({ ' ^csc.* %.exe$' }, MatchCompilerName , extractor , {
54
+ prepend = { ' --cil ' , ' --compiler ' , ' "${compiler}" ' },
55
55
order = ORDER_BEFORE
56
56
}),
57
- CreatePatternMatcher ({' ^csc.*%.exe$' }, MatchCompilerName , extractor , {
58
- prepend = {' --compiler' , ' "${compiler}"' , ' --cil' },
59
- order = ORDER_BEFORE
60
- }),
61
- CreatePatternMatcher ({' ^fakes.*%.exe$' , ' moles.*%.exe' },
62
- MatchCompilerName , nil , {trace = false })
57
+ CreatePatternMatcher ({ ' ^fakes.*%.exe$' , ' moles.*%.exe' },
58
+ MatchCompilerName , nil , { trace = false }),
59
+ function (compilerName , compilerPath , compilerArguments , _languageId )
60
+ -- handle cases like `dotnet.exe exec csc.dll <args>`
61
+ if compilerName ~= ' dotnet.exe' then
62
+ return nil
63
+ end
64
+
65
+ local seenCompilerCall = false
66
+ local argv = NativeArgumentsToArgv (compilerArguments .nativeArgumentPointer )
67
+ local extractorArgs = { ' --cil' , ' --compiler' }
68
+ for _ , arg in ipairs (argv ) do
69
+ if arg :match (' csc%.dll$' ) then
70
+ seenCompilerCall = true
71
+ end
72
+ if seenCompilerCall then
73
+ table.insert (extractorArgs , ' "' .. arg .. ' "' )
74
+ end
75
+ end
76
+
77
+ if seenCompilerCall then
78
+ return {
79
+ order = ORDER_BEFORE ,
80
+ invocation = {
81
+ path = AbsolutifyExtractorPath (id , extractor ),
82
+ arguments = {
83
+ commandLineString = table.concat (extractorArgs , " " )
84
+ }
85
+ }
86
+ }
87
+ end
88
+ return nil
89
+ end
63
90
}
64
91
local posixMatchers = {
65
92
DotnetMatcherBuild ,
66
- CreatePatternMatcher ({' ^mono' , ' ^dotnet$' }, MatchCompilerName ,
67
- extractor , {
68
- prepend = {' --dotnetexec' , ' --cil' },
69
- order = ORDER_BEFORE
70
- }),
71
- CreatePatternMatcher ({' ^mcs%.exe$' , ' ^csc%.exe$' }, MatchCompilerName ,
72
- extractor , {
73
- prepend = {' --compiler' , ' "${compiler}"' , ' --cil' },
93
+ CreatePatternMatcher ({ ' ^mcs%.exe$' , ' ^csc%.exe$' }, MatchCompilerName ,
94
+ extractor , {
95
+ prepend = { ' --cil' , ' --compiler' , ' "${compiler}"' },
74
96
order = ORDER_BEFORE
75
97
}), function (compilerName , compilerPath , compilerArguments , _languageId )
76
98
if MatchCompilerName (' ^msbuild$' , compilerName , compilerPath ,
77
- compilerArguments ) or
99
+ compilerArguments ) or
78
100
MatchCompilerName (' ^xbuild$' , compilerName , compilerPath ,
79
- compilerArguments ) then
101
+ compilerArguments ) then
80
102
return {
81
103
order = ORDER_REPLACE ,
82
104
invocation = BuildExtractorInvocation (id , compilerPath ,
83
- compilerPath ,
84
- compilerArguments ,
85
- nil , {
105
+ compilerPath ,
106
+ compilerArguments ,
107
+ nil , {
86
108
' /p:UseSharedCompilation=false'
87
109
})
88
110
89
111
}
90
112
end
113
+ end , function (compilerName , compilerPath , compilerArguments , _languageId )
114
+ -- handle cases like `dotnet exec csc.dll <args>` and `mono(-sgen64) csc.exe <args>`
115
+ if compilerName ~= ' dotnet' and not compilerName :match (' ^mono' ) then
116
+ return nil
117
+ end
118
+
119
+ local seenCompilerCall = false
120
+ local argv = compilerArguments .argv
121
+ local extractorArgs = { ' --cil' , ' --compiler' }
122
+ for _ , arg in ipairs (argv ) do
123
+ if arg :match (' csc%.dll$' ) or arg :match (' csc%.exe$' ) or arg :match (' mcs%.exe$' ) then
124
+ seenCompilerCall = true
125
+ end
126
+ if seenCompilerCall then
127
+ table.insert (extractorArgs , arg )
128
+ end
129
+ end
130
+
131
+ if seenCompilerCall then
132
+ return {
133
+ order = ORDER_BEFORE ,
134
+ invocation = {
135
+ path = AbsolutifyExtractorPath (id , extractor ),
136
+ arguments = {
137
+ argv = extractorArgs
138
+ }
139
+ }
140
+ }
141
+ end
142
+ return nil
91
143
end
92
144
}
93
145
if OperatingSystem == ' windows' then
99
151
100
152
-- Return a list of minimum supported versions of the configuration file format
101
153
-- return one entry per supported major version.
102
- function GetCompatibleVersions () return {' 1.0.0' } end
154
+ function GetCompatibleVersions () return { ' 1.0.0' } end
0 commit comments