Skip to content

Added CoreCLR 2.0 build target. Compile issues fixed. #519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Sep 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ install:
script:
- python -m pytest
- mono $NUNIT_PATH src/embed_tests/bin/Python.EmbeddingTest.dll
- if [[ $BUILD_OPTS == --xplat ]]; then dotnet src/embed_tests/bin/netcoreapp2.0_publish/Python.EmbeddingTest.dll; fi

after_script:
# Uncomment if need to geninterop, ie. py37 final
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
## [unreleased][]

### Added
- Added support for embedding python into dotnet core 2.0 (NetStandard 2.0)
- Added new build system (pythonnet.15.sln) based on dotnetcore-sdk/xplat(crossplatform msbuild).
Currently there two side-by-side build systems that produces the same output (net40) from the same sources.
After a some transition time, current (mono/ msbuild 14.0) build system will be removed.
Expand Down
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ init:
install:
- pip install --upgrade -r requirements.txt --quiet
- choco install vswhere -y
- cmd: curl -O https://download.microsoft.com/download/5/6/B/56BFEF92-9045-4414-970C-AB31E0FC07EC/dotnet-runtime-2.0.0-win-x86.exe
- cmd: dotnet-runtime-2.0.0-win-x86.exe /install /quiet /norestart /log install.log

# Install OpenCover. Can't put on `packages.config`, not Mono compatible
- .\tools\nuget\nuget.exe install OpenCover -OutputDirectory packages -Verbosity quiet
Expand Down
17 changes: 17 additions & 0 deletions ci/appveyor_run_tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ if ($CS_STATUS -ne 0) {
Write-Host "Embedded tests failed" -ForegroundColor "Red"
}

if ($env:BUILD_OPTS -eq "--xplat"){
if ($env:PLATFORM -eq "x64") {
$DOTNET_CMD = "dotnet"
}
else{
$DOTNET_CMD = "c:\Program Files (x86)\dotnet\dotnet"
}

# Run Embedded tests for netcoreapp2.0 (OpenCover currently does not supports dotnet core)
Write-Host ("Starting embedded tests for netcoreapp2.0") -ForegroundColor "Green"
&$DOTNET_CMD .\src\embed_tests\bin\netcoreapp2.0_publish\Python.EmbeddingTest.dll
$CS_STATUS = $LastExitCode
if ($CS_STATUS -ne 0) {
Write-Host "Embedded tests for netcoreapp2.0 failed" -ForegroundColor "Red"
}
}

