Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit 94b4f95

Browse files
committed
[Core] Support generating a binlog for any MSBuild target
Previously a binlog file would only be generated if a Build was run. Now it is possible to have a binlog generated for any MSBuild target. The filename for the bin log can be specified when running an MSBuild target by setting the TargetEvaluationContext's BinLogFilePath. Note that setting the BinLogFilePath if a build session is in progress will not have any affect, the build session's binlog overrides this setting.
1 parent c201f24 commit 94b4f95

File tree

8 files changed

+34
-8
lines changed

8 files changed

+34
-8
lines changed

main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/RemoteProjectBuilder.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public async Task<MSBuildResult> Run (
9191
TextWriter logWriter,
9292
MSBuildLogger logger,
9393
MSBuildVerbosity verbosity,
94+
string binLogFilePath,
9495
string[] runTargets,
9596
string[] evaluateItems,
9697
string[] evaluateProperties,
@@ -105,7 +106,7 @@ CancellationToken cancellationToken
105106

106107
try {
107108
BeginOperation ();
108-
var res = await SendRun (configurations, loggerId, logger.EnabledEvents, verbosity, runTargets, evaluateItems, evaluateProperties, globalProperties, taskId).ConfigureAwait (false);
109+
var res = await SendRun (configurations, loggerId, logger.EnabledEvents, verbosity, binLogFilePath, runTargets, evaluateItems, evaluateProperties, globalProperties, taskId).ConfigureAwait (false);
109110
if (res == null && cancellationToken.IsCancellationRequested) {
110111
MSBuildTargetResult err = new MSBuildTargetResult (file, false, "", "", file, 1, 1, 1, 1, "Build cancelled", "");
111112
return new MSBuildResult (new [] { err });
@@ -170,7 +171,7 @@ Task SendRefreshWithContent (string projectContent)
170171
return connection.SendMessage (new RefreshWithContentRequest { ProjectId = projectId, Content = projectContent });
171172
}
172173

173-
async Task<MSBuildResult> SendRun (ProjectConfigurationInfo [] configurations, int loggerId, MSBuildEvent enabledLogEvents, MSBuildVerbosity verbosity, string [] runTargets, string [] evaluateItems, string [] evaluateProperties, Dictionary<string, string> globalProperties, int taskId)
174+
async Task<MSBuildResult> SendRun (ProjectConfigurationInfo [] configurations, int loggerId, MSBuildEvent enabledLogEvents, MSBuildVerbosity verbosity, string binLogFilePath, string [] runTargets, string [] evaluateItems, string [] evaluateProperties, Dictionary<string, string> globalProperties, int taskId)
174175
{
175176
var msg = new RunProjectRequest {
176177
ProjectId = projectId,
@@ -182,7 +183,8 @@ async Task<MSBuildResult> SendRun (ProjectConfigurationInfo [] configurations, i
182183
EvaluateItems = evaluateItems,
183184
EvaluateProperties = evaluateProperties,
184185
GlobalProperties = globalProperties,
185-
TaskId = taskId
186+
TaskId = taskId,
187+
BinLogFilePath = binLogFilePath
186188
};
187189

188190
var res = await connection.SendMessage (msg);
@@ -293,13 +295,14 @@ public Task<MSBuildResult> Run (
293295
TextWriter logWriter,
294296
MSBuildLogger logger,
295297
MSBuildVerbosity verbosity,
298+
string binLogFilePath,
296299
string [] runTargets,
297300
string [] evaluateItems,
298301
string [] evaluateProperties,
299302
Dictionary<string, string> globalProperties,
300303
CancellationToken cancellationToken
301304
) {
302-
return builder.Run (configurations, logWriter, logger, verbosity, runTargets, evaluateItems, evaluateProperties, globalProperties, cancellationToken);
305+
return builder.Run (configurations, logWriter, logger, verbosity, binLogFilePath, runTargets, evaluateItems, evaluateProperties, globalProperties, cancellationToken);
303306
}
304307

305308
public void Dispose ()
@@ -317,6 +320,7 @@ Task<MSBuildResult> Run (
317320
TextWriter logWriter,
318321
MSBuildLogger logger,
319322
MSBuildVerbosity verbosity,
323+
string binLogFilePath,
320324
string [] runTargets,
321325
string [] evaluateItems,
322326
string [] evaluateProperties,

main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,7 @@ await Task.Run (async delegate {
15091509
var logger = context.Loggers.Count != 1 ? new ProxyLogger (this, context.Loggers) : context.Loggers.First ();
15101510

15111511
try {
1512-
result = await builder.Run (configs, monitor.Log, logger, context.LogVerbosity, targets, evaluateItems, evaluateProperties, globalProperties, monitor.CancellationToken).ConfigureAwait (false);
1512+
result = await builder.Run (configs, monitor.Log, logger, context.LogVerbosity, context.BinLogFilePath, targets, evaluateItems, evaluateProperties, globalProperties, monitor.CancellationToken).ConfigureAwait (false);
15131513
} finally {
15141514
builder.Dispose ();
15151515
t1.End ();

main/src/core/MonoDevelop.Core/MonoDevelop.Projects/TargetEvaluationContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public ICollection<MSBuildLogger> Loggers {
5656
get { return loggers; }
5757
}
5858

59+
public string BinLogFilePath { get; set; }
60+
5961
/// <summary>
6062
/// Gets or sets the builder queue to be used to execute the target
6163
/// </summary>

main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.MSBuild/BuildEngine.Shared.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public BinaryMessage RunProject (RunProjectRequest msg)
200200
var pb = GetProject (msg.ProjectId);
201201
if (pb != null) {
202202
var logger = msg.LogWriterId != -1 ? (IEngineLogWriter) new LogWriter (msg.LogWriterId, msg.EnabledLogEvents) : (IEngineLogWriter) new NullLogWriter ();
203-
var res = pb.Run (msg.Configurations, logger, msg.Verbosity, msg.RunTargets, msg.EvaluateItems, msg.EvaluateProperties, msg.GlobalProperties, msg.TaskId);
203+
var res = pb.Run (msg.Configurations, logger, msg.Verbosity, msg.BinLogFilePath, msg.RunTargets, msg.EvaluateItems, msg.EvaluateProperties, msg.GlobalProperties, msg.TaskId);
204204
return new RunProjectResponse { Result = res };
205205
}
206206
return msg.CreateResponse ();

main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.MSBuild/MSBuildLoggerAdapter.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ public List<MSBuildTargetResult> BuildResult {
9393
get { return results; }
9494
}
9595

96+
public void AddLogger (ILogger logger)
97+
{
98+
var newLoggers = new ILogger [loggers.Length + 1];
99+
Array.Copy (loggers, newLoggers, loggers.Length);
100+
newLoggers [loggers.Length] = logger;
101+
loggers = newLoggers;
102+
}
103+
96104
void Initialize (IEventSource eventSource)
97105
{
98106
this.eventSource = eventSource;

main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.MSBuild/ProjectBuilder.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public ProjectBuilder (BuildEngine buildEngine, ProjectCollection engine, string
5454
}
5555

5656
public MSBuildResult Run (
57-
ProjectConfigurationInfo[] configurations, IEngineLogWriter logWriter, MSBuildVerbosity verbosity,
57+
ProjectConfigurationInfo[] configurations, IEngineLogWriter logWriter, MSBuildVerbosity verbosity, string binLogFilePath,
5858
string[] runTargets, string[] evaluateItems, string[] evaluateProperties, Dictionary<string,string> globalProperties, int taskId)
5959
{
6060
if (runTargets == null || runTargets.Length == 0)
@@ -71,8 +71,16 @@ public MSBuildResult Run (
7171
if (buildEngine.BuildOperationStarted) {
7272
loggerAdapter = buildEngine.StartProjectSessionBuild (logWriter);
7373
}
74-
else
74+
else {
7575
loggerAdapter = new MSBuildLoggerAdapter (logWriter, verbosity);
76+
if (!string.IsNullOrEmpty (binLogFilePath)) {
77+
var binaryLogger = new BinaryLogger {
78+
Parameters = binLogFilePath,
79+
Verbosity = LoggerVerbosity.Diagnostic
80+
};
81+
loggerAdapter.AddLogger (binaryLogger);
82+
}
83+
}
7684

7785
try {
7886
project = SetupProject (configurations);

main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.MSBuild/RemoteBuildEngineMessages.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ class RunProjectRequest: BinaryMessage<RunProjectResponse>
144144

145145
[MessageDataProperty]
146146
public int TaskId { get; set; }
147+
148+
[MessageDataProperty]
149+
public string BinLogFilePath { get; set; }
147150
}
148151

149152
[MessageDataTypeAttribute]

main/tests/MonoDevelop.Core.Tests/MonoDevelop.Projects/BuilderManagerTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ public async Task ReloadProject_ProjectDisposedWhilstTargetRunning_AnotherTarget
418418
new StringWriter (),
419419
new MSBuildLogger (),
420420
MSBuildVerbosity.Quiet,
421+
null,
421422
new [] { "ResolveAssemblyReferences" },
422423
new string [0],
423424
new string [0],

0 commit comments

Comments
 (0)