Skip to content

Commit ac38906

Browse files
committed
C#: Limit detection of sub-command names
1 parent 69ea7d9 commit ac38906

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

csharp/tools/tracing-config.lua

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ function RegisterExtractorPack(id)
2424
local testMatch = false
2525
local dotnetRunNeedsSeparator = false;
2626
local dotnetRunInjectionIndex = nil;
27+
-- A flag indicating whether we are in a position where we expect a sub-command such as `build`.
28+
-- Once we have found one, we set this to `false` to not accidentally pick up on things that
29+
-- look like sub-command names later on in the argument vector.
30+
local inSubCommandPosition = true;
2731
local argv = compilerArguments.argv
2832
if OperatingSystem == 'windows' then
2933
-- let's hope that this split matches the escaping rules `dotnet` applies to command line arguments
@@ -35,30 +39,38 @@ function RegisterExtractorPack(id)
3539
-- dotnet options start with either - or / (both are legal)
3640
local firstCharacter = string.sub(arg, 1, 1)
3741
if not (firstCharacter == '-') and not (firstCharacter == '/') then
38-
if (not match) then
42+
if (not match) and inSubCommandPosition then
3943
Log(1, 'Dotnet subcommand detected: %s', arg)
4044
end
41-
if arg == 'build' or arg == 'msbuild' or arg == 'publish' or arg == 'pack' then
42-
match = true
43-
break
44-
end
45-
if arg == 'run' then
46-
-- for `dotnet run`, we need to make sure that `-p:UseSharedCompilation=false` is
47-
-- not passed in as an argument to the program that is run
48-
match = true
49-
dotnetRunNeedsSeparator = true
50-
dotnetRunInjectionIndex = i + 1
51-
end
52-
if arg == 'test' then
53-
match = true
54-
testMatch = true
45+
-- only respond to strings that look like sub-command names if we have not yet
46+
-- encountered something that looks like a sub-command
47+
if inSubCommandPosition then
48+
if arg == 'build' or arg == 'msbuild' or arg == 'publish' or arg == 'pack' then
49+
match = true
50+
break
51+
end
52+
if arg == 'run' then
53+
-- for `dotnet run`, we need to make sure that `-p:UseSharedCompilation=false` is
54+
-- not passed in as an argument to the program that is run
55+
match = true
56+
dotnetRunNeedsSeparator = true
57+
dotnetRunInjectionIndex = i + 1
58+
end
59+
if arg == 'test' then
60+
match = true
61+
testMatch = true
62+
end
5563
end
64+
5665
-- for `dotnet test`, we should not append `-p:UseSharedCompilation=false` to the command line
5766
-- if an `exe` or `dll` is passed as an argument as the call is forwarded to vstest.
5867
if testMatch and (arg:match('%.exe$') or arg:match('%.dll')) then
5968
match = false
6069
break
6170
end
71+
72+
-- we have found a sub-command, ignore all strings that look like sub-command names from now on
73+
inSubCommandPosition = false
6274
end
6375
-- if we see a separator to `dotnet run`, inject just prior to the existing separator
6476
if arg == '--' then

0 commit comments

Comments
 (0)