From cc09a79cfab1cc7633d37b7e1e96d638ca1a0c89 Mon Sep 17 00:00:00 2001 From: Tom Hvitved Date: Mon, 19 Sep 2022 09:30:16 +0200 Subject: [PATCH] C#: Prepend `-p:UseSharedCompilation=false` instead of append for `dotnet run` --- csharp/tools/tracing-config.lua | 56 ++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/csharp/tools/tracing-config.lua b/csharp/tools/tracing-config.lua index 7c62f0062e4..b8a4d4ed847 100644 --- a/csharp/tools/tracing-config.lua +++ b/csharp/tools/tracing-config.lua @@ -22,6 +22,7 @@ function RegisterExtractorPack(id) -- otherwise we do nothing. local match = false local needsSeparator = false; + local injectionIndex = nil; local argv = compilerArguments.argv if OperatingSystem == 'windows' then -- let's hope that this split matches the escaping rules `dotnet` applies to command line arguments @@ -38,13 +39,60 @@ function RegisterExtractorPack(id) match = true break end + if arg == 'run' then + -- for `dotnet run`, we need to make sure that `-p:UseSharedCompilation=false` is + -- not passed in as an argument to the program that is run + match = true + needsSeparator = true + injectionIndex = i + 1 + end + end + if arg == '--' then + needsSeparator = false + injectionIndex = i + break end end if match then - return { - order = ORDER_REPLACE, - invocation = BuildExtractorInvocation(id, compilerPath, compilerPath, compilerArguments, nil, { '-p:UseSharedCompilation=false' }) - } + local injections = { '-p:UseSharedCompilation=false' } + if needsSeparator then + table.insert(injections, '--') + end + if injectionIndex == nil then + -- Simple case; just append at the end + return { + order = ORDER_REPLACE, + invocation = BuildExtractorInvocation(id, compilerPath, compilerPath, compilerArguments, nil, + injections) + } + end + + -- Complex case; splice injections into the middle of the command line + for i, injectionArg in ipairs(injections) do + table.insert(argv, injectionIndex + i - 1, injectionArg) + end + + if OperatingSystem == 'windows' then + return { + order = ORDER_REPLACE, + invocation = { + path = AbsolutifyExtractorPath(id, compilerPath), + arguments = { + commandLineString = table.concat(argv, " ") + } + } + } + else + return { + order = ORDER_REPLACE, + invocation = { + path = AbsolutifyExtractorPath(id, compilerPath), + arguments = { + argv = argv + } + } + } + end end return nil end