Browse Source

Modified the MonoCompilerTask class (base class for all mono compiler tasks) so it uses Microsoft's ToolTask class to run the compiler instead of doing all the work itself.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1161 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 20 years ago
parent
commit
17aa48e709
  1. 2
      src/Libraries/ICSharpCode.Build.Tasks/Project/ICSharpCode.Build.Tasks.csproj
  2. 17
      src/Libraries/ICSharpCode.Build.Tasks/Project/ICompilerResultsParser.cs
  3. 17
      src/Libraries/ICSharpCode.Build.Tasks/Project/Mbas.cs
  4. 48
      src/Libraries/ICSharpCode.Build.Tasks/Project/MonoBasicCompilerResultsParser.cs
  5. 56
      src/Libraries/ICSharpCode.Build.Tasks/Project/MonoCSharpCompilerResultsParser.cs
  6. 9
      src/Libraries/ICSharpCode.Build.Tasks/Project/MonoCSharpCompilerTask.cs
  7. 53
      src/Libraries/ICSharpCode.Build.Tasks/Project/MonoCompiler.cs
  8. 62
      src/Libraries/ICSharpCode.Build.Tasks/Project/MonoCompilerTask.cs
  9. 2
      src/Libraries/ICSharpCode.Build.Tasks/Project/MonoToolLocationHelper.cs
  10. 2
      src/Libraries/ICSharpCode.Build.Tasks/Test/MockMbas.cs
  11. 2
      src/Libraries/ICSharpCode.Build.Tasks/Test/MockMonoCSharpCompilerTask.cs

2
src/Libraries/ICSharpCode.Build.Tasks/Project/ICSharpCode.Build.Tasks.csproj

@ -40,8 +40,6 @@ @@ -40,8 +40,6 @@
<Compile Include="Mcs.cs" />
<Compile Include="MonoCompilerTask.cs" />
<Compile Include="CompilerCommandLineArguments.cs" />
<Compile Include="MonoCompiler.cs" />
<Compile Include="ICompilerResultsParser.cs" />
<Compile Include="MonoCSharpCompilerResultsParser.cs" />
<Compile Include="Gmcs.cs" />
<None Include="SharpDevelop.Build.Mono.Gmcs.targets">

17
src/Libraries/ICSharpCode.Build.Tasks/Project/ICompilerResultsParser.cs

@ -1,17 +0,0 @@ @@ -1,17 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.CodeDom.Compiler;
namespace ICSharpCode.Build.Tasks
{
public interface ICompilerResultsParser
{
CompilerResults Parse(TempFileCollection tempFiles, string outputFileName, string errorFileName);
}
}

17
src/Libraries/ICSharpCode.Build.Tasks/Project/Mbas.cs

@ -25,6 +25,8 @@ namespace ICSharpCode.Build.Tasks @@ -25,6 +25,8 @@ namespace ICSharpCode.Build.Tasks
bool removeIntegerChecks;
string rootNamespace;
MonoBasicCompilerResultsParser parser = new MonoBasicCompilerResultsParser();
public ITaskItem[] Imports {
get {
return imports;
@ -88,10 +90,7 @@ namespace ICSharpCode.Build.Tasks @@ -88,10 +90,7 @@ namespace ICSharpCode.Build.Tasks
}
}
/// <summary>
/// Command line arguments that will be passed to the compiler.
/// </summary>
protected override string GenerateCommandLineArguments()
protected override string GenerateResponseFileCommands()
{
CompilerCommandLineArguments args = new CompilerCommandLineArguments();
@ -123,11 +122,6 @@ namespace ICSharpCode.Build.Tasks @@ -123,11 +122,6 @@ namespace ICSharpCode.Build.Tasks
return args.ToString();
}
protected override ICompilerResultsParser GetCompilerResultsParser()
{
return new MonoBasicCompilerResultsParser();
}
protected override string ToolName {
get {
return "Mbas.exe";
@ -138,5 +132,10 @@ namespace ICSharpCode.Build.Tasks @@ -138,5 +132,10 @@ namespace ICSharpCode.Build.Tasks
{
return MonoToolLocationHelper.GetPathToTool(ToolName);
}
protected override CompilerError ParseLine(string line)
{
return parser.ParseLine(line);
}
}
}

