Remove The host build, consume the host build from core-setup

This commit is contained in:
Bryan 2016-05-16 15:30:53 -07:00 committed by Bryan Thornbury
parent 651e8c2524
commit aa01110c33
293 changed files with 650 additions and 25590 deletions

View file

@ -110,17 +110,18 @@ namespace Microsoft.DotNet.Cli.Build
return rid;
}
public void CrossgenDirectory(BuildTargetContext c, string pathToAssemblies)
public void CrossgenDirectory(string sharedFxPath, string pathToAssemblies)
{
// Check if we need to skip crossgen
if (string.Equals(Environment.GetEnvironmentVariable("DISABLE_CROSSGEN"), "1"))
{
c.Warn("Skipping crossgen for because DISABLE_CROSSGEN is set to 1");
var originalColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Skipping crossgen for because DISABLE_CROSSGEN is set to 1");
Console.ForegroundColor = originalColor;
return;
}
string sharedFxPath = c.BuildContext.Get<string>("SharedFrameworkPath");
// HACK
// The input directory can be a portable FAT app (example the CLI itself).
// In that case there can be RID specific managed dependencies which are not right next to the app binary (example System.Diagnostics.TraceSource).

View file

@ -27,6 +27,7 @@ namespace Microsoft.DotNet.Cli.Build
public static readonly string CorehostLocked = Path.Combine(Output, "corehost", "locked");
public static readonly string CorehostLocalPackages = Path.Combine(Output, "corehost");
public static readonly string CorehostDummyPackages = Path.Combine(Output, "corehostdummypackages");
public static readonly string SharedFrameworkPublish = Path.Combine(Intermediate, "sharedFrameworkPublish");
public static readonly string TestOutput = Path.Combine(Output, "tests");
public static readonly string TestArtifacts = Path.Combine(TestOutput, "artifacts");
public static readonly string TestPackages = Path.Combine(TestOutput, "packages");

View file

@ -70,7 +70,7 @@ namespace Microsoft.DotNet.Cli.Build
public static string GetDebianSharedFrameworkPackageName(BuildTargetContext c)
{
var sharedFrameworkNugetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
var sharedFrameworkNugetVersion = DependencyVersions.SharedFrameworkVersion;
return $"dotnet-sharedframework-{SharedFrameworkName}-{sharedFrameworkNugetVersion}".ToLower();
}

View file

@ -0,0 +1,81 @@
using Microsoft.DotNet.Cli.Build.Framework;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.DotNet.Cli.Build
{
public class PublishMutationUtilties
{
public static void CleanPublishOutput(
string path,
string name,
bool deleteRuntimeConfigJson=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"));
if (deleteRuntimeConfigJson)
{
File.Delete(Path.Combine(path, $"{name}.runtimeconfig.json"));
}
if (deleteDepsJson)
{
File.Delete(Path.Combine(path, $"{name}.deps.json"));
}
}
public static void ChangeEntryPointLibraryName(string depsFile, string newName)
{
JToken deps;
using (var file = File.OpenText(depsFile))
using (JsonTextReader reader = new JsonTextReader(file))
{
deps = JObject.ReadFrom(reader);
}
string version = null;
foreach (JProperty target in deps["targets"])
{
var targetLibrary = target.Value.Children<JProperty>().FirstOrDefault();
if (targetLibrary == null)
{
continue;
}
version = targetLibrary.Name.Substring(targetLibrary.Name.IndexOf('/') + 1);
if (newName == null)
{
targetLibrary.Remove();
}
else
{
targetLibrary.Replace(new JProperty(newName + '/' + version, targetLibrary.Value));
}
}
if (version != null)
{
var library = deps["libraries"].Children<JProperty>().First();
if (newName == null)
{
library.Remove();
}
else
{
library.Replace(new JProperty(newName + '/' + version, library.Value));
}
using (var file = File.CreateText(depsFile))
using (var writer = new JsonTextWriter(file) { Formatting = Formatting.Indented })
{
deps.WriteTo(writer);
}
}
}
}
}

View file

@ -0,0 +1,219 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.Cli.Build.Framework;
using Newtonsoft.Json;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
using static Microsoft.DotNet.Cli.Build.FS;
namespace Microsoft.DotNet.Cli.Build
{
public class SharedFrameworkPublisher
{
public static string s_sharedFrameworkName = "Microsoft.NETCore.App";
private string _sharedFrameworkTemplateSourceRoot;
private string _sharedFrameworkNugetVersion;
private string _sharedFrameworkRid;
private string _sharedFrameworkSourceRoot;
private string _repoRoot;
private string _corehostLockedDirectory;
private string _corehostLatestDirectory;
private Crossgen _crossgenUtil = new Crossgen(DependencyVersions.CoreCLRVersion);
private string _corehostPackageSource;
public SharedFrameworkPublisher(
string repoRoot,
string corehostLockedDirectory,
string corehostLatestDirectory,
string corehostPackageSource,
string sharedFrameworkNugetVersion)
{
_repoRoot = repoRoot;
_corehostLockedDirectory = corehostLockedDirectory;
_corehostLatestDirectory = corehostLatestDirectory;
_corehostPackageSource = corehostPackageSource;
_sharedFrameworkTemplateSourceRoot = Path.Combine(repoRoot, "src", "sharedframework", "framework");
_sharedFrameworkNugetVersion = sharedFrameworkNugetVersion;
_sharedFrameworkRid = ComputeSharedFrameworkRid();
_sharedFrameworkSourceRoot = GenerateSharedFrameworkProject(
_sharedFrameworkNugetVersion,
_sharedFrameworkTemplateSourceRoot,
_sharedFrameworkRid);
}
public static string GetSharedFrameworkPublishPath(string outputRootDirectory, string sharedFrameworkNugetVersion)
{
return Path.Combine(
outputRootDirectory,
"shared",
s_sharedFrameworkName,
sharedFrameworkNugetVersion);
}
private string ComputeSharedFrameworkRid()
{
return RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows
? $"win7-{RuntimeEnvironment.RuntimeArchitecture}"
: RuntimeEnvironment.GetRuntimeIdentifier();
}
public void CopySharedHostArtifacts(string sharedFrameworkPublishRoot)
{
File.Copy(
Path.Combine(_corehostLockedDirectory, HostArtifactNames.DotnetHostBaseName),
Path.Combine(sharedFrameworkPublishRoot, HostArtifactNames.DotnetHostBaseName), true);
File.Copy(
Path.Combine(_corehostLockedDirectory, HostArtifactNames.DotnetHostFxrBaseName),
Path.Combine(sharedFrameworkPublishRoot, HostArtifactNames.DotnetHostFxrBaseName), true);
}
public void PublishSharedFramework(string outputRootDirectory, string commitHash, DotNetCli dotnetCli)
{
dotnetCli.Restore(
"--verbosity", "verbose",
"--disable-parallel",
"--infer-runtimes",
"--fallbacksource", _corehostPackageSource)
.WorkingDirectory(_sharedFrameworkSourceRoot)
.Execute()
.EnsureSuccessful();
// We publish to a sub folder of the PublishRoot so tools like heat and zip can generate folder structures easier.
string sharedFrameworkNameAndVersionRoot = GetSharedFrameworkPublishPath(outputRootDirectory, _sharedFrameworkNugetVersion);
if (Directory.Exists(sharedFrameworkNameAndVersionRoot))
{
Utils.DeleteDirectory(sharedFrameworkNameAndVersionRoot);
}
dotnetCli.Publish(
"--output", sharedFrameworkNameAndVersionRoot,
"-r", _sharedFrameworkRid,
_sharedFrameworkSourceRoot)
.Execute()
.EnsureSuccessful();
// Clean up artifacts that dotnet-publish generates which we don't need
PublishMutationUtilties.CleanPublishOutput(
sharedFrameworkNameAndVersionRoot,
"framework",
deleteRuntimeConfigJson: true,
deleteDepsJson: false);
// Rename the .deps file
var destinationDeps = Path.Combine(sharedFrameworkNameAndVersionRoot, $"{s_sharedFrameworkName}.deps.json");
File.Move(Path.Combine(sharedFrameworkNameAndVersionRoot, "framework.deps.json"), destinationDeps);
PublishMutationUtilties.ChangeEntryPointLibraryName(destinationDeps, null);
// Generate RID fallback graph
GenerateRuntimeGraph(dotnetCli, destinationDeps);
CopyHostArtifactsToSharedFramework(sharedFrameworkNameAndVersionRoot);
if (File.Exists(Path.Combine(sharedFrameworkNameAndVersionRoot, "mscorlib.ni.dll")))
{
// Publish already places the crossgen'd version of mscorlib into the output, so we can
// remove the IL version
File.Delete(Path.Combine(sharedFrameworkNameAndVersionRoot, "mscorlib.dll"));
}
_crossgenUtil.CrossgenDirectory(sharedFrameworkNameAndVersionRoot, sharedFrameworkNameAndVersionRoot);
// Generate .version file for sharedfx
var version = _sharedFrameworkNugetVersion;
var content = $@"{commitHash}{Environment.NewLine}{version}{Environment.NewLine}";
File.WriteAllText(Path.Combine(sharedFrameworkNameAndVersionRoot, ".version"), content);
return;
}
private void GenerateRuntimeGraph(DotNetCli dotnetCli, string destinationDeps)
{
string runtimeGraphGeneratorRuntime = null;
switch (RuntimeEnvironment.OperatingSystemPlatform)
{
case Platform.Windows:
runtimeGraphGeneratorRuntime = "win";
break;
case Platform.Linux:
runtimeGraphGeneratorRuntime = "linux";
break;
case Platform.Darwin:
runtimeGraphGeneratorRuntime = "osx";
break;
}
if (!string.IsNullOrEmpty(runtimeGraphGeneratorRuntime))
{
var runtimeGraphGeneratorName = "RuntimeGraphGenerator";
var runtimeGraphGeneratorProject = Path.Combine(Dirs.RepoRoot, "tools", "independent", runtimeGraphGeneratorName);
var runtimeGraphGeneratorOutput = Path.Combine(Dirs.Output, "tools", "independent", runtimeGraphGeneratorName);
dotnetCli.Publish(
"--output", runtimeGraphGeneratorOutput,
runtimeGraphGeneratorProject).Execute().EnsureSuccessful();
var runtimeGraphGeneratorExe = Path.Combine(runtimeGraphGeneratorOutput, $"{runtimeGraphGeneratorName}{Constants.ExeSuffix}");
Cmd(runtimeGraphGeneratorExe, "--project", _sharedFrameworkSourceRoot, "--deps", destinationDeps, runtimeGraphGeneratorRuntime)
.Execute()
.EnsureSuccessful();
}
else
{
throw new Exception($"Could not determine rid graph generation runtime for platform {RuntimeEnvironment.OperatingSystemPlatform}");
}
}
private void CopyHostArtifactsToSharedFramework(string sharedFrameworkNameAndVersionRoot)
{
File.Copy(
Path.Combine(_corehostLockedDirectory, HostArtifactNames.DotnetHostBaseName),
Path.Combine(sharedFrameworkNameAndVersionRoot, HostArtifactNames.DotnetHostBaseName), true);
File.Copy(
Path.Combine(_corehostLockedDirectory, HostArtifactNames.DotnetHostBaseName),
Path.Combine(sharedFrameworkNameAndVersionRoot, $"corehost{Constants.ExeSuffix}"), 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(
Path.Combine(_corehostLatestDirectory, HostArtifactNames.HostPolicyBaseName),
Path.Combine(sharedFrameworkNameAndVersionRoot, HostArtifactNames.HostPolicyBaseName), true);
}
private string GenerateSharedFrameworkProject(
string sharedFrameworkNugetVersion,
string sharedFrameworkTemplatePath,
string rid)
{
string sharedFrameworkProjectPath = Path.Combine(Dirs.Intermediate, "sharedFramework", "framework");
Utils.DeleteDirectory(sharedFrameworkProjectPath);
CopyRecursive(sharedFrameworkTemplatePath, sharedFrameworkProjectPath, true);
string templateFile = Path.Combine(sharedFrameworkProjectPath, "project.json.template");
JObject sharedFrameworkProject = JsonUtils.ReadProject(templateFile);
sharedFrameworkProject["dependencies"]["Microsoft.NETCore.App"] = sharedFrameworkNugetVersion;
((JObject)sharedFrameworkProject["runtimes"]).RemoveAll();
sharedFrameworkProject["runtimes"][rid] = new JObject();
string projectJsonPath = Path.Combine(sharedFrameworkProjectPath, "project.json");
JsonUtils.WriteProject(sharedFrameworkProject, projectJsonPath);
Rm(templateFile);
return sharedFrameworkProjectPath;
}
}
}