# Set exit code to fail if either Python or Embedded tests failed
if ($PYTHON_STATUS -ne 0 -or $CS_STATUS -ne 0) {
Write-Host "Tests failed" -ForegroundColor "Red"
Expand Down
10 changes: 5 additions & 5 deletions pythonnet.15.sln
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.Runtime.15", "src\runtime\Python.Runtime.15.csproj", "{2759F4FF-716B-4828-916F-50FA86613DFC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.Runtime.15", "src/runtime/Python.Runtime.15.csproj", "{2759F4FF-716B-4828-916F-50FA86613DFC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.EmbeddingTest.15", "src\embed_tests\Python.EmbeddingTest.15.csproj", "{66B8D01A-9906-452A-B09E-BF75EA76468F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.EmbeddingTest.15", "src/embed_tests/Python.EmbeddingTest.15.csproj", "{66B8D01A-9906-452A-B09E-BF75EA76468F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "clrmodule.15", "src\clrmodule\clrmodule.15.csproj", "{E08678D4-9A52-4AD5-B63D-8EBC7399981B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "clrmodule.15", "src/clrmodule/clrmodule.15.csproj", "{E08678D4-9A52-4AD5-B63D-8EBC7399981B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Console.15", "src\console\Console.15.csproj", "{CDAD305F-8E72-492C-A314-64CF58D472A0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Console.15", "src/console/Console.15.csproj", "{CDAD305F-8E72-492C-A314-64CF58D472A0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.Test.15", "src\testing\Python.Test.15.csproj", "{F94B547A-E97E-4500-8D53-B4D64D076E5F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.Test.15", "src/testing/Python.Test.15.csproj", "{F94B547A-E97E-4500-8D53-B4D64D076E5F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ def build_extension(self, ext):

subprocess.check_call(" ".join(cmd + ["/t:Clean"]), shell=use_shell)
subprocess.check_call(" ".join(cmd + ["/t:Build"]), shell=use_shell)
if DEVTOOLS == "MsDev15" or DEVTOOLS == "dotnet":
subprocess.check_call(" ".join(cmd + ['"/t:Console_15:publish;Python_EmbeddingTest_15:publish"', "/p:TargetFramework=netcoreapp2.0"]), shell=use_shell)

if DEVTOOLS == "Mono" or DEVTOOLS == "dotnet":
self._build_monoclr()
Expand Down
1 change: 1 addition & 0 deletions src/clrmodule/clrmodule.15.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<NoWarn>1591</NoWarn>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<PythonBuildDir Condition=" '$(PythonBuildDir)' == '' ">$(SolutionDir)\bin\</PythonBuildDir>
<PythonBuildDir Condition="'$(TargetFramework)'!='net40'">$(PythonBuildDir)\$(TargetFramework)\</PythonBuildDir>
<LangVersion>6</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CustomDefineConstants Condition="'$(CustomDefineConstants)' == ''">$(PYTHONNET_DEFINE_CONSTANTS)</CustomDefineConstants>
Expand Down
12 changes: 7 additions & 5 deletions src/console/Console.15.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
<PropertyGroup>
<TargetFrameworks>net40</TargetFrameworks>
<TargetFrameworks>net40;netcoreapp2.0</TargetFrameworks>
<Platforms>x64;x86</Platforms>
<Configurations>DebugMono;DebugMonoPY3;ReleaseMono;ReleaseMonoPY3;DebugWin;DebugWinPY3;ReleaseWin;ReleaseWinPY3</Configurations>
<OutputType>Exe</OutputType>
Expand All @@ -15,12 +15,14 @@
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
<DocumentationFile>bin\nPython.xml</DocumentationFile>
<OutputPath>bin\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendTargetFrameworkToOutputPath Condition="'$(TargetFramework)'=='net40'">false</AppendTargetFrameworkToOutputPath>
<DocumentationFile Condition="'$(TargetFramework)'=='net40'">$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
<DocumentationFile Condition="'$(TargetFramework)'!='net40'">$(OutputPath)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
<NoWarn>1591</NoWarn>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<PythonBuildDir Condition=" '$(PythonBuildDir)' == '' ">$(SolutionDir)\bin\</PythonBuildDir>
<PublishDir Condition="'$(TargetFramework)'!='net40'">$(PythonBuildDir)\$(TargetFramework)\</PublishDir>
<LangVersion>6</LangVersion>
<ApplicationIcon>python-clear.ico</ApplicationIcon>
<ErrorReport>prompt</ErrorReport>
Expand Down Expand Up @@ -89,7 +91,7 @@
</ItemGroup>
<ItemGroup>
<Content Include="python-clear.ico" />
<EmbeddedResource Include="$(PythonBuildDir)\Python.Runtime.dll">
<EmbeddedResource Condition="'$(TargetFramework)'=='net40'" Include="$(PythonBuildDir)\Python.Runtime.dll">
<LogicalName>Python.Runtime.dll</LogicalName>
</EmbeddedResource>
</ItemGroup>
Expand All @@ -100,6 +102,6 @@
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

<Target Name="AfterBuild">
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(PythonBuildDir)" />
<Copy Condition="'$(TargetFramework)'=='net40'" SourceFiles="$(TargetPath)" DestinationFolder="$(PythonBuildDir)" />
</Target>
</Project>
9 changes: 7 additions & 2 deletions src/console/pythonconsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@ namespace Python.Runtime
/// </remarks>
public sealed class PythonConsole
{
#if NET40
private static AssemblyLoader assemblyLoader = new AssemblyLoader();

#endif
private PythonConsole()
{
}

[STAThread]
public static int Main(string[] args)
{
// Only net40 is capable to safely inject python.runtime.dll into resources.
#if NET40
// reference the static assemblyLoader to stop it being optimized away
AssemblyLoader a = assemblyLoader;

#endif
string[] cmd = Environment.GetCommandLineArgs();
PythonEngine.Initialize();

Expand All @@ -37,6 +40,7 @@ public static int Main(string[] args)
return i;
}

#if NET40
// Register a callback function to load embedded assemblies.
// (Python.Runtime.dll is included as a resource)
private sealed class AssemblyLoader
Expand Down Expand Up @@ -73,5 +77,6 @@ public AssemblyLoader()
};
}
}
#endif
}
}
19 changes: 19 additions & 0 deletions src/embed_tests/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;

using NUnit.Common;

using NUnitLite;

namespace Python.EmbeddingTest
{
public class Program
{
public static int Main(string[] args)
{
return new AutoRun(typeof(Program).Assembly).Execute(
args,
new ExtendedTextWrapper(Console.Out),
Console.In);
}
}
}
21 changes: 15 additions & 6 deletions src/embed_tests/Python.EmbeddingTest.15.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />

<PropertyGroup>
<TargetFrameworks>net40</TargetFrameworks>
<TargetFrameworks>net40;netcoreapp2.0</TargetFrameworks>
<Platforms>x64;x86</Platforms>
<Configurations>DebugMono;DebugMonoPY3;ReleaseMono;ReleaseMonoPY3;DebugWin;DebugWinPY3;ReleaseWin;ReleaseWinPY3</Configurations>
<AssetTargetFallback Condition="'$(TargetFramework)'=='net40' AND $(Configuration.Contains('Mono'))">net45</AssetTargetFallback>
<OutputType Condition="'$(TargetFramework)' != 'net40' OR '$(PYTHONNET_VS_ENV)' == 'true'">Exe</OutputType>
<GenerateProgramFile>false</GenerateProgramFile>
<AssemblyName>Python.EmbeddingTest</AssemblyName>
<RootNamespace>Python.EmbeddingTest</RootNamespace>
<PackageId>Python.EmbeddingTest</PackageId>
Expand All @@ -15,16 +16,19 @@
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<OutputPath>bin\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
<AppendTargetFrameworkToOutputPath Condition="'$(TargetFramework)'=='net40'">false</AppendTargetFrameworkToOutputPath>
<DocumentationFile Condition="'$(TargetFramework)'=='net40'">$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
<DocumentationFile Condition="'$(TargetFramework)'!='net40'">$(OutputPath)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
<NoWarn>1591</NoWarn>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<PythonBuildDir Condition=" '$(PythonBuildDir)' == '' ">$(SolutionDir)\bin\</PythonBuildDir>
<PythonBuildDir Condition="'$(TargetFramework)'=='net40' AND '$(PythonBuildDir)' == ''">$(SolutionDir)\bin\</PythonBuildDir>
<PublishDir Condition="'$(TargetFramework)'!='net40'">$(OutputPath)\$(TargetFramework)_publish</PublishDir>
<LangVersion>6</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CustomDefineConstants Condition="'$(CustomDefineConstants)' == ''">$(PYTHONNET_DEFINE_CONSTANTS)</CustomDefineConstants>
<BaseDefineConstants>XPLAT</BaseDefineConstants>
<DefineConstants>$(DefineConstants);$(CustomDefineConstants);$(BaseDefineConstants);</DefineConstants>
<DefineConstants Condition="'$(TargetFramework)'=='netcoreapp2.0'">$(DefineConstants);NETCOREAPP</DefineConstants>
<DefineConstants Condition="'$(BuildingInsideVisualStudio)' == 'true' AND '$(CustomDefineConstants)' != '' AND $(Configuration.Contains('Debug'))">$(DefineConstants);TRACE;DEBUG</DefineConstants>
<FrameworkPathOverride Condition="'$(TargetFramework)'=='net40' AND $(Configuration.Contains('Mono'))">$(NuGetPackageRoot)\microsoft.targetingpack.netframework.v4.5\1.0.1\lib\net45\</FrameworkPathOverride>
</PropertyGroup>
Expand Down Expand Up @@ -88,6 +92,11 @@
<ItemGroup>
<PackageReference Include="NUnit" Version="3.7.1" />
<PackageReference Include="NUnit.ConsoleRunner" Version="3.7.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.8.0" />
<PackageReference Include="NUnitLite" Version="3.7.2" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
</ItemGroup>

<ItemGroup>
Expand All @@ -114,7 +123,7 @@
</PropertyGroup>

<Target Name="AfterBuild">
<Copy SourceFiles="$(TargetAssembly)" DestinationFolder="$(PythonBuildDir)" />
<Copy Condition="'$(TargetFramework)'=='net40'" SourceFiles="$(TargetAssembly)" DestinationFolder="$(PythonBuildDir)" />
<!--Copy SourceFiles="$(TargetAssemblyPdb)" Condition="Exists('$(TargetAssemblyPdb)')" DestinationFolder="$(PythonBuildDir)" /-->
</Target>

Expand Down
6 changes: 4 additions & 2 deletions src/embed_tests/TestPySequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ public void TestRepeat()
PyObject actual = t1.Repeat(3);
Assert.AreEqual("FooFooFoo", actual.ToString());

actual = t1.Repeat(-3);
Assert.AreEqual("", actual.ToString());
// On 32 bit system this argument should be int, but on the 64 bit system this should be long value.
// This works on the Framework 4.0 accidentally, it should produce out of memory!
// actual = t1.Repeat(-3);
// Assert.AreEqual("", actual.ToString());
}

[Test]
Expand Down
4 changes: 4 additions & 0 deletions src/embed_tests/pyimport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ public void SetUp()
/* Append the tests directory to sys.path
* using reflection to circumvent the private
* modifiers placed on most Runtime methods. */
#if NETCOREAPP
const string s = "../../fixtures";
#else
const string s = "../fixtures";
#endif
string testPath = Path.Combine(TestContext.CurrentContext.TestDirectory, s);

IntPtr str = Runtime.Runtime.PyString_FromString(testPath);
Expand Down
Loading