48
src/Libraries/ICSharpCode.Build.Tasks/Project/MonoBasicCompilerResultsParser.cs

@ -13,7 +13,7 @@ using System.Text.RegularExpressions; @@ -13,7 +13,7 @@ using System.Text.RegularExpressions;
namespace ICSharpCode.Build.Tasks
{
public class MonoBasicCompilerResultsParser : ICompilerResultsParser
public class MonoBasicCompilerResultsParser
{
public const string NormalErrorPattern = @"(?<file>.*)\((?<line>\d+),(?<column>\d+)\)\s+(?<error>\w+)\s+(?<number>[\d\w]+):\s+(?<message>.*)";
@ -23,43 +23,21 @@ namespace ICSharpCode.Build.Tasks @@ -23,43 +23,21 @@ namespace ICSharpCode.Build.Tasks
{
}
public CompilerResults Parse(TempFileCollection tempFiles, string outputFileName, string errorFileName)
public CompilerError ParseLine(string line)
{
CompilerResults results = new CompilerResults(tempFiles);
StringBuilder compilerOutput = new StringBuilder();
StreamReader resultsReader = File.OpenText(outputFileName);
while (true) {
string curLine = resultsReader.ReadLine();
compilerOutput.Append(curLine);
compilerOutput.Append('\n');
if (curLine == null) {
break;
}
curLine = curLine.Trim();
if (curLine.Length == 0) {
continue;
}
// try to match standard mono errors
Match match = normalError.Match(line);
if (match.Success) {
CompilerError error = new CompilerError();
// try to match standard mono errors
Match match = normalError.Match(curLine);
if (match.Success) {
error.Column = Int32.Parse(match.Result("${column}"));
error.Line = Int32.Parse(match.Result("${line}"));
error.FileName = Path.GetFullPath(match.Result("${file}"));
error.IsWarning = match.Result("${error}") == "warning";
error.ErrorNumber = match.Result("${number}");
error.ErrorText = match.Result("${message}");
results.Errors.Add(error);
}
error.Column = Int32.Parse(match.Result("${column}"));
error.Line = Int32.Parse(match.Result("${line}"));
error.FileName = Path.GetFullPath(match.Result("${file}"));
error.IsWarning = match.Result("${error}") == "warning";
error.ErrorNumber = match.Result("${number}");
error.ErrorText = match.Result("${message}");
return error;
}
resultsReader.Close();
return results;
return null;
}
}
}

56
src/Libraries/ICSharpCode.Build.Tasks/Project/MonoCSharpCompilerResultsParser.cs

@ -13,7 +13,7 @@ using System.Text.RegularExpressions; @@ -13,7 +13,7 @@ using System.Text.RegularExpressions;
namespace ICSharpCode.Build.Tasks
{
public class MonoCSharpCompilerResultsParser : ICompilerResultsParser
public class MonoCSharpCompilerResultsParser
{
public const string NormalErrorPattern = @"(?<file>.*)\((?<line>\d+),(?<column>\d+)\):\s+(?<error>\w+)\s+(?<number>[\d\w]+):\s+(?<message>.*)";
public const string GeneralErrorPattern = @"(?<error>.+?)\s+(?<number>[\d\w]+?):\s+(?<message>.*)";
@ -25,52 +25,30 @@ namespace ICSharpCode.Build.Tasks @@ -25,52 +25,30 @@ namespace ICSharpCode.Build.Tasks
{
}
public CompilerResults Parse(TempFileCollection tempFiles, string outputFileName, string errorFileName)
public CompilerError ParseLine(string line)
{
CompilerResults results = new CompilerResults(tempFiles);
StringBuilder compilerOutput = new StringBuilder();
StreamReader resultsReader = File.OpenText(errorFileName);
while (true) {
string curLine = resultsReader.ReadLine();
compilerOutput.Append(curLine);
compilerOutput.Append('\n');
if (curLine == null) {
break;
}
curLine = curLine.Trim();
if (curLine.Length == 0) {
continue;
}
// try to match standard mono errors
Match match = normalError.Match(line);
if (match.Success) {
CompilerError error = new CompilerError();
// try to match standard mono errors
Match match = normalError.Match(curLine);
error.Column = Int32.Parse(match.Result("${column}"));
error.Line = Int32.Parse(match.Result("${line}"));
error.FileName = Path.GetFullPath(match.Result("${file}"));
error.IsWarning = match.Result("${error}") == "warning";
error.ErrorNumber = match.Result("${number}");
error.ErrorText = match.Result("${message}");
return error;
} else {
match = generalError.Match(line);
if (match.Success) {
error.Column = Int32.Parse(match.Result("${column}"));
error.Line = Int32.Parse(match.Result("${line}"));
error.FileName = Path.GetFullPath(match.Result("${file}"));
CompilerError error = new CompilerError();
error.IsWarning = match.Result("${error}") == "warning";
error.ErrorNumber = match.Result("${number}");
error.ErrorText = match.Result("${message}");
results.Errors.Add(error);
} else {
match = generalError.Match(curLine);
if (match.Success) {
error.IsWarning = match.Result("${error}") == "warning";
error.ErrorNumber = match.Result("${number}");
error.ErrorText = match.Result("${message}");
results.Errors.Add(error);
}
return error;
}
}
resultsReader.Close();
return results;
return null;
}
}
}

9
src/Libraries/ICSharpCode.Build.Tasks/Project/MonoCSharpCompilerTask.cs

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
// </file>
using System;
using System.CodeDom.Compiler;
namespace ICSharpCode.Build.Tasks
{
@ -25,6 +26,8 @@ namespace ICSharpCode.Build.Tasks @@ -25,6 +26,8 @@ namespace ICSharpCode.Build.Tasks
string win32Icon;
string win32Resource;
MonoCSharpCompilerResultsParser parser = new MonoCSharpCompilerResultsParser();
public bool CheckForOverflowUnderflow {
get {
return checkForOverflowUnderflow;
@ -116,7 +119,7 @@ namespace ICSharpCode.Build.Tasks @@ -116,7 +119,7 @@ namespace ICSharpCode.Build.Tasks
}
}
protected override string GenerateCommandLineArguments()
protected override string GenerateResponseFileCommands()
{
CompilerCommandLineArguments args = new CompilerCommandLineArguments();
args.AppendSwitchIfTrue("-noconfig", noConfig);
@ -150,9 +153,9 @@ namespace ICSharpCode.Build.Tasks @@ -150,9 +153,9 @@ namespace ICSharpCode.Build.Tasks
return args.ToString();
}
protected override ICompilerResultsParser GetCompilerResultsParser()
protected override CompilerError ParseLine(string line)
{
return new MonoCSharpCompilerResultsParser();
return parser.ParseLine(line);
}
}
}

53
src/Libraries/ICSharpCode.Build.Tasks/Project/MonoCompiler.cs

@ -1,53 +0,0 @@ @@ -1,53 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.CodeDom.Compiler;
using System.IO;
namespace ICSharpCode.Build.Tasks
{
public class MonoCompiler
{
CompilerResults results;
public MonoCompiler()
{
}
public int Run(string compiler, string args, ICompilerResultsParser parser)
{
string responseFileName = Path.GetTempFileName();
using (StreamWriter writer = new StreamWriter(responseFileName)) {
writer.Write(args);
}
//string outstr = String.Concat(compilerFileName, compilerparameters.NoConfig ? " /noconfig" : String.Empty, " \"@", responseFileName, "\"");
string outputFileName = String.Empty;
string errorFileName = String.Empty;
TempFileCollection tempFiles = new TempFileCollection();
string command = String.Concat(compiler, " \"@", responseFileName, "\"");
int returnValue = Executor.ExecWaitWithCapture(command, tempFiles, ref outputFileName, ref errorFileName);
results = parser.Parse(tempFiles, outputFileName, errorFileName);
File.Delete(responseFileName);
File.Delete(outputFileName);
File.Delete(errorFileName);
return returnValue;
}
public CompilerResults Results {
get {
return results;
}
}
}
}

62
src/Libraries/ICSharpCode.Build.Tasks/Project/MonoCompilerTask.cs

@ -39,8 +39,7 @@ namespace ICSharpCode.Build.Tasks @@ -39,8 +39,7 @@ namespace ICSharpCode.Build.Tasks
ITaskItem[] sources;
string targetType;
bool treatWarningsAsErrors;
int warningLevel = DefaultWarningLevel;
bool warningLevelSet;
int? warningLevel;
public bool AllowUnsafeBlocks {
get {
@ -224,39 +223,14 @@ namespace ICSharpCode.Build.Tasks @@ -224,39 +223,14 @@ namespace ICSharpCode.Build.Tasks
public int WarningLevel {
get {
return warningLevel;
if (warningLevel.HasValue) {
return warningLevel.Value;
}
return DefaultWarningLevel;
}
set {
warningLevel = value;
warningLevelSet = true;
}
}
public override bool Execute()
{
string args = GenerateCommandLineArguments();
ToolPath = GenerateFullPathToTool();
LogToolCommand(String.Concat(ToolPath, " ", args));
MonoCompiler compiler = new MonoCompiler();
int returnValue = compiler.Run(ToolPath, args, GetCompilerResultsParser());
int errorCount = 0;
foreach (CompilerError error in compiler.Results.Errors) {
if (error.IsWarning) {
Log.LogWarning("warning", error.ErrorNumber, null, error.FileName, error.Line, error.Column, error.Line, error.Column, error.ErrorText);
} else {
errorCount++;
Log.LogError("error", error.ErrorNumber, null, error.FileName, error.Line, error.Column, error.Line, error.Column, error.ErrorText);
}
}
if (returnValue != 0 && errorCount == 0) {
Log.LogError(String.Concat("Failed to execute compiler: ", returnValue, ": ", ToolPath));
}
return errorCount == 0;
}
/// <summary>
@ -264,24 +238,36 @@ namespace ICSharpCode.Build.Tasks @@ -264,24 +238,36 @@ namespace ICSharpCode.Build.Tasks
/// </summary>
protected bool IsWarningLevelSet {
get {
return warningLevelSet;
return warningLevel.HasValue;
}
}
/// <summary>
/// Command line arguments that will be passed to the compiler.
/// Returns a compiler error from the standard output or standard
/// error line.
/// </summary>
protected virtual string GenerateCommandLineArguments()
protected virtual CompilerError ParseLine(string line)
{
return String.Empty;
return null;
}
/// <summary>
/// Gets the parser that handles the compiler output.
/// Each line of output, from either standard output or standard error
/// is parsed and any compiler errors are logged. If the line cannot
/// be parsed it is logged using the specified message importance.
/// </summary>
protected virtual ICompilerResultsParser GetCompilerResultsParser()
protected override void LogEventsFromTextOutput(string singleLine, MessageImportance messageImportance)
{
return null;
CompilerError error = ParseLine(singleLine);
if (error != null) {
if (error.IsWarning) {
Log.LogWarning("warning", error.ErrorNumber, null, error.FileName, error.Line, error.Column, error.Line, error.Column, error.ErrorText);
} else {
Log.LogError("error", error.ErrorNumber, null, error.FileName, error.Line, error.Column, error.Line, error.Column, error.ErrorText);
}
} else {
Log.LogMessage(messageImportance, singleLine);
}
}
}
}

2
src/Libraries/ICSharpCode.Build.Tasks/Project/MonoToolLocationHelper.cs

@ -44,7 +44,7 @@ namespace ICSharpCode.Build.Tasks @@ -44,7 +44,7 @@ namespace ICSharpCode.Build.Tasks
if (sdkPath.Length > 0) {
string toolPath = Path.Combine(sdkPath, toolName);
if (System.IO.File.Exists(toolPath)) {
return String.Concat("\"", toolPath, "\"");
return toolPath;
}
}

2
src/Libraries/ICSharpCode.Build.Tasks/Test/MockMbas.cs

@ -22,7 +22,7 @@ namespace ICSharpCode.Build.Tasks.Tests @@ -22,7 +22,7 @@ namespace ICSharpCode.Build.Tasks.Tests
/// </summary>
public string GetCommandLine()
{
return base.GenerateCommandLineArguments();
return base.GenerateResponseFileCommands();
}
}
}

2
src/Libraries/ICSharpCode.Build.Tasks/Test/MockMonoCSharpCompilerTask.cs

@ -22,7 +22,7 @@ namespace ICSharpCode.Build.Tasks.Tests @@ -22,7 +22,7 @@ namespace ICSharpCode.Build.Tasks.Tests
/// </summary>
public string GetCommandLine()
{
return base.GenerateCommandLineArguments();
return base.GenerateResponseFileCommands();
}
protected override string ToolName {

Loading…
Cancel
Save