Browse Source

An error message is now displayed when trying to compile a Python application when no main file is specified.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4065 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 16 years ago
parent
commit
4fa1e2e656
  1. 2
      src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Python.Build.Tasks.csproj
  2. 12
      src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/PythonCompiler.cs
  3. 18
      src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/PythonCompilerException.cs
  4. 2
      src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/PythonCompilerTask.cs
  5. 25
      src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/Resources.cs
  6. 8
      src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/IOErrorTestFixture.cs
  7. 56
      src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/MissingMainEntryPointTestFixture.cs
  8. 2
      src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/Python.Build.Tasks.Tests.csproj
  9. 46
      src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/PythonCompilerTests.cs

2
src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Python.Build.Tasks.csproj

@ -65,8 +65,10 @@ @@ -65,8 +65,10 @@
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Src\IPythonCompiler.cs" />
<Compile Include="Src\PythonCompiler.cs" />
<Compile Include="Src\PythonCompilerException.cs" />
<Compile Include="Src\PythonCompilerTask.cs" />
<Compile Include="Src\ResourceFile.cs" />
<Compile Include="Src\Resources.cs" />
<None Include="SharpDevelop.Build.Python.targets">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>

12
src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/PythonCompiler.cs

@ -92,6 +92,8 @@ namespace ICSharpCode.Python.Build.Tasks @@ -92,6 +92,8 @@ namespace ICSharpCode.Python.Build.Tasks
/// </summary>
public void Compile()
{
VerifyParameters();
// Compile the source files to a dll first.
ScriptEngine engine = IronPython.Hosting.Python.CreateEngine();
PythonDictionary dictionary = new PythonDictionary();
@ -113,6 +115,16 @@ namespace ICSharpCode.Python.Build.Tasks @@ -113,6 +115,16 @@ namespace ICSharpCode.Python.Build.Tasks
}
}
/// <summary>
/// Verifies the compiler parameters that have been set correctly.
/// </summary>
public void VerifyParameters()
{
if ((mainFile == null) && (targetKind != PEFileKinds.Dll)) {
throw new PythonCompilerException(Resources.NoMainFileSpecified);
}
}
public void Dispose()
{
}

18
src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/PythonCompilerException.cs

@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
// <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;
namespace ICSharpCode.Python.Build.Tasks
{
public class PythonCompilerException : ApplicationException
{
public PythonCompilerException(string message) : base(message)
{
}
}
}

2
src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/PythonCompilerTask.cs

@ -135,6 +135,8 @@ namespace ICSharpCode.Python.Build.Tasks @@ -135,6 +135,8 @@ namespace ICSharpCode.Python.Build.Tasks
LogSyntaxError(ex);
} catch (IOException ex) {
LogError(ex.Message);
} catch (PythonCompilerException ex) {
LogError(ex.Message);
}
}
return false;

25
src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/Resources.cs

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
// <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;
namespace ICSharpCode.Python.Build.Tasks
{
public class Resources
{
Resources()
{
}
/// <summary>
/// No main file specified when trying to compile an application
/// </summary>
public static string NoMainFileSpecified {
get { return "No main file specified."; }
}
}
}

8
src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/IOErrorTestFixture.cs

@ -41,7 +41,7 @@ namespace Python.Build.Tasks.Tests @@ -41,7 +41,7 @@ namespace Python.Build.Tasks.Tests
TaskItem sourceFile = new TaskItem(@"D:\Projects\MyProject\test.py");
compiler.Sources = new ITaskItem[] {sourceFile};
mockCompiler.ThrowExceptionAtCompile = PythonOps.IOError("Could not find main file test.py");;
mockCompiler.ThrowExceptionAtCompile = PythonOps.IOError("Could not find main file test.py");
success = compiler.Execute();
}
@ -57,11 +57,5 @@ namespace Python.Build.Tasks.Tests @@ -57,11 +57,5 @@ namespace Python.Build.Tasks.Tests
{
Assert.AreEqual("Could not find main file test.py", compiler.LoggedErrorMessage);
}
// [Test]
// public void IsErrorCodeLogged()
// {
// Assert.AreEqual("1000", compiler.LoggedErrorCode);
// }
}
}

56
src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/MissingMainEntryPointTestFixture.cs

@ -0,0 +1,56 @@ @@ -0,0 +1,56 @@
// <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.Reflection.Emit;
using ICSharpCode.Python.Build.Tasks;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using NUnit.Framework;
namespace Python.Build.Tasks.Tests
{
/// <summary>
/// Tests that an error is reported when the mainFile is missing and we are trying to compile
/// an executable.
/// </summary>
[TestFixture]
public class MissingMainEntryPointTestFixture
{
MockPythonCompiler mockCompiler;
DummyPythonCompilerTask compiler;
bool success;
[SetUp]
public void Init()
{
mockCompiler = new MockPythonCompiler();
compiler = new DummyPythonCompilerTask(mockCompiler, @"C:\Projects\MyProject");
compiler.TargetType = "Exe";
compiler.OutputAssembly = "test.exe";
TaskItem sourceFile = new TaskItem(@"D:\Projects\MyProject\test.py");
compiler.Sources = new ITaskItem[] {sourceFile};
mockCompiler.ThrowExceptionAtCompile = new PythonCompilerException("Missing main file.");
success = compiler.Execute();
}
[Test]
public void ExecuteFailed()
{
Assert.IsFalse(success);
}
[Test]
public void IsExceptionMessageLogged()
{
Assert.AreEqual("Missing main file.", compiler.LoggedErrorMessage);
}
}
}

2
src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/Python.Build.Tasks.Tests.csproj

@ -68,9 +68,11 @@ @@ -68,9 +68,11 @@
<Compile Include="IncludeDebugInfoTestFixture.cs" />
<Compile Include="IOErrorTestFixture.cs" />
<Compile Include="MainEntryPointTestFixture.cs" />
<Compile Include="MissingMainEntryPointTestFixture.cs" />
<Compile Include="MockPythonCompiler.cs" />
<Compile Include="CompileSingleSourceFileTestFixture.cs" />
<Compile Include="PlatformTestFixture.cs" />
<Compile Include="PythonCompilerTests.cs" />
<Compile Include="RelativeReferenceTestFixture.cs" />
<Compile Include="RelativeResourceFileTestFixture.cs" />
<Compile Include="SyntaxErrorTestFixture.cs" />

46
src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/PythonCompilerTests.cs

@ -0,0 +1,46 @@ @@ -0,0 +1,46 @@
// <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.Reflection.Emit;
using ICSharpCode.Python.Build.Tasks;
using NUnit.Framework;
namespace Python.Build.Tasks.Tests
{
[TestFixture]
public class PythonCompilerTests
{
[Test]
public void NoMainFileSpecifiedForWindowsApplication()
{
try {
PythonCompiler compiler = new PythonCompiler();
compiler.TargetKind = PEFileKinds.WindowApplication;
compiler.OutputAssembly = "test.exe";
compiler.SourceFiles = new string[0];
compiler.MainFile = null;
compiler.Compile();
Assert.Fail("Expected PythonCompilerException.");
} catch (PythonCompilerException ex) {
Assert.AreEqual(Resources.NoMainFileSpecified, ex.Message);
}
}
[Test]
public void NoMainSpecifiedForLibraryThrowsNoError()
{
PythonCompiler compiler = new PythonCompiler();
compiler.TargetKind = PEFileKinds.Dll;
compiler.OutputAssembly = "test.dll";
compiler.SourceFiles = new string[0];
compiler.MainFile = null;
compiler.VerifyParameters();
}
}
}
Loading…
Cancel
Save