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. 19
      src/Libraries/ICSharpCode.Build.Tasks/Project/Mbas.cs
  4. 2
      src/Libraries/ICSharpCode.Build.Tasks/Project/Mcs.cs
  5. 48
      src/Libraries/ICSharpCode.Build.Tasks/Project/MonoBasicCompilerResultsParser.cs
  6. 56
      src/Libraries/ICSharpCode.Build.Tasks/Project/MonoCSharpCompilerResultsParser.cs
  7. 9
      src/Libraries/ICSharpCode.Build.Tasks/Project/MonoCSharpCompilerTask.cs
  8. 53
      src/Libraries/ICSharpCode.Build.Tasks/Project/MonoCompiler.cs
  9. 64
      src/Libraries/ICSharpCode.Build.Tasks/Project/MonoCompilerTask.cs
  10. 2
      src/Libraries/ICSharpCode.Build.Tasks/Project/MonoToolLocationHelper.cs
  11. 2
      src/Libraries/ICSharpCode.Build.Tasks/Test/MockMbas.cs
  12. 2
      src/Libraries/ICSharpCode.Build.Tasks/Test/MockMonoCSharpCompilerTask.cs

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

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

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

@ -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);
}
}

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

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

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

@ -22,7 +22,7 @@ namespace ICSharpCode.Build.Tasks
} }
protected override string GenerateFullPathToTool() protected override string GenerateFullPathToTool()
{ {
return MonoToolLocationHelper.GetPathToTool(ToolName); return MonoToolLocationHelper.GetPathToTool(ToolName);
} }
} }

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

@ -13,7 +13,7 @@ using System.Text.RegularExpressions;
namespace ICSharpCode.Build.Tasks 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>.*)"; 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
{ {
} }
public CompilerResults Parse(TempFileCollection tempFiles, string outputFileName, string errorFileName) public CompilerError ParseLine(string line)
{ {
CompilerResults results = new CompilerResults(tempFiles); // try to match standard mono errors
Match match = normalError.Match(line);
StringBuilder compilerOutput = new StringBuilder(); if (match.Success) {
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;
}
CompilerError error = new CompilerError(); CompilerError error = new CompilerError();
error.Column = Int32.Parse(match.Result("${column}"));
// try to match standard mono errors error.Line = Int32.Parse(match.Result("${line}"));
Match match = normalError.Match(curLine); error.FileName = Path.GetFullPath(match.Result("${file}"));
if (match.Success) { error.IsWarning = match.Result("${error}") == "warning";
error.Column = Int32.Parse(match.Result("${column}")); error.ErrorNumber = match.Result("${number}");
error.Line = Int32.Parse(match.Result("${line}")); error.ErrorText = match.Result("${message}");
error.FileName = Path.GetFullPath(match.Result("${file}")); return error;
error.IsWarning = match.Result("${error}") == "warning";
error.ErrorNumber = match.Result("${number}");
error.ErrorText = match.Result("${message}");
results.Errors.Add(error);
}
} }
resultsReader.Close(); return null;
return results;
} }
} }
} }

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

@ -13,7 +13,7 @@ using System.Text.RegularExpressions;
namespace ICSharpCode.Build.Tasks 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 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>.*)"; public const string GeneralErrorPattern = @"(?<error>.+?)\s+(?<number>[\d\w]+?):\s+(?<message>.*)";
@ -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); // try to match standard mono errors
Match match = normalError.Match(line);
StringBuilder compilerOutput = new StringBuilder(); if (match.Success) {
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;
}
CompilerError error = new CompilerError(); CompilerError error = new CompilerError();
error.Column = Int32.Parse(match.Result("${column}"));
// try to match standard mono errors error.Line = Int32.Parse(match.Result("${line}"));
Match match = normalError.Match(curLine); 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) { if (match.Success) {
error.Column = Int32.Parse(match.Result("${column}")); CompilerError error = new CompilerError();
error.Line = Int32.Parse(match.Result("${line}"));
error.FileName = Path.GetFullPath(match.Result("${file}"));
error.IsWarning = match.Result("${error}") == "warning"; error.IsWarning = match.Result("${error}") == "warning";
error.ErrorNumber = match.Result("${number}"); error.ErrorNumber = match.Result("${number}");
error.ErrorText = match.Result("${message}"); error.ErrorText = match.Result("${message}");
return error;
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);
}
} }
} }
resultsReader.Close(); return null;
return results;
} }
} }
} }

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

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

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

@ -39,8 +39,7 @@ namespace ICSharpCode.Build.Tasks
ITaskItem[] sources; ITaskItem[] sources;
string targetType; string targetType;
bool treatWarningsAsErrors; bool treatWarningsAsErrors;
int warningLevel = DefaultWarningLevel; int? warningLevel;
bool warningLevelSet;
public bool AllowUnsafeBlocks { public bool AllowUnsafeBlocks {
get { get {
@ -224,39 +223,14 @@ namespace ICSharpCode.Build.Tasks
public int WarningLevel { public int WarningLevel {
get { get {
return warningLevel; if (warningLevel.HasValue) {
return warningLevel.Value;
}
return DefaultWarningLevel;
} }
set { set {
warningLevel = value; 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> /// <summary>
@ -264,24 +238,36 @@ namespace ICSharpCode.Build.Tasks
/// </summary> /// </summary>
protected bool IsWarningLevelSet { protected bool IsWarningLevelSet {
get { get {
return warningLevelSet; return warningLevel.HasValue;
} }
} }
/// <summary> /// <summary>
/// Command line arguments that will be passed to the compiler. /// Returns a compiler error from the standard output or standard
/// error line.
/// </summary> /// </summary>
protected virtual string GenerateCommandLineArguments() protected virtual CompilerError ParseLine(string line)
{ {
return String.Empty; return null;
} }
/// <summary> /// <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> /// </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
if (sdkPath.Length > 0) { if (sdkPath.Length > 0) {
string toolPath = Path.Combine(sdkPath, toolName); string toolPath = Path.Combine(sdkPath, toolName);
if (System.IO.File.Exists(toolPath)) { 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
/// </summary> /// </summary>
public string GetCommandLine() 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
/// </summary> /// </summary>
public string GetCommandLine() public string GetCommandLine()
{ {
return base.GenerateCommandLineArguments(); return base.GenerateResponseFileCommands();
} }
protected override string ToolName { protected override string ToolName {

Loading…
Cancel
Save