Remove Dotnet.exe from M.N.App

Sign Dotnet.exe
Cleanup after introducing apphost

Renaming RuntimeGraphGenerator as DepsProcessor
This commit is contained in:
Rama Krishnan Raghupathy 2017-03-24 13:14:07 -07:00
Родитель c2f78a394f
Коммит 60230ccc6b
14 изменённых файлов: 126 добавлений и 70 удалений

Просмотреть файл

@ -6,6 +6,7 @@
<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
<add key="cli-deps" value="https://dotnet.myget.org/F/cli-deps/api/v3/index.json" />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="corefxlab" value="https://dotnet.myget.org/F/dotnet-corefxlab/api/v3/index.json" />
</packageSources>
<disabledPackageSources>
<clear />

Просмотреть файл

@ -459,12 +459,14 @@ namespace Microsoft.DotNet.Host.Build
{
var hostVersion = c.BuildContext.Get<HostVersion>("HostVersion");
var lockedHostFxrVersion = hostVersion.LockedHostFxrVersion.ToString();
var lockedHostVersion = hostVersion.LockedHostVersion.ToString();
string currentRid = HostPackageSupportedRids[c.BuildContext.Get<string>("TargetRID")];
string framework = c.BuildContext.Get<string>("TargetFramework");
string projectJson = $@"{{
""dependencies"": {{
""Microsoft.NETCore.DotNetHostResolver"" : ""{lockedHostFxrVersion}""
""Microsoft.NETCore.DotNetHostResolver"" : ""{lockedHostFxrVersion}"",
""Microsoft.NETCore.DotNetHost"" : ""{lockedHostVersion}"",
}},
""frameworks"": {{
""{framework}"": {{}}

Просмотреть файл

@ -35,6 +35,9 @@
<FilesToSign Include="$(OutDir)corehost/**/hostpolicy.dll">
<Authenticode>$(CertificateId)</Authenticode>
</FilesToSign>
<FilesToSign Include="$(OutDir)corehost/**/dotnet.exe">
<Authenticode>$(CertificateId)</Authenticode>
</FilesToSign>
</ItemGroup>
</Target>
@ -116,4 +119,4 @@
</ItemGroup>
</Target>
</Project>
</Project>

Просмотреть файл

@ -12,15 +12,19 @@ namespace Microsoft.DotNet.Cli.Build
public class PublishMutationUtilties
{
public static void CleanPublishOutput(
string path,
string path,
string name,
List<string> binariesToBeDeleted,
bool deleteRuntimeConfigJson=false,
bool deleteDepsJson=false,
bool deleteAppHost=false)
bool deleteDepsJson=false)
{
File.Delete(Path.Combine(path, $"{name}{Constants.ExeSuffix}"));
File.Delete(Path.Combine(path, $"{name}.dll"));
File.Delete(Path.Combine(path, $"{name}.pdb"));
binariesToBeDeleted.Add(name);
foreach (var binaryName in binariesToBeDeleted)
{
File.Delete(Path.Combine(path, $"{binaryName}{Constants.ExeSuffix}"));
File.Delete(Path.Combine(path, $"{binaryName}.dll"));
File.Delete(Path.Combine(path, $"{binaryName}.pdb"));
}
if (deleteRuntimeConfigJson)
{
@ -32,10 +36,6 @@ namespace Microsoft.DotNet.Cli.Build
File.Delete(Path.Combine(path, $"{name}.deps.json"));
}
if (deleteAppHost)
{
File.Delete(Path.Combine(path, $"apphost{Constants.ExeSuffix}"));
}
}
public static void ChangeEntryPointLibraryName(string depsFile, string newName)

Просмотреть файл

@ -139,9 +139,9 @@ namespace Microsoft.DotNet.Cli.Build
PublishMutationUtilties.CleanPublishOutput(
sharedFrameworkNameAndVersionRoot,
"framework",
new List<string> {"apphost", "hostfxr", "dotnet" },
deleteRuntimeConfigJson: true,
deleteDepsJson: false,
deleteAppHost: true);
deleteDepsJson: false);
// Rename the .deps file
var destinationDeps = Path.Combine(sharedFrameworkNameAndVersionRoot, $"{s_sharedFrameworkName}.deps.json");
@ -149,9 +149,8 @@ namespace Microsoft.DotNet.Cli.Build
PublishMutationUtilties.ChangeEntryPointLibraryName(destinationDeps, null);
// Generate RID fallback graph
GenerateRuntimeGraph(dotnetCli, destinationDeps);
CopyHostArtifactsToSharedFramework(sharedFrameworkNameAndVersionRoot, hostFxrVersion);
CopyHostArtifactsToSharedFramework(sharedFrameworkNameAndVersionRoot);
ProcessGeneratedDeps(dotnetCli, destinationDeps, new List<string> { $"runtime.{_sharedFrameworkRid}.microsoft.netcore.dotnetapphost", $"runtime.{_sharedFrameworkRid}.microsoft.netcore.dotnethostresolver", "microsoft.netcore.dotnetapphost", "microsoft.netcore.dotnethostresolver" });
_crossgenUtil.CrossgenDirectory(sharedFrameworkNameAndVersionRoot, sharedFrameworkNameAndVersionRoot);
@ -198,7 +197,7 @@ namespace Microsoft.DotNet.Cli.Build
return;
}
private void GenerateRuntimeGraph(DotNetCli dotnetCli, string destinationDeps)
private void ProcessGeneratedDeps(DotNetCli dotnetCli, string destinationDeps, IReadOnlyList<string> packagesToBeRemoved)
{
string runtimeGraphGeneratorRuntime = null;
switch (RuntimeEnvironment.OperatingSystemPlatform)
@ -215,16 +214,24 @@ namespace Microsoft.DotNet.Cli.Build
}
if (!string.IsNullOrEmpty(runtimeGraphGeneratorRuntime))
{
var runtimeGraphGeneratorName = "RuntimeGraphGenerator";
var runtimeGraphGeneratorProject = Path.Combine(Dirs.RepoRoot, "setuptools", "independent", runtimeGraphGeneratorName);
var runtimeGraphGeneratorOutput = Path.Combine(Dirs.Output, "setuptools", "independent", runtimeGraphGeneratorName);
var depsProcessorName = "DepsProcessor";
var depsProcessorProject = Path.Combine(Dirs.RepoRoot, "setuptools", "independent", depsProcessorName);
var depsProcessorOutput = Path.Combine(Dirs.Output, "setuptools", "independent", depsProcessorName);
dotnetCli.Publish(
"--output", runtimeGraphGeneratorOutput,
runtimeGraphGeneratorProject).Execute().EnsureSuccessful();
var runtimeGraphGeneratorExe = Path.Combine(runtimeGraphGeneratorOutput, $"{runtimeGraphGeneratorName}{Constants.ExeSuffix}");
"--output", depsProcessorOutput,
depsProcessorProject).Execute().EnsureSuccessful();
var depsProcessorExe = Path.Combine(depsProcessorOutput, $"{depsProcessorName}{Constants.ExeSuffix}");
Cmd(runtimeGraphGeneratorExe, "--project", _sharedFrameworkSourceRoot, "--deps", destinationDeps, runtimeGraphGeneratorRuntime)
var args = new List<string>() { "--project", _sharedFrameworkSourceRoot, "--deps", destinationDeps, runtimeGraphGeneratorRuntime};
foreach (var pkg in packagesToBeRemoved)
{
args.Add("--remove");
args.Add(pkg);
}
Cmd(depsProcessorExe, args.ToArray())
.Execute()
.EnsureSuccessful();
}
@ -234,15 +241,8 @@ namespace Microsoft.DotNet.Cli.Build
}
}
private void CopyHostArtifactsToSharedFramework(string sharedFrameworkNameAndVersionRoot, string hostFxrVersion)
private void CopyHostArtifactsToSharedFramework(string sharedFrameworkNameAndVersionRoot)
{
File.Copy(
Path.Combine(_corehostLockedDirectory, HostArtifactNames.DotnetHostBaseName),
Path.Combine(sharedFrameworkNameAndVersionRoot, HostArtifactNames.DotnetHostBaseName), true);
File.Copy(
Path.Combine(_corehostLockedDirectory, HostArtifactNames.DotnetHostFxrBaseName),
Path.Combine(sharedFrameworkNameAndVersionRoot, HostArtifactNames.DotnetHostFxrBaseName), true);
// Hostpolicy should be the latest and not the locked version as it is supposed to evolve for
// the framework and has a tight coupling with coreclr's API in the framework.
File.Copy(

Просмотреть файл

@ -34,9 +34,9 @@
<TargetFramework>.NETCoreApp1.1</TargetFramework>
</Dependency>
<!-- references the host packages -->
<Dependency Include="Microsoft.NETCore.DotNetAppHost">
<Version>$(AppHostFullVersion)</Version>
<TargetFramework>.NETCoreApp2.0</TargetFramework>
<Dependency Include="Microsoft.NETCore.DotNetHostPolicy">
<Version>$(HostPolicyFullVersion)</Version>
<TargetFramework>.NETCoreApp2.0</TargetFramework>
</Dependency>
<!-- Add a placeholder to make sure NuGet understands we still support older versions,
@ -60,28 +60,6 @@
</ProjectReference>
</ItemGroup>
<ItemGroup Condition="'$(PackageTargetRuntime)' != ''">
<ArchitectureSpecificNativeFile Include="$(DotNetHostBinDir)/dotnet$(ApplicationFileExtension)" />
<ArchitectureSpecificNativeFile Include="$(DotNetHostBinDir)/dotnet$(SymbolFileExtension)"
Condition="Exists('$(DotNetHostBinDir)/dotnet$(SymbolFileExtension)')">
<IsSymbolFile>true</IsSymbolFile>
</ArchitectureSpecificNativeFile>
<ArchitectureSpecificNativeFile Include="$(DotNetHostBinDir)/$(LibraryFilePrefix)hostfxr$(LibraryFileExtension)"/>
<ArchitectureSpecificNativeFile Include="$(DotNetHostBinDir)/$(LibraryFilePrefix)hostfxr$(SymbolFileExtension)"
Condition="Exists('$(DotNetHostBinDir)/$(LibraryFilePrefix)hostfxr$(SymbolFileExtension)')">
<IsSymbolFile>true</IsSymbolFile>
</ArchitectureSpecificNativeFile>
<ArchitectureSpecificNativeFile Include="$(DotNetHostBinDir)/$(LibraryFilePrefix)hostpolicy$(LibraryFileExtension)"/>
<ArchitectureSpecificNativeFile Include="$(DotNetHostBinDir)/$(LibraryFilePrefix)hostpolicy$(SymbolFileExtension)"
Condition="Exists('$(DotNetHostBinDir)/$(LibraryFilePrefix)hostpolicy$(SymbolFileExtension)')">
<IsSymbolFile>true</IsSymbolFile>
</ArchitectureSpecificNativeFile>
<File Include="@(ArchitectureSpecificNativeFile)">
<TargetPath>runtimes/$(PackageTargetRuntime)/native</TargetPath>
</File>
</ItemGroup>
<UsingTask TaskName="GenerateFileVersionProps" AssemblyFile="$(BuildToolsTaskDir)core-setup.tasks.dll"/>
<Target Name="GenerateFileVersionProps" BeforeTargets="GenerateNuSpec" Condition="'$(PackageTargetRuntime)' == ''">
<MSBuild Projects="@(ProjectReference)"

Просмотреть файл

@ -7,9 +7,6 @@
</PropertyGroup>
<ItemGroup>
<Dependency Include="Microsoft.NETCore.DotNetHost">
<Version>$(HostFullVersion)</Version>
</Dependency>
<Dependency Include="Microsoft.NETCore.DotNetAppHost">
<Version>$(AppHostFullVersion)</Version>
</Dependency>
@ -18,4 +15,4 @@
<Import Condition="'$(PackageTargetRuntime)' != ''" Project="$(MSBuildThisFileDirectory)runtime.$(OSGroup).$(MSBuildProjectName).props" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
</Project>

Просмотреть файл

@ -5,13 +5,14 @@ using System;
using System.Collections.Generic;
using System.CommandLine;
using System.IO;
using System.Linq;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.Extensions.DependencyModel;
using NuGet.Frameworks;
namespace RuntimeGraphGenerator
namespace DepsProcessor
{
public class Program
{
@ -22,6 +23,7 @@ namespace RuntimeGraphGenerator
string projectDirectory = null;
string depsFile = null;
IReadOnlyList<string> runtimes = null;
IReadOnlyList<string> runtimepackagesToBeRemoved = null;
try
{
ArgumentSyntax.Parse(args, syntax =>
@ -33,6 +35,7 @@ namespace RuntimeGraphGenerator
syntax.DefineOption("p|project", ref projectDirectory, "Project location");
syntax.DefineOption("d|deps", ref depsFile, "Deps file path");
syntax.DefineOptionList("r|remove", ref runtimepackagesToBeRemoved, "Runtime packages to be removed");
syntax.DefineParameterList("runtimes", ref runtimes, "Runtimes");
});
@ -75,11 +78,18 @@ namespace RuntimeGraphGenerator
var graph = manager.Collect(exporter.GetDependencies(LibraryType.Package));
var expandedGraph = manager.Expand(graph, runtimes);
var trimmedRuntimeLibraries = context.RuntimeLibraries;
if (runtimepackagesToBeRemoved != null && runtimepackagesToBeRemoved.Count > 0)
{
trimmedRuntimeLibraries = RuntimeReference.RemoveReferences(context.RuntimeLibraries, runtimepackagesToBeRemoved);
}
context = new DependencyContext(
context.Target,
context.CompilationOptions,
context.CompileLibraries,
context.RuntimeLibraries,
trimmedRuntimeLibraries,
expandedGraph
);

Просмотреть файл

@ -0,0 +1,66 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.Extensions.DependencyModel;
using NuGet.Frameworks;
namespace DepsProcessor
{
public class RuntimeReference
{
public static List<RuntimeLibrary> RemoveReferences(IReadOnlyList<RuntimeLibrary> runtimeLibraries, IReadOnlyList<string> packages)
{
List<RuntimeLibrary> result = new List<RuntimeLibrary>();
foreach (var runtimeLib in runtimeLibraries)
{
if (string.IsNullOrEmpty(packages.FirstOrDefault(elem => runtimeLib.Name.Equals(elem, StringComparison.OrdinalIgnoreCase))))
{
List<Dependency> toRemoveDependecy = new List<Dependency>();
foreach (var dependency in runtimeLib.Dependencies)
{
if (!string.IsNullOrEmpty(packages.FirstOrDefault(elem => dependency.Name.Equals(elem, StringComparison.OrdinalIgnoreCase))))
{
toRemoveDependecy.Add(dependency);
}
}
if (toRemoveDependecy.Count > 0)
{
List<Dependency> modifiedDependencies = new List<Dependency>();
foreach (var dependency in runtimeLib.Dependencies)
{
if (!toRemoveDependecy.Contains(dependency))
{
modifiedDependencies.Add(dependency);
}
}
result.Add(new RuntimeLibrary(runtimeLib.Type,
runtimeLib.Name,
runtimeLib.Version,
runtimeLib.Hash,
runtimeLib.RuntimeAssemblyGroups,
runtimeLib.NativeLibraryGroups,
runtimeLib.ResourceAssemblies,
modifiedDependencies,
runtimeLib.Serviceable));
}
else if (string.IsNullOrEmpty(packages.FirstOrDefault(elem => runtimeLib.Name.Equals(elem, StringComparison.OrdinalIgnoreCase))))
{
result.Add(runtimeLib);
}
}
}
return result;
}
}
}

Просмотреть файл

@ -6,7 +6,7 @@
"dependencies": {
"NuGet.RuntimeModel": "3.5.0-rc-1285",
"NuGet.Versioning": "3.5.0-rc-1285",
"System.CommandLine": "0.1.0-e160119-1",
"System.CommandLine": "0.1.0-e170322-6",
"System.Runtime.Serialization.Json": "4.0.2",
"Microsoft.DotNet.ProjectModel": "1.0.0-rc2-002794",
"Microsoft.DotNet.Cli.Utils": "1.0.0-preview2-002794",
@ -16,6 +16,7 @@
"frameworks": {
"netcoreapp1.0": {
"imports": [
"netstandard1.5",
"dnxcore50",
"portable-net45+wp80+win8+wpa81+dnxcore50"
]

Просмотреть файл

@ -557,8 +557,7 @@ bool deps_resolver_t::resolve_probe_dirs(
{
// For standalone apps, apphost.exe will be renamed. Do not use the full package name
// because of rid-fallback could happen (ex: CentOS falling back to RHEL)
if (((entry.asset_name == _X("dotnet")) && ends_with(entry.library_name, _X(".Microsoft.NETCore.App"), false)) ||
((entry.asset_name == _X("apphost")) && ends_with(entry.library_name, _X(".Microsoft.NETCore.DotNetAppHost"), false)))
if ((entry.asset_name == _X("apphost")) && ends_with(entry.library_name, _X(".Microsoft.NETCore.DotNetAppHost"), false))
{
trace::warning(_X("Warning: assembly specified in the dependencies manifest was not found -- package: '%s', version: '%s', path: '%s'"),
entry.library_name.c_str(), entry.library_version.c_str(), entry.relative_path.c_str());

Просмотреть файл

@ -126,12 +126,11 @@ pal::string_t resolve_fxr_path(const pal::string_t& own_dir)
return ret_path;
}
}
// TODO: Issue #215 Do not allow dotnet to load hostfxr side-by-side.
pal::string_t fxr_path;
if (library_exists_in_dir(own_dir, LIBFXR_NAME, &fxr_path))
{
trace::info(_X("Resolved fxr [%s]..."), fxr_path.c_str());
return fxr_path;
trace::error(_X("A fatal error was encountered. This executable cannot be used to activate a standalone app"));
}
return pal::string_t();
#endif