Skip to content
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

Revert MSBuildDebugEngine #6787

Closed
Closed
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
2 changes: 1 addition & 1 deletion documentation/wiki/ChangeWaves.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ A wave of features is set to "rotate out" (i.e. become standard functionality) t
- [Scheduler should honor BuildParameters.DisableInprocNode](https://github.com/dotnet/msbuild/pull/6400)
- [Don't compile globbing regexes on .NET Framework](https://github.com/dotnet/msbuild/pull/6632)
- [Default to transitively copying content items](https://github.com/dotnet/msbuild/pull/6622)
- [Improve debugging experience: add global switch MSBuildDebugEngine; Inject binary logger from BuildManager; print static graph as .dot file](https://github.com/dotnet/msbuild/pull/6639)
- [Reference assemblies are now no longer placed in the `bin` directory by default](https://github.com/dotnet/msbuild/pull/6560)

## Change Waves No Longer In Rotation
### 16.8
Expand Down
18 changes: 3 additions & 15 deletions src/Build.UnitTests/Graph/ProjectGraph_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1476,34 +1476,22 @@ public void DotNotationShouldRepresentGraph(Dictionary<int, int[]> edges)
var graph = Helpers.CreateProjectGraph(
_env,
edges,
globalProperties: new Dictionary<string, string> {{"a", "b"}},
createProjectFile: (env, projectId, references, _, _, _) => Helpers.CreateProjectFile(
env,
projectId,
references,
projectReferenceTargets: new Dictionary<string, string[]>
{
{"Build", new[] {$"TargetFrom{projectId}", "Build"}}
}));
new Dictionary<string, string> {{"a", "b"}});

var targetsPerNode = graph.GetTargetLists(new []{ "Build" });

Func<ProjectGraphNode, string> nodeIdProvider = GetProjectFileName;

var dot = graph.ToDot(nodeIdProvider, targetsPerNode);
var dot = graph.ToDot(nodeIdProvider);

var edgeCount = 0;

foreach (var node in graph.ProjectNodes)
{
var nodeId = nodeIdProvider(node);

var targets = string.Join(".*", targetsPerNode[node]);
targets.ShouldNotBeNullOrEmpty();

foreach (var globalProperty in node.ProjectInstance.GlobalProperties)
{
dot.ShouldMatch($@"{nodeId}\s*\[.*{targets}.*{globalProperty.Key}.*{globalProperty.Value}.*\]");
dot.ShouldMatch($@"{nodeId}\s*\[.*{globalProperty.Key}.*{globalProperty.Value}.*\]");
}

foreach (var reference in node.ProjectReferences)
Expand Down
49 changes: 8 additions & 41 deletions src/Build/BackEnd/BuildManager/BuildManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
using Microsoft.Build.Internal;
using Microsoft.Build.Logging;
using Microsoft.Build.Shared;
using Microsoft.Build.Shared.Debugging;
using Microsoft.Build.Shared.FileSystem;
using Microsoft.Build.Utilities;
using ForwardingLoggerRecord = Microsoft.Build.Logging.ForwardingLoggerRecord;
using LoggerDescription = Microsoft.Build.Logging.LoggerDescription;

Expand Down Expand Up @@ -488,7 +486,7 @@ public void BeginBuild(BuildParameters parameters)
ILoggingService InitializeLoggingService()
{
ILoggingService loggingService = CreateLoggingService(
AppendDebuggingLoggers(_buildParameters.Loggers),
_buildParameters.Loggers,
_buildParameters.ForwardingLoggers,
_buildParameters.WarningsAsErrors,
_buildParameters.WarningsAsMessages);
Expand Down Expand Up @@ -520,22 +518,6 @@ ILoggingService InitializeLoggingService()
return loggingService;
}

// VS builds discard many msbuild events so attach a binlogger to capture them all.
IEnumerable<ILogger> AppendDebuggingLoggers(IEnumerable<ILogger> loggers)
{
if (DebugUtils.ShouldDebugCurrentProcess is false ||
Traits.Instance.DebugEngine is false)
{
return loggers;
}

var binlogPath = DebugUtils.FindNextAvailableDebugFilePath($"{DebugUtils.ProcessInfoString}_BuildManager_{_hostName}.binlog");

var logger = new BinaryLogger { Parameters = binlogPath };

return (loggers ?? Enumerable.Empty<ILogger>()).Concat(new[] { logger });
}

void InitializeCaches()
{
Debug.Assert(Monitor.IsEntered(_syncLock));
Expand Down Expand Up @@ -579,14 +561,17 @@ void InitializeCaches()
}
}

private static void AttachDebugger()
private void AttachDebugger()
{
if (Debugger.IsAttached)
{
return;
}

if (!DebugUtils.ShouldDebugCurrentProcess)
var processNameToBreakInto = Environment.GetEnvironmentVariable("MSBuildDebugBuildManagerOnStartProcessName");
var thisProcessMatchesName = string.IsNullOrWhiteSpace(processNameToBreakInto) || Process.GetCurrentProcess().ProcessName.Contains(processNameToBreakInto);

if (!thisProcessMatchesName)
{
return;
}
Expand Down Expand Up @@ -1818,17 +1803,11 @@ private void ExecuteGraphBuildScheduler(GraphBuildSubmission submission)
if (submission.BuildRequestData.GraphBuildOptions.Build)
{
var cacheServiceTask = Task.Run(() => SearchAndInitializeProjectCachePluginFromGraph(projectGraph));
var targetListTask = projectGraph.GetTargetLists(submission.BuildRequestData.TargetNames);

DumpGraph(projectGraph, targetListTask);
var targetListTask = Task.Run(() => projectGraph.GetTargetLists(submission.BuildRequestData.TargetNames));

using DisposablePluginService cacheService = cacheServiceTask.Result;

resultsPerNode = BuildGraph(projectGraph, targetListTask, submission.BuildRequestData);
}
else
{
DumpGraph(projectGraph);
resultsPerNode = BuildGraph(projectGraph, targetListTask.Result, submission.BuildRequestData);
}

ErrorUtilities.VerifyThrow(
Expand Down Expand Up @@ -1892,18 +1871,6 @@ private void ExecuteGraphBuildScheduler(GraphBuildSubmission submission)
_overallBuildSuccess = false;
}
}

static void DumpGraph(ProjectGraph graph, IReadOnlyDictionary<ProjectGraphNode, ImmutableList<string>> targetList = null)
{
if (Traits.Instance.DebugEngine is false)
{
return;
}

var logPath = DebugUtils.FindNextAvailableDebugFilePath($"{DebugUtils.ProcessInfoString}_ProjectGraph.dot");

File.WriteAllText(logPath, graph.ToDot(targetList));
}
}

private Dictionary<ProjectGraphNode, BuildResult> BuildGraph(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
using Microsoft.Build.BackEnd.Logging;
using Microsoft.Build.Execution;
using Microsoft.Build.Shared;
using Microsoft.Build.Shared.Debugging;
using Microsoft.Build.Utilities;
using BuildAbortedException = Microsoft.Build.Exceptions.BuildAbortedException;

namespace Microsoft.Build.BackEnd
Expand Down Expand Up @@ -117,10 +115,8 @@ internal class BuildRequestEngine : IBuildRequestEngine, IBuildComponent
/// </summary>
internal BuildRequestEngine()
{
_debugDumpState = Traits.Instance.DebugScheduler;
_debugDumpPath = ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_0)
? DebugUtils.DebugPath
: Environment.GetEnvironmentVariable("MSBUILDDEBUGPATH");
_debugDumpState = Environment.GetEnvironmentVariable("MSBUILDDEBUGSCHEDULER") == "1";
_debugDumpPath = Environment.GetEnvironmentVariable("MSBUILDDEBUGPATH");
_debugForceCaching = Environment.GetEnvironmentVariable("MSBUILDDEBUGFORCECACHING") == "1";

if (String.IsNullOrEmpty(_debugDumpPath))
Expand Down
Loading