-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Ensure all evaluation data are in binlogs from file-based apps #49841
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,7 +180,6 @@ public override int Execute() | |
} | ||
|
||
Dictionary<string, string?> savedEnvironmentVariables = []; | ||
ProjectCollection? projectCollection = null; | ||
try | ||
{ | ||
// Set environment variables. | ||
|
@@ -191,17 +190,20 @@ public override int Execute() | |
} | ||
|
||
// Set up MSBuild. | ||
ReadOnlySpan<ILogger> binaryLoggers = binaryLogger is null ? [] : [binaryLogger]; | ||
projectCollection = new ProjectCollection( | ||
ReadOnlySpan<ILogger> binaryLoggers = binaryLogger is null ? [] : [binaryLogger.Value]; | ||
IEnumerable<ILogger> loggers = [.. binaryLoggers, consoleLogger]; | ||
var projectCollection = new ProjectCollection( | ||
MSBuildArgs.GlobalProperties, | ||
[.. binaryLoggers, consoleLogger], | ||
loggers, | ||
ToolsetDefinitionLocations.Default); | ||
var parameters = new BuildParameters(projectCollection) | ||
{ | ||
Loggers = projectCollection.Loggers, | ||
Loggers = loggers, | ||
LogTaskInputs = binaryLoggers.Length != 0, | ||
}; | ||
|
||
BuildManager.DefaultBuildManager.BeginBuild(parameters); | ||
|
||
// Do a restore first (equivalent to MSBuild's "implicit restore", i.e., `/restore`). | ||
// See https://github.com/dotnet/msbuild/blob/a1c2e7402ef0abe36bf493e395b04dd2cb1b3540/src/MSBuild/XMake.cs#L1838 | ||
// and https://github.com/dotnet/msbuild/issues/11519. | ||
|
@@ -213,8 +215,6 @@ public override int Execute() | |
hostServices: null, | ||
BuildRequestDataFlags.ClearCachesAfterBuild | BuildRequestDataFlags.SkipNonexistentTargets | BuildRequestDataFlags.IgnoreMissingEmptyAndInvalidImports | BuildRequestDataFlags.FailOnUnresolvedSdk); | ||
|
||
BuildManager.DefaultBuildManager.BeginBuild(parameters); | ||
|
||
var restoreResult = BuildManager.DefaultBuildManager.BuildRequest(restoreRequest); | ||
if (restoreResult.OverallResult != BuildResultCode.Success) | ||
{ | ||
|
@@ -229,12 +229,6 @@ public override int Execute() | |
CreateProjectInstance(projectCollection), | ||
targetsToBuild: MSBuildArgs.RequestedTargets ?? ["Build"]); | ||
|
||
// For some reason we need to BeginBuild after creating BuildRequestData otherwise the binlog doesn't contain Evaluation. | ||
if (NoRestore) | ||
{ | ||
BuildManager.DefaultBuildManager.BeginBuild(parameters); | ||
} | ||
|
||
var buildResult = BuildManager.DefaultBuildManager.BuildRequest(buildRequest); | ||
if (buildResult.OverallResult != BuildResultCode.Success) | ||
{ | ||
|
@@ -261,7 +255,7 @@ public override int Execute() | |
Environment.SetEnvironmentVariable(key, value); | ||
} | ||
|
||
binaryLogger?.Shutdown(); | ||
binaryLogger?.Value.ReallyShutdown(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this is a method on the facade type, where the ordinary shutdown method doesn't do anything on it? |
||
consoleLogger.Shutdown(); | ||
} | ||
|
||
|
@@ -289,7 +283,7 @@ static Action<IDictionary<string, string>> AddRestoreGlobalProperties(ReadOnlyDi | |
}; | ||
} | ||
|
||
static ILogger? GetBinaryLogger(IReadOnlyList<string>? args) | ||
static Lazy<FacadeLogger>? GetBinaryLogger(IReadOnlyList<string>? args) | ||
{ | ||
if (args is null) return null; | ||
// Like in MSBuild, only the last binary logger is used. | ||
|
@@ -298,12 +292,17 @@ static Action<IDictionary<string, string>> AddRestoreGlobalProperties(ReadOnlyDi | |
var arg = args[i]; | ||
if (LoggerUtility.IsBinLogArgument(arg)) | ||
{ | ||
return new BinaryLogger | ||
// We don't want to create the binlog file until actually needed, hence we wrap this in a Lazy. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not? |
||
return new(() => | ||
{ | ||
Parameters = arg.IndexOf(':') is >= 0 and var index | ||
? arg[(index + 1)..] | ||
: "msbuild.binlog", | ||
}; | ||
var logger = new BinaryLogger | ||
{ | ||
Parameters = arg.IndexOf(':') is >= 0 and var index | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to worry about the source of |
||
? arg[(index + 1)..] | ||
: "msbuild.binlog", | ||
}; | ||
return LoggerUtility.CreateFacadeLogger([logger]); | ||
}); | ||
} | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.