Browse Source

Enable MSBuild's change detection.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/dotnet4@4260 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 17 years ago
parent
commit
df936415bb
  1. 1
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  2. 58
      src/Main/Base/Project/Src/Project/MSBuildEngine/BuildLogFileLogger.cs
  3. 21
      src/Main/Base/Project/Src/Project/MSBuildEngine/MSBuildEngine.cs
  4. 32
      src/Main/Base/Project/Src/Project/MSBuildEngine/ParallelMSBuildManager.cs
  5. 23
      src/Main/Base/Project/Src/Project/MSBuildInternals.cs

1
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -193,6 +193,7 @@ @@ -193,6 +193,7 @@
<Compile Include="Src\Project\ContextSpecificProperties.cs" />
<Compile Include="Src\Project\IBuildFeedbackSink.cs" />
<Compile Include="Src\Project\IProjectItemBackendStore.cs" />
<Compile Include="Src\Project\MSBuildEngine\BuildLogFileLogger.cs" />
<Compile Include="Src\Project\MSBuildEngine\EventSource.cs" />
<Compile Include="Src\Project\MSBuildEngine\MSBuildEngine.cs" />
<Compile Include="Src\Project\MSBuildEngine\ParallelMSBuildManager.cs" />

58
src/Main/Base/Project/Src/Project/MSBuildEngine/BuildLogFileLogger.cs

