Verify coreclr absence/presence depending on app type during dotnet build.
This commit is contained in:
Bryan 2016-04-29 15:54:47 -07:00 committed by Bryan Thornbury
parent 4f1dbeba0e
commit a25e92208e
12 changed files with 167 additions and 3 deletions

View file

@ -0,0 +1,12 @@
using System;
namespace PortableApp
{
public static class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
}

View file

@ -0,0 +1,17 @@
{
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-*"
}
}
}
}
}

View file

@ -0,0 +1,26 @@
{
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-*"
}
}
}
},
"runtimes": {
"win7-x64": {},
"win7-x86": {},
"osx.10.10-x64": {},
"osx.10.11-x64": {},
"ubuntu.14.04-x64": {},
"centos.7-x64": {},
"rhel.7.2-x64": {},
"debian.8-x64": {}
}
}

View file

@ -0,0 +1,12 @@
using System;
namespace StandaloneApp
{
public static class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
}

View file

@ -0,0 +1,22 @@
{
"compilationOptions": {
"emitEntryPoint": true
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": "1.0.0-rc2-*"
}
}
},
"runtimes": {
"win7-x64": {},
"win7-x86": {},
"osx.10.10-x64": {},
"osx.10.11-x64": {},
"ubuntu.14.04-x64": {},
"centos.7-x64": {},
"rhel.7.2-x64": {},
"debian.8-x64": {}
}
}

View file

@ -0,0 +1,25 @@
{
"compilationOptions": {
"emitEntryPoint": true
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-*"
}
}
}
},
"runtimes": {
"win7-x64": {},
"win7-x86": {},
"osx.10.10-x64": {},
"osx.10.11-x64": {},
"ubuntu.14.04-x64": {},
"centos.7-x64": {},
"rhel.7.2-x64": {},
"debian.8-x64": {}
}
}

View file

@ -43,5 +43,12 @@ namespace Microsoft.DotNet.Cli.Utils
(CurrentPlatform == Platform.Windows ? "hostfxr" : "libhostfxr") + DynamicLibSuffix
};
public static readonly string[] LibCoreClrBinaryNames = new string[]
{
"coreclr.dll",
"libcoreclr.so",
"libcoreclr.dylib"
};
}
}

View file

@ -56,6 +56,23 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
ExportRuntimeAssets();
}
private void VerifyCoreclrPresenceInPackageGraph()
{
var isCoreclrPresent = _exporter
.GetAllExports()
.SelectMany(e => e.NativeLibraryGroups)
.SelectMany(g => g.Assets)
.Select(a => a.FileName)
.Where(f => Constants.LibCoreClrBinaryNames.Contains(f))
.Any();
// coreclr should be present for standalone apps
if (! isCoreclrPresent)
{
throw new InvalidOperationException("Expected coreclr library not found in package graph. Please try running restore again.");
}
}
private void ExportRuntimeAssets()
{
if (_context.TargetFramework.IsDesktop())
@ -77,13 +94,15 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
}
private void MakeCompilationOutputRunnableForCoreCLR()
{
{
WriteDepsFileAndCopyProjectDependencies(_exporter);
var emitEntryPoint = _compilerOptions.EmitEntryPoint ?? false;
if (emitEntryPoint && !string.IsNullOrEmpty(_context.RuntimeIdentifier))
if (emitEntryPoint && !_context.IsPortable)
{
// TODO: Pick a host based on the RID
VerifyCoreclrPresenceInPackageGraph();
CoreHost.CopyTo(_runtimeOutputPath, _compilerOptions.OutputName + Constants.ExeSuffix);
}
}

View file

@ -129,7 +129,7 @@ namespace Microsoft.DotNet.Tools.Build
}
catch (Exception e)
{
throw new Exception($"Failed to make the following project runnable: {graphNode.ProjectContext.GetDisplayName()}", e);
throw new Exception($"Failed to make the following project runnable: {graphNode.ProjectContext.GetDisplayName()} reason: {e.Message}", e);
}
}

View file

@ -307,6 +307,30 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
}
}
[Fact]
private void StandaloneApp_WithoutCoreclrDll_Fails()
{
// Convert a Portable App to Standalone to simulate the customer scenario
var testInstance = TestAssetsManager.CreateTestInstance("DependencyChangeTest")
.WithLockFiles();
// Convert the portable test project to standalone by removing "type": "platform" and adding rids
var originalTestProject = Path.Combine(testInstance.TestRoot, "PortableApp_Standalone", "project.json");
var modifiedTestProject = Path.Combine(testInstance.TestRoot, "PortableApp_Standalone", "project.json.modified");
// Simulate a user editting the project.json
File.Delete(originalTestProject);
File.Copy(modifiedTestProject, originalTestProject);
var buildResult = new BuildCommand(originalTestProject, framework: DefaultFramework)
.ExecuteWithCapturedOutput();
buildResult.Should().Fail();
buildResult.StdErr.Should().Contain("Expected coreclr library not found in package graph. Please try running restore again.");
}
private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir)
{
// copy all the files to temp dir