Skip to content

C#: Recognize options to dotnet run in tracer when injecting -p:UseSharedCompilation=false #10667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ def check_build_out(msg, s):
# to `dotnet run -p:UseSharedCompilation=true -p:UseSharedCompilation=false -- hello world`
s = run_codeql_database_create_stdout(['dotnet clean', 'rm -rf test6-db', 'dotnet run -p:UseSharedCompilation=true -- hello world'], "test7-db")
check_build_out("hello, world", s)

# option passed into `dotnet run`
s = run_codeql_database_create_stdout(['dotnet clean', 'rm -rf test7-db', 'dotnet build', 'dotnet run --no-build hello world'], "test8-db")
check_build_out("hello, world", s)
29 changes: 19 additions & 10 deletions csharp/tools/tracing-config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ function RegisterExtractorPack(id)
-- if that's `build`, we append `-p:UseSharedCompilation=false` to the command line,
-- otherwise we do nothing.
local match = false
local needsSeparator = false;
local injectionIndex = nil;
local dotnetRunNeedsSeparator = false;
local dotnetRunInjectionIndex = 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
Expand All @@ -34,7 +34,9 @@ function RegisterExtractorPack(id)
-- dotnet options start with either - or / (both are legal)
local firstCharacter = string.sub(arg, 1, 1)
if not (firstCharacter == '-') and not (firstCharacter == '/') then
Log(1, 'Dotnet subcommand detected: %s', arg)
if (not match) then
Log(1, 'Dotnet subcommand detected: %s', arg)
end
if arg == 'build' or arg == 'msbuild' or arg == 'publish' or arg == 'pack' or arg == 'test' then
match = true
break
Expand All @@ -43,22 +45,29 @@ function RegisterExtractorPack(id)
-- 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
dotnetRunNeedsSeparator = true
dotnetRunInjectionIndex = i + 1
end
end
-- if we see a separator to `dotnet run`, inject just prior to the existing separator
if arg == '--' then
needsSeparator = false
injectionIndex = i
dotnetRunNeedsSeparator = false
dotnetRunInjectionIndex = i
break
end
-- if we see an option to `dotnet run` (e.g., `--project`), inject just prior
-- to the last option
if firstCharacter == '-' then
dotnetRunNeedsSeparator = false
dotnetRunInjectionIndex = i
end
end
if match then
local injections = { '-p:UseSharedCompilation=false' }
if needsSeparator then
if dotnetRunNeedsSeparator then
table.insert(injections, '--')
end
if injectionIndex == nil then
if dotnetRunInjectionIndex == nil then
-- Simple case; just append at the end
return {
order = ORDER_REPLACE,
Expand All @@ -69,7 +78,7 @@ function RegisterExtractorPack(id)

-- 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)
table.insert(argv, dotnetRunInjectionIndex + i - 1, injectionArg)
end

if OperatingSystem == 'windows' then
Expand Down