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

Add /waitfordebugger argument to MGCB. #8227

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions .vscode/launch.json
Expand Up @@ -14,6 +14,20 @@
"cwd": "${workspaceFolder}/Artifacts/MonoGame.Content.Builder.Editor/Mac/Debug",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": "Attach to Process",
"type": "coreclr",
"request": "attach",
"processId": "${input.processid}",
}
],
"inputs": [
{
"id": "processid",
"type": "promptString",
"default": "0",
"description": "Enter Process Id of process to attach to."
}
]
}
30 changes: 20 additions & 10 deletions Tools/MonoGame.Content.Builder/BuildContent.cs
Expand Up @@ -17,9 +17,15 @@ class BuildContent
[CommandLineParameter(
Name = "launchdebugger",
Flag = "d",
Description = "Wait for debugger to attach before building content.")]
Description = "Launch the debugger before building content.")]
public bool LaunchDebugger = false;

[CommandLineParameter(
Name = "waitfordebugger",
Flag = "a",
Description = "Wait for debugger to attach before building content.")]
public bool WaitForDebuggerToAttach = false;

[CommandLineParameter(
Name = "quiet",
Flag = "q",
Expand Down Expand Up @@ -299,7 +305,7 @@ public void Build(out int successCount, out int errorCount)

// If the intent is to debug build, break at the original location
// of any exception, eg, within the actual importer/processor.
if (LaunchDebugger)
if (LaunchDebugger || WaitForDebuggerToAttach)
_manager.RethrowExceptions = false;

// Feed all the assembly references to the pipeline manager
Expand Down Expand Up @@ -450,10 +456,12 @@ public void Build(out int successCount, out int errorCount)
var dstTime = File.GetLastWriteTimeUtc(dest);
if (srcTime <= dstTime)
{
if (string.IsNullOrEmpty(c.Link))
Console.WriteLine("Skipping {0}", c.SourceFile);
else
Console.WriteLine("Skipping {0} => {1}", c.SourceFile, c.Link);
if (!Quiet) {
if (string.IsNullOrEmpty(c.Link))
Console.WriteLine("Skipping {0}", c.SourceFile);
else
Console.WriteLine("Skipping {0} => {1}", c.SourceFile, c.Link);
}

// Copy the stats from the previous stats collection.
_manager.ContentStats.CopyPreviousStats(c.SourceFile);
Expand All @@ -477,10 +485,12 @@ public void Build(out int successCount, out int errorCount)

var buildTime = DateTime.UtcNow - startTime;

if (string.IsNullOrEmpty(c.Link))
Console.WriteLine("{0}", c.SourceFile);
else
Console.WriteLine("{0} => {1}", c.SourceFile, c.Link);
if (!Quiet) {
if (string.IsNullOrEmpty(c.Link))
Console.WriteLine("{0}", c.SourceFile);
else
Console.WriteLine("{0} => {1}", c.SourceFile, c.Link);
}

// Record content stats on the copy.
_manager.ContentStats.RecordStats(c.SourceFile, dest, "CopyItem", typeof(File), (float)buildTime.TotalSeconds);
Expand Down
13 changes: 13 additions & 0 deletions Tools/MonoGame.Content.Builder/Program.cs
Expand Up @@ -3,6 +3,8 @@
// file 'LICENSE.txt', which is part of this source code package.

using System;
using System.Diagnostics;
using System.Threading;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -45,6 +47,17 @@ static int Main(string[] args)
Console.Error.WriteLine("The debugger is not implemented under Mono and thus is not supported on your platform.");
}
}
if (content.WaitForDebuggerToAttach)
{
var currentProcess = Process.GetCurrentProcess();
Console.WriteLine($"Waiting for debugger to attach ({currentProcess.MainModule.FileName} PID {currentProcess.Id}). Press any key to continue without debugger.");
while (!Debugger.IsAttached) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Braces should be be in new lines.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, let us use the same braces formatting as the rest of MonoGame, braces on new lines, indented with the function.

Other than that, it is good to go.

if (Console.KeyAvailable) {
break;
}
Thread.Sleep(100);
}
}

// Print a startup message.
var buildStarted = DateTime.Now;
Expand Down