Fix Package targets to respect the new CLI SDK layout.

This commit is contained in:
Sridhar Periyasamy 2016-03-16 17:54:44 -07:00
parent 4d19e4d866
commit 5150bae60c
10 changed files with 100 additions and 291 deletions

View file

@ -139,7 +139,7 @@ namespace Microsoft.DotNet.Cli.Build
{
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "src"));
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "test"));
if (Directory.Exists(Dirs.Stage1))
{
Utils.DeleteDirectory(Dirs.Stage1);
@ -147,7 +147,7 @@ namespace Microsoft.DotNet.Cli.Build
Directory.CreateDirectory(Dirs.Stage1);
CopySharedHost(Dirs.Stage1);
PackageSharedFramework(c, Dirs.Stage1, DotNetCli.Stage0);
PublishSharedFramework(c, Dirs.Stage1, DotNetCli.Stage0);
return CompileCliSdk(c,
dotnet: DotNetCli.Stage0,
outputDir: Dirs.Stage1);
@ -160,14 +160,14 @@ namespace Microsoft.DotNet.Cli.Build
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "src"));
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "test"));
if (Directory.Exists(Dirs.Stage2))
{
Utils.DeleteDirectory(Dirs.Stage2);
}
Directory.CreateDirectory(Dirs.Stage2);
PackageSharedFramework(c, Dirs.Stage2, DotNetCli.Stage1);
PublishSharedFramework(c, Dirs.Stage2, DotNetCli.Stage1);
CopySharedHost(Dirs.Stage2);
var result = CompileCliSdk(c,
dotnet: DotNetCli.Stage1,
@ -211,10 +211,10 @@ namespace Microsoft.DotNet.Cli.Build
Path.Combine(outputDir, DotnetHostFxrBaseName), true);
}
public static void PackageSharedFramework(BuildTargetContext c, string outputDir, DotNetCli dotnetCli)
public static void PublishSharedFramework(BuildTargetContext c, string outputDir, DotNetCli dotnetCli)
{
string SharedFrameworkSourceRoot = Path.Combine(Dirs.RepoRoot, "src", "sharedframework", "framework");
string SharedFrameworkNugetVersion = GetVersionFromProjectJson(Path.Combine(Path.Combine(Dirs.RepoRoot, "src", "sharedframework", "framework"), "project.json"));
string SharedFrameworkNugetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
// We publish to a sub folder of the PublishRoot so tools like heat and zip can generate folder structures easier.
string SharedFrameworkNameAndVersionRoot = Path.Combine(outputDir, "shared", SharedFrameworkName, SharedFrameworkNugetVersion);
@ -303,23 +303,6 @@ namespace Microsoft.DotNet.Cli.Build
CrossgenSharedFx(c, SharedFrameworkNameAndVersionRoot);
}
private static string GetVersionFromProjectJson(string pathToProjectJson)
{
Regex r = new Regex($"\"{Regex.Escape(SharedFrameworkName)}\"\\s*:\\s*\"(?'version'[^\"]*)\"");
foreach (var line in File.ReadAllLines(pathToProjectJson))
{
var m = r.Match(line);
if (m.Success)
{
return m.Groups["version"].Value;
}
}
throw new InvalidOperationException("Unable to match the version name from " + pathToProjectJson);
}
private static BuildTargetResult CompileCliSdk(BuildTargetContext c, DotNetCli dotnet, string outputDir)
{
var configuration = c.BuildContext.Get<string>("Configuration");
@ -499,7 +482,7 @@ namespace Microsoft.DotNet.Cli.Build
c.Warn("Skipping crossgen for SharedFx because CROSSGEN_SHAREDFRAMEWORK is not set to 1");
return c.Success();
}
foreach (var file in Directory.GetFiles(pathToAssemblies))
{
string fileName = Path.GetFileName(file);

View file

@ -99,7 +99,7 @@ namespace Microsoft.DotNet.Cli.Build
Cmd(Path.Combine(Dirs.RepoRoot, "scripts", "package", "package-sharedframework-debian.sh"),
"--input", inputRoot, "--output", debFile, "--package-name", packageName,
"--framework-nuget-name", SharedFrameworkTargets.SharedFrameworkName,
"--framework-nuget-name", Monikers.SharedFrameworkName,
"--framework-nuget-version", c.BuildContext.Get<string>("SharedFrameworkNugetVersion"),
"--obj-root", objRoot, "--version", version)
.Execute()

View file

@ -64,7 +64,7 @@ namespace Microsoft.DotNet.Cli.Build
[BuildPlatforms(BuildPlatform.Windows)]
public static BuildTargetResult InitMsi(BuildTargetContext c)
{
SdkBundle = c.BuildContext.Get<string>("SdkInstallerFile");
SdkBundle = c.BuildContext.Get<string>("CombinedFrameworkSDKHostInstallerFile");
SdkMsi = Path.ChangeExtension(SdkBundle, "msi");
Engine = Path.Combine(Path.GetDirectoryName(SdkBundle), ENGINE);
@ -129,7 +129,7 @@ namespace Microsoft.DotNet.Cli.Build
public static BuildTargetResult GenerateDotnetSharedFrameworkMsi(BuildTargetContext c)
{
var inputDir = c.BuildContext.Get<string>("SharedFrameworkPublishRoot");
var sharedFrameworkNuGetName = SharedFrameworkTargets.SharedFrameworkName;
var sharedFrameworkNuGetName = Monikers.SharedFrameworkName;
var sharedFrameworkNuGetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
var upgradeCode = Utils.GenerateGuidFromName($"{sharedFrameworkNuGetName}-{sharedFrameworkNuGetVersion}-{Arch}").ToString().ToUpper();
var wixObjRoot = Path.Combine(Dirs.Output, "obj", "wix", "sharedframework");

View file

@ -13,8 +13,8 @@ namespace Microsoft.DotNet.Cli.Build
public static class PackageTargets
{
[Target(nameof(PackageTargets.CopyCLISDKLayout),
nameof(SharedFrameworkTargets.PublishSharedHost),
nameof(SharedFrameworkTargets.PublishSharedFramework),
nameof(PackageTargets.CopySharedHostLayout),
nameof(PackageTargets.CopySharedFxLayout),
nameof(PackageTargets.CopyCombinedFrameworkSDKHostLayout),
nameof(PackageTargets.CopyCombinedFrameworkHostLayout))]
public static BuildTargetResult InitPackage(BuildTargetContext c)
@ -52,45 +52,62 @@ namespace Microsoft.DotNet.Cli.Build
[Target]
public static BuildTargetResult CopyCLISDKLayout(BuildTargetContext c)
{
var nugetVersion = c.BuildContext.Get<BuildVersion>("BuildVersion").NuGetVersion;
var cliSdkRoot = Path.Combine(Dirs.Output, "obj", "clisdk");
var cliSdk = Path.Combine(cliSdkRoot, "sdk", nugetVersion);
if (Directory.Exists(cliSdkRoot))
{
Utils.DeleteDirectory(cliSdkRoot);
}
Directory.CreateDirectory(cliSdk);
var binPath = Path.Combine(Dirs.Stage2, "bin");
foreach (var file in Directory.GetFiles(binPath, "*", SearchOption.AllDirectories))
{
string destFile = file.Replace(binPath, cliSdk);
Directory.CreateDirectory(Path.GetDirectoryName(destFile));
File.Copy(file, destFile, true);
}
File.Copy(Path.Combine(Dirs.Stage2, ".version"), Path.Combine(cliSdk, ".version"), true);
// copy stage2 to "cliSdkRoot\bin".
// this is a temp hack until we fix the build scripts to use the new shared fx and shared host
// the current build scripts need the CLI sdk to be in the bin folder.
foreach (var file in Directory.GetFiles(Dirs.Stage2, "*", SearchOption.AllDirectories))
{
string destFile = file.Replace(Dirs.Stage2, cliSdkRoot);
Directory.CreateDirectory(Path.GetDirectoryName(destFile));
File.Copy(file, destFile, true);
}
Directory.CreateDirectory(cliSdkRoot);
Utils.CopyDirectoryRecursively(Path.Combine(Dirs.Stage2, "sdk"), cliSdkRoot, true);
c.BuildContext["CLISDKRoot"] = cliSdkRoot;
return c.Success();
}
[Target]
public static BuildTargetResult CopySharedHostLayout(BuildTargetContext c)
{
var sharedHostRoot = Path.Combine(Dirs.Output, "obj", "sharedHost");
if (Directory.Exists(sharedHostRoot))
{
Utils.DeleteDirectory(sharedHostRoot);
}
Directory.CreateDirectory(sharedHostRoot);
foreach (var file in Directory.GetFiles(Dirs.Stage2, "*", SearchOption.TopDirectoryOnly))
{
var destFile = file.Replace(Dirs.Stage2, sharedHostRoot);
File.Copy(file, destFile, true);
}
c.BuildContext["SharedHostPublishRoot"] = sharedHostRoot;
return c.Success();
}
[Target]
public static BuildTargetResult CopySharedFxLayout(BuildTargetContext c)
{
var sharedFxRoot = Path.Combine(Dirs.Output, "obj", "sharedFx");
if (Directory.Exists(sharedFxRoot))
{
Utils.DeleteDirectory(sharedFxRoot);
}
Directory.CreateDirectory(sharedFxRoot);
Utils.CopyDirectoryRecursively(Path.Combine(Dirs.Stage2, "shared"), sharedFxRoot, true);
c.BuildContext["SharedFrameworkPublishRoot"] = sharedFxRoot;
return c.Success();
}
[Target]
public static BuildTargetResult CopyCombinedFrameworkSDKHostLayout(BuildTargetContext c)
{
var combinedRoot = Path.Combine(Dirs.Output, "obj", "combined-framework-sdk-host");
if (Directory.Exists(combinedRoot))
{
Utils.DeleteDirectory(combinedRoot);
}
string sdkPublishRoot = c.BuildContext.Get<string>("CLISDKRoot");
Utils.CopyDirectoryRecursively(sdkPublishRoot, combinedRoot);
@ -109,6 +126,11 @@ namespace Microsoft.DotNet.Cli.Build
public static BuildTargetResult CopyCombinedFrameworkHostLayout(BuildTargetContext c)
{
var combinedRoot = Path.Combine(Dirs.Output, "obj", "combined-framework-host");
if (Directory.Exists(combinedRoot))
{
Utils.DeleteDirectory(combinedRoot);
}
string sharedFrameworkPublishRoot = c.BuildContext.Get<string>("SharedFrameworkPublishRoot");
Utils.CopyDirectoryRecursively(sharedFrameworkPublishRoot, combinedRoot);
@ -130,9 +152,6 @@ namespace Microsoft.DotNet.Cli.Build
[BuildPlatforms(BuildPlatform.Windows)]
public static BuildTargetResult GenerateZip(BuildTargetContext c)
{
CreateZipFromDirectory(c.BuildContext.Get<string>("SharedHostPublishRoot"), c.BuildContext.Get<string>("SharedHostCompressedFile"));
CreateZipFromDirectory(c.BuildContext.Get<string>("SharedFrameworkPublishRoot"), c.BuildContext.Get<string>("SharedFrameworkCompressedFile"));
CreateZipFromDirectory(c.BuildContext.Get<string>("CLISDKRoot"), c.BuildContext.Get<string>("SdkCompressedFile"));
CreateZipFromDirectory(c.BuildContext.Get<string>("CombinedFrameworkSDKHostRoot"), c.BuildContext.Get<string>("CombinedFrameworkSDKHostCompressedFile"));
CreateZipFromDirectory(c.BuildContext.Get<string>("CombinedFrameworkHostRoot"), c.BuildContext.Get<string>("CombinedFrameworkHostCompressedFile"));
@ -143,9 +162,6 @@ namespace Microsoft.DotNet.Cli.Build
[BuildPlatforms(BuildPlatform.Unix)]
public static BuildTargetResult GenerateTarBall(BuildTargetContext c)
{
CreateTarBallFromDirectory(c.BuildContext.Get<string>("SharedHostPublishRoot"), c.BuildContext.Get<string>("SharedHostCompressedFile"));
CreateTarBallFromDirectory(c.BuildContext.Get<string>("SharedFrameworkPublishRoot"), c.BuildContext.Get<string>("SharedFrameworkCompressedFile"));
CreateTarBallFromDirectory(c.BuildContext.Get<string>("CLISDKRoot"), c.BuildContext.Get<string>("SdkCompressedFile"));
CreateTarBallFromDirectory(c.BuildContext.Get<string>("CombinedFrameworkSDKHostRoot"), c.BuildContext.Get<string>("CombinedFrameworkSDKHostCompressedFile"));
CreateTarBallFromDirectory(c.BuildContext.Get<string>("CombinedFrameworkHostRoot"), c.BuildContext.Get<string>("CombinedFrameworkHostCompressedFile"));
@ -159,7 +175,7 @@ namespace Microsoft.DotNet.Cli.Build
var versionSuffix = c.BuildContext.Get<BuildVersion>("BuildVersion").VersionSuffix;
var env = GetCommonEnvVars(c);
Cmd("powershell", "-NoProfile", "-NoLogo",
Path.Combine(Dirs.RepoRoot, "packaging", "nuget", "package.ps1"), Path.Combine(Dirs.Stage2, "bin"), versionSuffix)
Path.Combine(Dirs.RepoRoot, "packaging", "nuget", "package.ps1"), Dirs.Stage2, versionSuffix)
.Environment(env)
.Execute()
.EnsureSuccessful();

View file

@ -37,7 +37,7 @@ namespace Microsoft.DotNet.Cli.Build
[BuildPlatforms(BuildPlatform.OSX)]
public static BuildTargetResult GenerateSharedFrameworkProductArchive(BuildTargetContext c)
{
string sharedFrameworkNugetName = SharedFrameworkTargets.SharedFrameworkName;
string sharedFrameworkNugetName = Monikers.SharedFrameworkName;
string sharedFrameworkNugetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
string version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
string id = $"com.microsoft.dotnet.sharedframework.{sharedFrameworkNugetName}.{sharedFrameworkNugetVersion}.osx.x64";
@ -53,9 +53,9 @@ namespace Microsoft.DotNet.Cli.Build
"shared-framework-distribution-template.xml");
string distTemplate = File.ReadAllText(inputDistTemplatePath);
string distributionPath = Path.Combine(packageIntermediatesPath, "shared-framework-formatted-distribution.xml");
string formattedDistContents =
string formattedDistContents =
distTemplate.Replace("{SharedFrameworkNugetVersion}", sharedFrameworkNugetVersion)
.Replace("{SharedFrameworkNugetName}", SharedFrameworkTargets.SharedFrameworkName)
.Replace("{SharedFrameworkNugetName}", Monikers.SharedFrameworkName)
.Replace("{VERSION}", version);
File.WriteAllText(distributionPath, formattedDistContents);
@ -63,7 +63,7 @@ namespace Microsoft.DotNet.Cli.Build
"--version", version,
"--identifier", id,
"--package-path", packageIntermediatesPath,
"--resources", resourcePath,
"--resources", resourcePath,
"--distribution", distributionPath,
outFilePath)
.Execute()
@ -76,7 +76,7 @@ namespace Microsoft.DotNet.Cli.Build
[BuildPlatforms(BuildPlatform.OSX)]
public static BuildTargetResult GenerateSharedFrameworkPkg(BuildTargetContext c)
{
string sharedFrameworkNugetName = SharedFrameworkTargets.SharedFrameworkName;
string sharedFrameworkNugetName = Monikers.SharedFrameworkName;
string sharedFrameworkNugetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
Directory.CreateDirectory(Path.Combine(Dirs.Output, "obj", "pkg"));
string version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;

View file

@ -10,6 +10,7 @@ using System.Text;
using static Microsoft.DotNet.Cli.Build.FS;
using static Microsoft.DotNet.Cli.Build.Utils;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
using System.Text.RegularExpressions;
namespace Microsoft.DotNet.Cli.Build
{
@ -45,6 +46,7 @@ namespace Microsoft.DotNet.Cli.Build
c.BuildContext["Configuration"] = configEnv;
c.BuildContext["Channel"] = Environment.GetEnvironmentVariable("CHANNEL");
c.BuildContext["SharedFrameworkNugetVersion"] = GetVersionFromProjectJson(Path.Combine(Dirs.RepoRoot, "src", "sharedframework", "framework", "project.json"));
c.Info($"Building {c.BuildContext["Configuration"]} to: {Dirs.Output}");
c.Info("Build Environment:");
@ -112,11 +114,11 @@ namespace Microsoft.DotNet.Cli.Build
var versionBadgeName = $"{CurrentPlatform.Current}_{CurrentArchitecture.Current}_{config}_version_badge.svg";
c.BuildContext["VersionBadge"] = Path.Combine(Dirs.Output, versionBadgeName);
AddInstallerArtifactToContext(c, "dotnet", "Sdk");
AddInstallerArtifactToContext(c, "dotnet-sdk", "Sdk");
AddInstallerArtifactToContext(c, "dotnet-host", "SharedHost");
AddInstallerArtifactToContext(c, "dotnet-sharedframework", "SharedFramework");
AddInstallerArtifactToContext(c, "dotnet-combined-framework-sdk-host", "CombinedFrameworkSDKHost");
AddInstallerArtifactToContext(c, "dotnet-combined-framework-host", "CombinedFrameworkHost");
AddInstallerArtifactToContext(c, "dotnet-dev", "CombinedFrameworkSDKHost");
AddInstallerArtifactToContext(c, "dotnet", "CombinedFrameworkHost");
return c.Success();
}
@ -315,6 +317,23 @@ cmake is required to build the native host 'corehost'";
return c.Success();
}
private static string GetVersionFromProjectJson(string pathToProjectJson)
{
Regex r = new Regex($"\"{Regex.Escape(Monikers.SharedFrameworkName)}\"\\s*:\\s*\"(?'version'[^\"]*)\"");
foreach (var line in File.ReadAllLines(pathToProjectJson))
{
var m = r.Match(line);
if (m.Success)
{
return m.Groups["version"].Value;
}
}
throw new InvalidOperationException("Unable to match the version name from " + pathToProjectJson);
}
private static bool AptPackageIsInstalled(string packageName)
{
var result = Command.Create("dpkg", "-s", packageName)

View file

@ -1,218 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Text.RegularExpressions;
using System.Reflection.PortableExecutable;
using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.Extensions.PlatformAbstractions;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
namespace Microsoft.DotNet.Cli.Build
{
public class SharedFrameworkTargets
{
public const string SharedFrameworkName = "Microsoft.NETCore.App";
private const string CoreHostBaseName = "corehost";
private const string DotnetHostFxrBaseName = "hostfxr";
private const string HostPolicyBaseName = "hostpolicy";
[Target(nameof(PackageSharedFramework), nameof(CrossGenAllManagedAssemblies))]
public static BuildTargetResult PublishSharedFramework(BuildTargetContext c)
{
return c.Success();
}
[Target]
public static BuildTargetResult PackageSharedFramework(BuildTargetContext c)
{
string SharedFrameworkPublishRoot = Path.Combine(Dirs.Output, "obj", "sharedframework");
string SharedFrameworkSourceRoot = Path.Combine(Dirs.RepoRoot, "src", "sharedframework", "framework");
string SharedFrameworkNugetVersion = GetVersionFromProjectJson(Path.Combine(Path.Combine(Dirs.RepoRoot, "src", "sharedframework", "framework"), "project.json"));
if (Directory.Exists(SharedFrameworkPublishRoot))
{
Utils.DeleteDirectory(SharedFrameworkPublishRoot);
}
// We publish to a sub folder of the PublishRoot so tools like heat and zip can generate folder structures easier.
string SharedFrameworkNameAndVersionRoot = Path.Combine(SharedFrameworkPublishRoot, "shared", SharedFrameworkName, SharedFrameworkNugetVersion);
string publishFramework = "dnxcore50"; // Temporary, use "netcoreapp" when we update nuget.
string publishRuntime;
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows)
{
publishRuntime = $"win7-{PlatformServices.Default.Runtime.RuntimeArchitecture}";
}
else
{
publishRuntime = PlatformServices.Default.Runtime.GetRuntimeIdentifier();
}
DotNetCli.Stage2.Publish(
"--output", SharedFrameworkNameAndVersionRoot,
"-r", publishRuntime,
"-f", publishFramework,
SharedFrameworkSourceRoot).Execute().EnsureSuccessful();
c.BuildContext["SharedFrameworkPublishRoot"] = SharedFrameworkPublishRoot;
c.BuildContext["SharedFrameworkNugetVersion"] = SharedFrameworkNugetVersion;
// Clean up artifacts that dotnet-publish generates which we don't need
File.Delete(Path.Combine(SharedFrameworkNameAndVersionRoot, $"framework{Constants.ExeSuffix}"));
File.Delete(Path.Combine(SharedFrameworkNameAndVersionRoot, "framework.dll"));
File.Delete(Path.Combine(SharedFrameworkNameAndVersionRoot, "framework.pdb"));
File.Delete(Path.Combine(SharedFrameworkNameAndVersionRoot, "framework.runtimeconfig.json"));
// Rename the .deps file
var destinationDeps = Path.Combine(SharedFrameworkNameAndVersionRoot, $"{SharedFrameworkName}.deps.json");
File.Move(Path.Combine(SharedFrameworkNameAndVersionRoot, "framework.deps"), Path.Combine(SharedFrameworkNameAndVersionRoot, $"{SharedFrameworkName}.deps"));
File.Move(Path.Combine(SharedFrameworkNameAndVersionRoot, "framework.deps.json"), destinationDeps);
// Generate RID fallback graph
string runtimeGraphGeneratorRuntime = null;
switch (PlatformServices.Default.Runtime.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(c.BuildContext.BuildDirectory, "tools", runtimeGraphGeneratorName);
var runtimeGraphGeneratorOutput = Path.Combine(Dirs.Output, "tools", runtimeGraphGeneratorName);
DotNetCli.Stage2.Publish(
"--output", runtimeGraphGeneratorOutput,
runtimeGraphGeneratorProject).Execute().EnsureSuccessful();
var runtimeGraphGeneratorExe = Path.Combine(runtimeGraphGeneratorOutput, $"{runtimeGraphGeneratorName}{Constants.ExeSuffix}");
Cmd(runtimeGraphGeneratorExe, "--project", SharedFrameworkSourceRoot, "--deps", destinationDeps, runtimeGraphGeneratorRuntime)
.Execute();
}
else
{
c.Error($"Could not determine rid graph generation runtime for platform {PlatformServices.Default.Runtime.OperatingSystemPlatform}");
}
// corehost will be renamed to dotnet at some point and then we will not need to rename it here.
File.Copy(
Path.Combine(Dirs.Corehost, $"{CoreHostBaseName}{Constants.ExeSuffix}"),
Path.Combine(SharedFrameworkNameAndVersionRoot, $"dotnet{Constants.ExeSuffix}"));
File.Copy(
Path.Combine(Dirs.Corehost, $"{Constants.DynamicLibPrefix}{HostPolicyBaseName}{Constants.DynamicLibSuffix}"),
Path.Combine(SharedFrameworkNameAndVersionRoot, $"{Constants.DynamicLibPrefix}{HostPolicyBaseName}{Constants.DynamicLibSuffix}"), true);
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"));
c.BuildContext["SharedFrameworkNameAndVersionRoot"] = SharedFrameworkNameAndVersionRoot;
}
return c.Success();
}
[Target]
public static BuildTargetResult PublishSharedHost(BuildTargetContext c)
{
string SharedHostPublishRoot = Path.Combine(Dirs.Output, "obj", "sharedhost");
if (Directory.Exists(SharedHostPublishRoot))
{
Utils.DeleteDirectory(SharedHostPublishRoot);
}
Directory.CreateDirectory(SharedHostPublishRoot);
// corehost will be renamed to dotnet at some point and then this can be removed.
File.Copy(
Path.Combine(Dirs.Corehost, $"{CoreHostBaseName}{Constants.ExeSuffix}"),
Path.Combine(SharedHostPublishRoot, $"dotnet{Constants.ExeSuffix}"));
File.Copy(
Path.Combine(Dirs.Corehost, $"{Constants.DynamicLibPrefix}{DotnetHostFxrBaseName}{Constants.DynamicLibSuffix}"),
Path.Combine(SharedHostPublishRoot, $"{Constants.DynamicLibPrefix}{DotnetHostFxrBaseName}{Constants.DynamicLibSuffix}"));
c.BuildContext["SharedHostPublishRoot"] = SharedHostPublishRoot;
return c.Success();
}
private static string GetVersionFromProjectJson(string pathToProjectJson)
{
Regex r = new Regex($"\"{Regex.Escape(SharedFrameworkName)}\"\\s*:\\s*\"(?'version'[^\"]*)\"");
foreach(var line in File.ReadAllLines(pathToProjectJson))
{
var m = r.Match(line);
if (m.Success)
{
return m.Groups["version"].Value;
}
}
throw new InvalidOperationException("Unable to match the version name from " + pathToProjectJson);
}
[Target]
[Environment("CROSSGEN_SHAREDFRAMEWORK", "1", "true")]
public static BuildTargetResult CrossGenAllManagedAssemblies(BuildTargetContext c)
{
string pathToAssemblies = c.BuildContext.Get<string>("SharedFrameworkNameAndVersionRoot");
foreach (var file in Directory.GetFiles(pathToAssemblies))
{
string fileName = Path.GetFileName(file);
if (fileName == "mscorlib.dll" || fileName == "mscorlib.ni.dll" || !HasMetadata(file))
{
continue;
}
string tempPathName = Path.ChangeExtension(file, "readytorun");
// This is not always correct. The version of crossgen we need to pick up is whatever one was restored as part
// of the Microsoft.NETCore.Runtime.CoreCLR package that is part of the shared library. For now, the version hardcoded
// in CompileTargets and the one in the shared library project.json match and are updated in lock step, but long term
// we need to be able to look at the project.lock.json file and figure out what version of Microsoft.NETCore.Runtime.CoreCLR
// was used, and then select that version.
ExecSilent(Crossgen.GetCrossgenPathForVersion(CompileTargets.CoreCLRVersion),
"-readytorun", "-in", file, "-out", tempPathName, "-platform_assemblies_paths", pathToAssemblies);
File.Delete(file);
File.Move(tempPathName, file);
}
return c.Success();
}
private static bool HasMetadata(string pathToFile)
{
try
{
using (var inStream = File.OpenRead(pathToFile))
{
using (var peReader = new PEReader(inStream))
{
return peReader.HasMetadata;
}
}
} catch (BadImageFormatException) { }
return false;
}
}
}

View file

@ -8,6 +8,8 @@ namespace Microsoft.DotNet.Cli.Build
{
public class Monikers
{
public const string SharedFrameworkName = "Microsoft.NETCore.App";
public static string GetProductMoniker(BuildTargetContext c, string artifactPrefix)
{
string osname = GetOSShortName();
@ -31,7 +33,7 @@ namespace Microsoft.DotNet.Cli.Build
case "rtm":
packageName = "dotnet";
break;
default:
default:
throw new Exception($"Unknown channel - {channel}");
}
@ -42,7 +44,7 @@ namespace Microsoft.DotNet.Cli.Build
{
var sharedFrameworkNugetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
return $"dotnet-sharedframework-{SharedFrameworkTargets.SharedFrameworkName}-{sharedFrameworkNugetVersion}".ToLower();
return $"dotnet-sharedframework-{SharedFrameworkName}-{sharedFrameworkNugetVersion}".ToLower();
}
public static string GetOSShortName()

View file

@ -101,8 +101,15 @@ namespace Microsoft.DotNet.Cli.Build
}
}
public static void CopyDirectoryRecursively(string path, string destination)
public static void CopyDirectoryRecursively(string path, string destination, bool keepParentDir = false)
{
if (keepParentDir)
{
path = path.TrimEnd(Path.DirectorySeparatorChar);
destination = Path.Combine(destination, Path.GetFileName(path));
Directory.CreateDirectory(destination);
}
foreach (var file in Directory.GetFiles(path, "*", SearchOption.AllDirectories))
{
string destFile = file.Replace(path, destination);

View file

@ -38,7 +38,7 @@ $testName = "Microsoft.DotNet.Cli.Msi.Tests"
$testDir="$PSScriptRoot\$testName"
$testBin="$RepoRoot\artifacts\tests\$testName"
pushd "$Stage2Dir\bin"
pushd "$Stage2Dir"
try {
.\dotnet restore `