@ -0,0 +1,58 @@ @@ -0,0 +1,58 @@
/*
* Created by SharpDevelop.
* User: Daniel
* Date: 07.06.2009
* Time: 14:56
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using Microsoft.Build.Framework;
using Microsoft.Build.Logging;
using System.IO;
namespace ICSharpCode.SharpDevelop.Project
{
sealed class BuildLogFileLogger : ConsoleLogger
{
string fileName;
StreamWriter writer;
public BuildLogFileLogger(string fileName, LoggerVerbosity verbosity)
: base(verbosity)
{
this.fileName = fileName;
base.WriteHandler = Write;
}
public override void Initialize(IEventSource eventSource)
{
OpenFile();
base.Initialize(eventSource);
}
public override void Initialize(IEventSource eventSource, int nodeCount)
{
OpenFile();
base.Initialize(eventSource, nodeCount);
}
void OpenFile()
{
writer = new StreamWriter(fileName);
}
public override void Shutdown()
{
base.Shutdown();
writer.Close();
writer = null;
}
void Write(string text)
{
if (writer != null)
writer.Write(text);
}
}
}

21
src/Main/Base/Project/Src/Project/MSBuildEngine/MSBuildEngine.cs

@ -5,7 +5,6 @@ @@ -5,7 +5,6 @@
// <version>$Revision$</version>
// </file>
using Microsoft.Build.Construction;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@ -15,6 +14,7 @@ using System.Text.RegularExpressions; @@ -15,6 +14,7 @@ using System.Text.RegularExpressions;
using System.Threading;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
using Microsoft.Build.Construction;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
using MSBuild = Microsoft.Build.Evaluation;
@ -71,6 +71,9 @@ namespace ICSharpCode.SharpDevelop.Project @@ -71,6 +71,9 @@ namespace ICSharpCode.SharpDevelop.Project
MSBuildProperties = new SortedList<string, string>();
MSBuildProperties.Add("SharpDevelopBinPath", Path.GetDirectoryName(typeof(MSBuildEngine).Assembly.Location));
// 'BuildingInsideVisualStudio' tells MSBuild that we took care of building a project's dependencies
// before trying to build the project itself. This speeds up compilation because it prevents MSBuild from
// repeatedly looking if a project needs to be rebuilt.
MSBuildProperties.Add("BuildingInsideVisualStudio", "true");
}
@ -182,11 +185,25 @@ namespace ICSharpCode.SharpDevelop.Project @@ -182,11 +185,25 @@ namespace ICSharpCode.SharpDevelop.Project
ProjectRootElement projectFile = ProjectRootElement.Open(project.FileName);
foreach (string import in additionalTargetFiles)
projectFile.AddImport(import);
if (globalProperties.ContainsKey("BuildingInsideVisualStudio")) {
// When we set BuildingInsideVisualStudio, MSBuild skips its own change detection
// because in Visual Studio, the host compiler does the change detection.
// We override the property '_ComputeNonExistentFileProperty' which is responsible
// for recompiling each time - our _ComputeNonExistentFileProperty does nothing,
// which re-enables the MSBuild's usual change detection.
projectFile.AddTarget("_ComputeNonExistentFileProperty");
}
ProjectInstance projectInstance = MSBuildInternals.LoadProjectInstance(projectFile, globalProperties);
string[] targets = { options.Target.TargetName };
BuildRequestData requestData = new BuildRequestData(projectInstance, targets, new HostServices());
ParallelMSBuildManager.StartBuild(requestData, new SharpDevelopLogger(this), OnComplete);
ILogger[] loggers = {
new SharpDevelopLogger(this),
new BuildLogFileLogger(projectFile.FullPath + ".log", LoggerVerbosity.Diagnostic)
};
ParallelMSBuildManager.StartBuild(requestData, loggers, OnComplete);
}
void OnComplete(BuildSubmission submission)

32
src/Main/Base/Project/Src/Project/MSBuildEngine/ParallelMSBuildManager.cs

@ -5,12 +5,13 @@ @@ -5,12 +5,13 @@
// <version>$Revision$</version>
// </file>
using Microsoft.Build.Logging;
using System;
using System.Collections.Generic;
using ICSharpCode.Core;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
using Microsoft.Build.Logging;
using System.Linq;
namespace ICSharpCode.SharpDevelop.Project
{
@ -72,18 +73,27 @@ namespace ICSharpCode.SharpDevelop.Project @@ -72,18 +73,27 @@ namespace ICSharpCode.SharpDevelop.Project
/// <param name="logger">The logger that received build output.</param>
/// <param name="callback">Callback that is run when the build is complete</param>
/// <returns>The build submission that was started.</returns>
public static BuildSubmission StartBuild(BuildRequestData requestData, ILogger logger, BuildSubmissionCompleteCallback callback)
public static BuildSubmission StartBuild(BuildRequestData requestData, IEnumerable<ILogger> loggers, BuildSubmissionCompleteCallback callback)
{
if (requestData == null)
throw new ArgumentNullException("requestData");
ILogger[] loggersArray;
if (loggers == null)
loggersArray = new ILogger[0];
else
loggersArray = loggers.ToArray(); // iterate through logger enumerable once
EnableBuildEngine();
try {
BuildSubmission submission = BuildManager.DefaultBuildManager.PendBuildRequest(requestData);
EventSource eventSource = new EventSource();
if (logger != null)
logger.Initialize(eventSource);
foreach (ILogger logger in loggersArray) {
if (logger != null)
logger.Initialize(eventSource);
}
lock (submissionEventSourceMapping) {
submissionEventSourceMapping.Add(submission.SubmissionId, eventSource);
}
RunningBuild build = new RunningBuild(eventSource, logger, callback);
RunningBuild build = new RunningBuild(eventSource, loggersArray, callback);
submission.ExecuteAsync(build.OnComplete, null);
return submission;
} catch (Exception ex) {
@ -95,14 +105,14 @@ namespace ICSharpCode.SharpDevelop.Project @@ -95,14 +105,14 @@ namespace ICSharpCode.SharpDevelop.Project
sealed class RunningBuild
{
ILogger logger;
ILogger[] loggers;
BuildSubmissionCompleteCallback callback;
EventSource eventSource;
public RunningBuild(EventSource eventSource, ILogger logger, BuildSubmissionCompleteCallback callback)
public RunningBuild(EventSource eventSource, ILogger[] loggers, BuildSubmissionCompleteCallback callback)
{
this.eventSource = eventSource;
this.logger = logger;
this.loggers = loggers;
this.callback = callback;
}
@ -117,8 +127,10 @@ namespace ICSharpCode.SharpDevelop.Project @@ -117,8 +127,10 @@ namespace ICSharpCode.SharpDevelop.Project
LoggingService.Error(submission.BuildResult.Exception);
eventSource.ForwardEvent(new BuildErrorEventArgs(null, null, null, 0, 0, 0, 0, submission.BuildResult.Exception.ToString(), null, null));
}
if (logger != null)
logger.Shutdown();
foreach (ILogger logger in loggers) {
if (logger != null)
logger.Shutdown();
}
if (callback != null)
callback(submission);
}

23
src/Main/Base/Project/Src/Project/MSBuildInternals.cs

@ -5,21 +5,15 @@ @@ -5,21 +5,15 @@
// <version>$Revision$</version>
// </file>
using Microsoft.Build.Construction;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using ICSharpCode.Core;
using Microsoft.Build.Construction;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
using MSBuild = Microsoft.Build;
using ProjectCollection = Microsoft.Build.Evaluation.ProjectCollection;
@ -171,7 +165,8 @@ namespace ICSharpCode.SharpDevelop.Project @@ -171,7 +165,8 @@ namespace ICSharpCode.SharpDevelop.Project
string[] targets = { "ResolveAssemblyReferences" };
BuildRequestData requestData = new BuildRequestData(project, targets, new HostServices());
BuildSubmission submission = ParallelMSBuildManager.StartBuild(requestData, new SimpleErrorLogger(), null);
ILogger[] loggers = { new SimpleErrorLogger() };
BuildSubmission submission = ParallelMSBuildManager.StartBuild(requestData, loggers, null);
LoggingService.Debug("Started build for ResolveAssemblyReferences");
submission.WaitHandle.WaitOne();
BuildResult result = submission.BuildResult;
@ -212,8 +207,8 @@ namespace ICSharpCode.SharpDevelop.Project @@ -212,8 +207,8 @@ namespace ICSharpCode.SharpDevelop.Project
public void Initialize(IEventSource eventSource)
{
eventSource.ErrorRaised += OnError;
eventSource.WarningRaised += OnWarning;
eventSource.ErrorRaised += OnError;
eventSource.WarningRaised += OnWarning;
}
public void Shutdown()
@ -223,10 +218,12 @@ namespace ICSharpCode.SharpDevelop.Project @@ -223,10 +218,12 @@ namespace ICSharpCode.SharpDevelop.Project
void OnError(object sender, BuildErrorEventArgs e)
{
TaskService.BuildMessageViewCategory.AppendLine(e.Message);
}
void OnWarning(object sender, BuildWarningEventArgs e)
{
TaskService.BuildMessageViewCategory.AppendLine(e.Message);
}
}
}

Loading…
Cancel
Save