Merge pull request #1795 from mellinoe/wip-build-stuff-rebased

Add installer scripts for the shared framework/host, incorporate into build
This commit is contained in:
Livar 2016-03-14 09:59:12 -07:00
commit 78778b883f
34 changed files with 1518 additions and 115 deletions

View file

@ -293,41 +293,13 @@ namespace Microsoft.DotNet.Cli.Build
}
// Find crossgen
string arch = PlatformServices.Default.Runtime.RuntimeArchitecture;
string packageId;
if (CurrentPlatform.IsWindows)
{
packageId = $"runtime.win7-{arch}.Microsoft.NETCore.Runtime.CoreCLR";
}
else if (CurrentPlatform.IsUbuntu)
{
packageId = "runtime.ubuntu.14.04-x64.Microsoft.NETCore.Runtime.CoreCLR";
}
else if (CurrentPlatform.IsCentOS || CurrentPlatform.IsRHEL)
{
// CentOS runtime is in the runtime.rhel.7-x64... package.
packageId = "runtime.rhel.7-x64.Microsoft.NETCore.Runtime.CoreCLR";
}
else if (CurrentPlatform.IsDebian)
{
packageId = "runtime.debian.8.2-x64.Microsoft.NETCore.Runtime.CoreCLR";
}
else if (CurrentPlatform.IsOSX)
{
packageId = "runtime.osx.10.10-x64.Microsoft.NETCore.Runtime.CoreCLR";
}
else
var crossGenExePath = Microsoft.DotNet.Cli.Build.Crossgen.GetCrossgenPathForVersion(CoreCLRVersion);
if (string.IsNullOrEmpty(crossGenExePath))
{
return c.Failed("Unsupported OS Platform");
}
var crossGenExePath = Path.Combine(
Dirs.NuGetPackages,
packageId,
CoreCLRVersion,
"tools",
$"crossgen{Constants.ExeSuffix}");
// We have to copy crossgen next to mscorlib
var crossgen = Path.Combine(outputDir, $"crossgen{Constants.ExeSuffix}");
File.Copy(crossGenExePath, crossgen, overwrite: true);

View file

@ -14,23 +14,44 @@ namespace Microsoft.DotNet.Cli.Build
{
[Target(nameof(MsiTargets.GenerateMsis),
nameof(MsiTargets.GenerateBundle),
nameof(InstallerTargets.GeneratePkg),
nameof(InstallerTargets.GenerateDeb))]
nameof(PkgTargets.GeneratePkgs),
nameof(InstallerTargets.GenerateDebs))]
public static BuildTargetResult GenerateInstaller(BuildTargetContext c)
{
return c.Success();
}
[Target(nameof(InstallerTargets.GenerateSdkDeb),
nameof(InstallerTargets.GenerateSharedFrameworkDeb),
nameof(InstallerTargets.GenerateSharedHostDeb))]
[BuildPlatforms(BuildPlatform.Ubuntu)]
public static BuildTargetResult GenerateDebs(BuildTargetContext c)
{
return c.Success();
}
[Target]
[BuildPlatforms(BuildPlatform.OSX)]
public static BuildTargetResult GeneratePkg(BuildTargetContext c)
[BuildPlatforms(BuildPlatform.Ubuntu)]
public static BuildTargetResult GenerateSdkDeb(BuildTargetContext c)
{
var channel = c.BuildContext.Get<string>("Channel").ToLower();
var packageName = Monikers.GetDebianPackageName(c);
var version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
var pkg = c.BuildContext.Get<string>("InstallerFile");
Cmd(Path.Combine(Dirs.RepoRoot, "packaging", "osx", "package-osx.sh"),
"-v", version, "-i", Dirs.Stage2, "-o", pkg)
var debFile = c.BuildContext.Get<string>("SdkInstallerFile");
var manPagesDir = Path.Combine(Dirs.RepoRoot, "Documentation", "manpages");
var previousVersionURL = $"https://dotnetcli.blob.core.windows.net/dotnet/{channel}/Installers/Latest/dotnet-ubuntu-x64.latest.deb";
var objRoot = Path.Combine(Dirs.Output, "obj", "debian", "sdk");
if (Directory.Exists(objRoot))
{
Directory.Delete(objRoot, true);
}
Directory.CreateDirectory(objRoot);
Cmd(Path.Combine(Dirs.RepoRoot, "scripts", "package", "package-debian.sh"),
"-v", version, "-i", Dirs.Stage2, "-o", debFile, "-p", packageName, "-m", manPagesDir, "--previous-version-url", previousVersionURL, "--obj-root", objRoot)
.Execute()
.EnsureSuccessful();
return c.Success();
@ -38,17 +59,49 @@ namespace Microsoft.DotNet.Cli.Build
[Target]
[BuildPlatforms(BuildPlatform.Ubuntu)]
public static BuildTargetResult GenerateDeb(BuildTargetContext c)
public static BuildTargetResult GenerateSharedHostDeb(BuildTargetContext c)
{
var channel = c.BuildContext.Get<string>("Channel").ToLower();
var packageName = Monikers.GetDebianPackageName(c);
var version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
var debFile = c.BuildContext.Get<string>("InstallerFile");
var manPagesDir = Path.Combine(Dirs.RepoRoot, "Documentation", "manpages");
var previousVersionURL = $"https://dotnetcli.blob.core.windows.net/dotnet/{channel}/Installers/Latest/dotnet-ubuntu-x64.latest.deb";
var inputRoot = c.BuildContext.Get<string>("SharedHostPublishRoot");
var debFile = c.BuildContext.Get<string>("SharedHostInstallerFile");
var objRoot = Path.Combine(Dirs.Output, "obj", "debian", "sharedhost");
Cmd(Path.Combine(Dirs.RepoRoot, "scripts", "package", "package-debian.sh"),
"-v", version, "-i", Dirs.Stage2, "-o", debFile, "-p", packageName, "-m", manPagesDir, "--previous-version-url", previousVersionURL)
if (Directory.Exists(objRoot))
{
Directory.Delete(objRoot, true);
}
Directory.CreateDirectory(objRoot);
Cmd(Path.Combine(Dirs.RepoRoot, "scripts", "package", "package-sharedhost-debian.sh"),
"--input", inputRoot, "--output", debFile, "--obj-root", objRoot, "--version", version)
.Execute()
.EnsureSuccessful();
return c.Success();
}
[Target]
[BuildPlatforms(BuildPlatform.Ubuntu)]
public static BuildTargetResult GenerateSharedFrameworkDeb(BuildTargetContext c)
{
var packageName = Monikers.GetDebianSharedFrameworkPackageName(c);
var version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
var inputRoot = c.BuildContext.Get<string>("SharedFrameworkPublishRoot");
var debFile = c.BuildContext.Get<string>("SharedFrameworkInstallerFile");
var objRoot = Path.Combine(Dirs.Output, "obj", "debian", "sharedframework");
if (Directory.Exists(objRoot))
{
Directory.Delete(objRoot, true);
}
Directory.CreateDirectory(objRoot);
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-version", c.BuildContext.Get<string>("SharedFrameworkNugetVersion"),
"--obj-root", objRoot, "--version", version)
.Execute()
.EnsureSuccessful();
return c.Success();

View file

@ -22,9 +22,13 @@ namespace Microsoft.DotNet.Cli.Build
}
}
private static string Msi { get; set; }
private static string SdkMsi { get; set; }
private static string Bundle { get; set; }
private static string SdkBundle { get; set; }
private static string SharedHostMsi { get; set; }
private static string SharedFrameworkMsi { get; set; }
private static string Engine { get; set; }
@ -60,9 +64,12 @@ namespace Microsoft.DotNet.Cli.Build
[BuildPlatforms(BuildPlatform.Windows)]
public static BuildTargetResult InitMsi(BuildTargetContext c)
{
Bundle = c.BuildContext.Get<string>("InstallerFile");
Msi = Path.ChangeExtension(Bundle, "msi");
Engine = Path.Combine(Path.GetDirectoryName(Bundle), ENGINE);
SdkBundle = c.BuildContext.Get<string>("SdkInstallerFile");
SdkMsi = Path.ChangeExtension(SdkBundle, "msi");
Engine = Path.Combine(Path.GetDirectoryName(SdkBundle), ENGINE);
SharedHostMsi = Path.ChangeExtension(c.BuildContext.Get<string>("SharedHostInstallerFile"), "msi");
SharedFrameworkMsi = Path.ChangeExtension(c.BuildContext.Get<string>("SharedFrameworkInstallerFile"), "msi");
var buildVersion = c.BuildContext.Get<BuildVersion>("BuildVersion");
MsiVersion = buildVersion.GenerateMsiVersion();
@ -74,9 +81,9 @@ namespace Microsoft.DotNet.Cli.Build
}
[Target(nameof(MsiTargets.InitMsi),
nameof(GenerateDotnetMuxerMsi),
nameof(GenerateDotnetSharedFxMsi),
nameof(GenerateCLISDKMsi))]
nameof(GenerateDotnetSharedHostMsi),
nameof(GenerateDotnetSharedFrameworkMsi),
nameof(GenerateCliSdkMsi))]
[BuildPlatforms(BuildPlatform.Windows)]
public static BuildTargetResult GenerateMsis(BuildTargetContext c)
{
@ -85,11 +92,11 @@ namespace Microsoft.DotNet.Cli.Build
[Target]
[BuildPlatforms(BuildPlatform.Windows)]
public static BuildTargetResult GenerateCLISDKMsi(BuildTargetContext c)
public static BuildTargetResult GenerateCliSdkMsi(BuildTargetContext c)
{
Cmd("powershell", "-NoProfile", "-NoLogo",
Path.Combine(Dirs.RepoRoot, "packaging", "windows", "generatemsi.ps1"),
Dirs.Stage2, Msi, WixRoot, MsiVersion, CliVersion, Arch, Channel)
Dirs.Stage2, SdkMsi, WixRoot, MsiVersion, CliVersion, Arch, Channel)
.Execute()
.EnsureSuccessful();
return c.Success();
@ -97,15 +104,48 @@ namespace Microsoft.DotNet.Cli.Build
[Target]
[BuildPlatforms(BuildPlatform.Windows)]
public static BuildTargetResult GenerateDotnetMuxerMsi(BuildTargetContext c)
public static BuildTargetResult GenerateDotnetSharedHostMsi(BuildTargetContext c)
{
var inputDir = c.BuildContext.Get<string>("SharedHostPublishRoot");
var wixObjRoot = Path.Combine(Dirs.Output, "obj", "wix", "sharedhost");
if (Directory.Exists(wixObjRoot))
{
Directory.Delete(wixObjRoot, true);
}
Directory.CreateDirectory(wixObjRoot);
Cmd("powershell", "-NoProfile", "-NoLogo",
Path.Combine(Dirs.RepoRoot, "packaging", "host", "windows", "generatemsi.ps1"),
inputDir, SharedHostMsi, WixRoot, MsiVersion, CliVersion, Arch, wixObjRoot)
.Execute()
.EnsureSuccessful();
return c.Success();
}
[Target]
[BuildPlatforms(BuildPlatform.Windows)]
public static BuildTargetResult GenerateDotnetSharedFxMsi(BuildTargetContext c)
public static BuildTargetResult GenerateDotnetSharedFrameworkMsi(BuildTargetContext c)
{
var inputDir = c.BuildContext.Get<string>("SharedFrameworkPublishRoot");
var sharedFrameworkNuGetName = SharedFrameworkTargets.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");
if (Directory.Exists(wixObjRoot))
{
Directory.Delete(wixObjRoot, true);
}
Directory.CreateDirectory(wixObjRoot);
Cmd("powershell", "-NoProfile", "-NoLogo",
Path.Combine(Dirs.RepoRoot, "packaging", "sharedframework", "windows", "generatemsi.ps1"),
inputDir, SharedFrameworkMsi, WixRoot, MsiVersion, sharedFrameworkNuGetName, sharedFrameworkNuGetVersion, upgradeCode, Arch, wixObjRoot)
.Execute()
.EnsureSuccessful();
return c.Success();
}
@ -116,7 +156,7 @@ namespace Microsoft.DotNet.Cli.Build
{
Cmd("powershell", "-NoProfile", "-NoLogo",
Path.Combine(Dirs.RepoRoot, "packaging", "windows", "generatebundle.ps1"),
Msi, Bundle, WixRoot, MsiVersion, CliVersion, Arch, Channel)
SdkMsi, SdkBundle, WixRoot, MsiVersion, CliVersion, Arch, Channel)
.EnvironmentVariable("Stage2Dir", Dirs.Stage2)
.Execute()
.EnsureSuccessful();
@ -127,7 +167,7 @@ namespace Microsoft.DotNet.Cli.Build
[BuildPlatforms(BuildPlatform.Windows)]
public static BuildTargetResult ExtractEngineFromBundle(BuildTargetContext c)
{
Cmd($"{WixRoot}\\insignia.exe", "-ib", Bundle, "-o", Engine)
Cmd($"{WixRoot}\\insignia.exe", "-ib", SdkBundle, "-o", Engine)
.Execute()
.EnsureSuccessful();
return c.Success();
@ -137,7 +177,7 @@ namespace Microsoft.DotNet.Cli.Build
[BuildPlatforms(BuildPlatform.Windows)]
public static BuildTargetResult ReattachEngineToBundle(BuildTargetContext c)
{
Cmd($"{WixRoot}\\insignia.exe", "-ab", Engine, Bundle, "-o", Bundle)
Cmd($"{WixRoot}\\insignia.exe", "-ab", Engine, SdkBundle, "-o", SdkBundle)
.Execute()
.EnsureSuccessful();
return c.Success();

View file

@ -22,6 +22,8 @@ namespace Microsoft.DotNet.Cli.Build
[Target(nameof(PrepareTargets.Init),
nameof(PackageTargets.InitPackage),
nameof(PackageTargets.GenerateVersionBadge),
nameof(SharedFrameworkTargets.PublishSharedHost),
nameof(SharedFrameworkTargets.PublishSharedFramework),
nameof(PackageTargets.GenerateCompressedFile),
nameof(InstallerTargets.GenerateInstaller),
nameof(PackageTargets.GenerateNugetPackages))]
@ -55,14 +57,10 @@ namespace Microsoft.DotNet.Cli.Build
[BuildPlatforms(BuildPlatform.Windows)]
public static BuildTargetResult GenerateZip(BuildTargetContext c)
{
var zipFile = c.BuildContext.Get<string>("CompressedFile");
CreateZipFromDirectory(c.BuildContext.Get<string>("SharedHostPublishRoot"), c.BuildContext.Get<string>("SharedHostCompressedFile"));
CreateZipFromDirectory(c.BuildContext.Get<string>("SharedFrameworkPublishRoot"), c.BuildContext.Get<string>("SharedFrameworkCompressedFile"));
CreateZipFromDirectory(Dirs.Stage2, c.BuildContext.Get<string>("SdkCompressedFile"));
if (File.Exists(zipFile))
{
File.Delete(zipFile);
}
ZipFile.CreateFromDirectory(Dirs.Stage2, zipFile, CompressionLevel.Optimal, false);
return c.Success();
}
@ -70,16 +68,10 @@ namespace Microsoft.DotNet.Cli.Build
[BuildPlatforms(BuildPlatform.Unix)]
public static BuildTargetResult GenerateTarBall(BuildTargetContext c)
{
var tarFile = c.BuildContext.Get<string>("CompressedFile");
CreateTarBallFromDirectory(c.BuildContext.Get<string>("SharedHostPublishRoot"), c.BuildContext.Get<string>("SharedHostCompressedFile"));
CreateTarBallFromDirectory(c.BuildContext.Get<string>("SharedFrameworkPublishRoot"), c.BuildContext.Get<string>("SharedFrameworkCompressedFile"));
CreateTarBallFromDirectory(Dirs.Stage2, c.BuildContext.Get<string>("SdkCompressedFile"));
if (File.Exists(tarFile))
{
File.Delete(tarFile);
}
Cmd("tar", "-czf", tarFile, "-C", Dirs.Stage2, ".")
.Execute()
.EnsureSuccessful();
return c.Success();
}
@ -134,5 +126,27 @@ namespace Microsoft.DotNet.Cli.Build
return env;
}
private static void CreateZipFromDirectory(string directory, string artifactPath)
{
if (File.Exists(artifactPath))
{
File.Delete(artifactPath);
}
ZipFile.CreateFromDirectory(directory, artifactPath, CompressionLevel.Optimal, false);
}
private static void CreateTarBallFromDirectory(string directory, string artifactPath)
{
if (File.Exists(artifactPath))
{
File.Delete(artifactPath);
}
Cmd("tar", "-czf", artifactPath, "-C", directory, ".")
.Execute()
.EnsureSuccessful();
}
}
}

View file

@ -0,0 +1,125 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.Extensions.PlatformAbstractions;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
namespace Microsoft.DotNet.Cli.Build
{
public class PkgTargets
{
[Target(nameof(GenerateSdkProductArchive), nameof(GenerateSharedFrameworkProductArchive))]
[BuildPlatforms(BuildPlatform.OSX)]
public static BuildTargetResult GeneratePkgs(BuildTargetContext c)
{
return c.Success();
}
[Target]
[BuildPlatforms(BuildPlatform.OSX)]
public static BuildTargetResult GenerateSdkProductArchive(BuildTargetContext c)
{
var version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
var pkg = c.BuildContext.Get<string>("SdkInstallerFile");
Cmd(Path.Combine(Dirs.RepoRoot, "packaging", "osx", "package-osx.sh"),
"-v", version, "-i", Dirs.Stage2, "-o", pkg)
.Execute()
.EnsureSuccessful();
return c.Success();
}
[Target(nameof(GenerateSharedFrameworkPkg), nameof(GenerateSharedHostPkg))]
[BuildPlatforms(BuildPlatform.OSX)]
public static BuildTargetResult GenerateSharedFrameworkProductArchive(BuildTargetContext c)
{
string sharedFrameworkNugetName = SharedFrameworkTargets.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";
string packageIntermediatesPath = Path.Combine(Dirs.Output, "obj", "pkg");
string resourcePath = Path.Combine(Dirs.RepoRoot, "packaging", "osx", "resources");
string outFilePath = Path.Combine(packageIntermediatesPath, id + ".pkg");
string inputDistTemplatePath = Path.Combine(
Dirs.RepoRoot,
"packaging",
"osx",
"sharedframework",
"shared-framework-distribution-template.xml");
string distTemplate = File.ReadAllText(inputDistTemplatePath);
string distributionPath = Path.Combine(packageIntermediatesPath, "shared-framework-formatted-distribution.xml");
string formattedDistContents =
distTemplate.Replace("{SharedFrameworkNugetVersion}", sharedFrameworkNugetVersion)
.Replace("{SharedFrameworkNugetName}", SharedFrameworkTargets.SharedFrameworkName)
.Replace("{VERSION}", version);
File.WriteAllText(distributionPath, formattedDistContents);
Cmd("productbuild",
"--version", version,
"--identifier", id,
"--package-path", packageIntermediatesPath,
"--resources", resourcePath,
"--distribution", distributionPath,
outFilePath)
.Execute()
.EnsureSuccessful();
return c.Success();
}
[Target]
[BuildPlatforms(BuildPlatform.OSX)]
public static BuildTargetResult GenerateSharedFrameworkPkg(BuildTargetContext c)
{
string sharedFrameworkNugetName = SharedFrameworkTargets.SharedFrameworkName;
string sharedFrameworkNugetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
Directory.CreateDirectory(Path.Combine(Dirs.Output, "obj", "pkg"));
string version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
string id = $"com.microsoft.dotnet.sharedframework.{sharedFrameworkNugetName}.{sharedFrameworkNugetVersion}.component.osx.x64";
string outFilePath = Path.Combine(Dirs.Output, "obj", "pkg", id + ".pkg");
string installLocation = "/usr/local/share/dotnet";
string scriptsLocation = Path.Combine(Dirs.RepoRoot, "packaging", "osx", "sharedframework", "scripts");
Cmd("pkgbuild",
"--root", c.BuildContext.Get<string>("SharedFrameworkPublishRoot"),
"--identifier", id,
"--version", version,
"--install-location", installLocation,
"--scripts", scriptsLocation,
outFilePath)
.Execute()
.EnsureSuccessful();
return c.Success();
}
[Target]
[BuildPlatforms(BuildPlatform.OSX)]
public static BuildTargetResult GenerateSharedHostPkg(BuildTargetContext c)
{
Directory.CreateDirectory(Path.Combine(Dirs.Output, "obj", "pkg"));
string version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
string id = $"com.microsoft.dotnet.sharedhost.osx.x64";
string outFilePath = Path.Combine(Dirs.Output, "obj", "pkg", id + ".pkg");
string installLocation = "/usr/local/share/dotnet";
string scriptsLocation = Path.Combine(Dirs.RepoRoot, "packaging", "osx", "sharedhost", "scripts");
Cmd("pkgbuild",
"--root", c.BuildContext.Get<string>("SharedHostPublishRoot"),
"--identifier", id,
"--version", version,
"--install-location", installLocation,
"--scripts", scriptsLocation,
outFilePath)
.Execute()
.EnsureSuccessful();
return c.Success();
}
}
}

View file

@ -108,34 +108,13 @@ namespace Microsoft.DotNet.Cli.Build
[Target]
public static BuildTargetResult ExpectedBuildArtifacts(BuildTargetContext c)
{
var productName = Monikers.GetProductMoniker(c);
var config = Environment.GetEnvironmentVariable("CONFIGURATION");
var versionBadgeName = $"{CurrentPlatform.Current}_{CurrentArchitecture.Current}_{config}_version_badge.svg";
c.BuildContext["VersionBadge"] = Path.Combine(Dirs.Output, versionBadgeName);
var extension = CurrentPlatform.IsWindows ? ".zip" : ".tar.gz";
c.BuildContext["CompressedFile"] = Path.Combine(Dirs.Packages, productName + extension);
string installer = "";
switch (CurrentPlatform.Current)
{
case BuildPlatform.Windows:
installer = productName + ".exe";
break;
case BuildPlatform.OSX:
installer = productName + ".pkg";
break;
case BuildPlatform.Ubuntu:
installer = productName + ".deb";
break;
default:
break;
}
if (!string.IsNullOrEmpty(installer))
{
c.BuildContext["InstallerFile"] = Path.Combine(Dirs.Packages, installer);
}
AddInstallerArtifactToContext(c, "dotnet", "Sdk");
AddInstallerArtifactToContext(c, "dotnet-host", "SharedHost");
AddInstallerArtifactToContext(c, "dotnet-sharedframework", "SharedFramework");
return c.Success();
}
@ -361,5 +340,35 @@ cmake is required to build the native host 'corehost'";
}
return dict;
}
private static void AddInstallerArtifactToContext(BuildTargetContext c, string artifactPrefix, string contextPrefix)
{
var productName = Monikers.GetProductMoniker(c, artifactPrefix);
var extension = CurrentPlatform.IsWindows ? ".zip" : ".tar.gz";
c.BuildContext[contextPrefix + "CompressedFile"] = Path.Combine(Dirs.Packages, productName + extension);
string installer = "";
switch (CurrentPlatform.Current)
{
case BuildPlatform.Windows:
installer = productName + ".exe";
break;
case BuildPlatform.OSX:
installer = productName + ".pkg";
break;
case BuildPlatform.Ubuntu:
installer = productName + ".deb";
break;
default:
break;
}
if (!string.IsNullOrEmpty(installer))
{
c.BuildContext[contextPrefix + "InstallerFile"] = Path.Combine(Dirs.Packages, installer);
}
}
}
}

View file

@ -45,7 +45,7 @@ namespace Microsoft.DotNet.Cli.Build
[Target(nameof(PublishTargets.PublishVersionBadge),
nameof(PublishTargets.PublishCompressedFile),
nameof(PublishTargets.PublishInstallerFile),
nameof(PublishTargets.PublishSdkInstallerFile),
nameof(PublishTargets.PublishLatestVersionTextFile))]
public static BuildTargetResult PublishArtifacts(BuildTargetContext c)
{
@ -67,7 +67,7 @@ namespace Microsoft.DotNet.Cli.Build
[Target]
public static BuildTargetResult PublishCompressedFile(BuildTargetContext c)
{
var compressedFile = c.BuildContext.Get<string>("CompressedFile");
var compressedFile = c.BuildContext.Get<string>("SdkCompressedFile");
var compressedFileBlob = $"{Channel}/Binaries/{Version}/{Path.GetFileName(compressedFile)}";
var latestCompressedFile = compressedFile.Replace(Version, "latest");
var latestCompressedFileBlob = $"{Channel}/Binaries/Latest/{Path.GetFileName(latestCompressedFile)}";
@ -79,9 +79,9 @@ namespace Microsoft.DotNet.Cli.Build
[Target]
[BuildPlatforms(BuildPlatform.Windows, BuildPlatform.OSX, BuildPlatform.Ubuntu)]
public static BuildTargetResult PublishInstallerFile(BuildTargetContext c)
public static BuildTargetResult PublishSdkInstallerFile(BuildTargetContext c)
{
var installerFile = c.BuildContext.Get<string>("InstallerFile");
var installerFile = c.BuildContext.Get<string>("SdkInstallerFile");
var installerFileBlob = $"{Channel}/Installers/{Version}/{Path.GetFileName(installerFile)}";
var latestInstallerFile = installerFile.Replace(Version, "latest");
var latestInstallerFileBlob = $"{Channel}/Installers/Latest/{Path.GetFileName(latestInstallerFile)}";
@ -102,12 +102,12 @@ namespace Microsoft.DotNet.Cli.Build
return c.Success();
}
[Target(nameof(PublishInstallerFile))]
[Target(nameof(PublishSdkInstallerFile))]
[BuildPlatforms(BuildPlatform.Ubuntu)]
public static BuildTargetResult PublishDebFileToDebianRepo(BuildTargetContext c)
{
var packageName = Monikers.GetDebianPackageName(c);
var installerFile = c.BuildContext.Get<string>("InstallerFile");
var installerFile = c.BuildContext.Get<string>("SdkInstallerFile");
var uploadUrl = $"https://dotnetcli.blob.core.windows.net/dotnet/{Channel}/Installers/{Version}/{Path.GetFileName(installerFile)}";
var uploadJson = GenerateUploadJsonFile(packageName, Version, uploadUrl);

View file

@ -0,0 +1,159 @@
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;
namespace Microsoft.DotNet.Cli.Build
{
public class SharedFrameworkTargets
{
public const string SharedFrameworkName = "NETStandard.Library";
private const string CoreHostBaseName = "corehost";
[Target]
public static BuildTargetResult PublishSharedFramework(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))
{
Directory.Delete(SharedFrameworkPublishRoot, true);
}
// 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);
DotNetCli.Stage0.Publish("--output", SharedFrameworkNameAndVersionRoot, 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"));
// Rename the .deps file
File.Move(Path.Combine(SharedFrameworkNameAndVersionRoot, "framework.deps"), Path.Combine(SharedFrameworkNameAndVersionRoot, $"{SharedFrameworkName}.deps"));
// corehost will be renamed to dotnet at some point and then this can be removed.
File.Move(Path.Combine(SharedFrameworkNameAndVersionRoot, $"{CoreHostBaseName}{Constants.ExeSuffix}"), Path.Combine(SharedFrameworkNameAndVersionRoot, $"dotnet{Constants.ExeSuffix}"));
// hostpolicy will be renamed to dotnet at some point and then this can be removed.
File.Move(Path.Combine(SharedFrameworkNameAndVersionRoot, $"{Constants.DynamicLibPrefix}hostpolicy{Constants.DynamicLibSuffix}"), Path.Combine(SharedFrameworkNameAndVersionRoot, $"{Constants.DynamicLibPrefix}dotnethostimpl{Constants.DynamicLibSuffix}"));
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"));
CrossGenAllManagedAssemblies(SharedFrameworkNameAndVersionRoot);
}
else
{
c.Warn("Shared framework will not be crossgen'd because mscorlib.ni.dll does not exist.");
}
return c.Success();
}
[Target]
public static BuildTargetResult PublishSharedHost(BuildTargetContext c)
{
string SharedHostPublishRoot = Path.Combine(Dirs.Output, "obj", "sharedhost");
if (Directory.Exists(SharedHostPublishRoot))
{
Directory.Delete(SharedHostPublishRoot, true);
}
DotNetCli.Stage0.Publish("--output", SharedHostPublishRoot, Path.Combine(Dirs.RepoRoot, "src", "sharedframework", "host")).Execute().EnsureSuccessful();
// For the shared host, we only want corerun and not any of the other artifacts in the package (like the hostpolicy)
foreach (var filePath in Directory.GetFiles(SharedHostPublishRoot))
{
if (Path.GetFileName(filePath) != $"{CoreHostBaseName}{Constants.ExeSuffix}")
{
File.Delete(filePath);
}
}
// corehost will be renamed to dotnet at some point and then this can be removed.
File.Move(Path.Combine(SharedHostPublishRoot, $"{CoreHostBaseName}{Constants.ExeSuffix}"), Path.Combine(SharedHostPublishRoot, $"dotnet{Constants.ExeSuffix}"));
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;
}
}
return null;
}
private static void CrossGenAllManagedAssemblies(string pathToAssemblies)
{
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);
}
}
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

@ -0,0 +1,50 @@
using System.IO;
using System.Linq;
using System;
using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.Cli.Build
{
internal static class Crossgen
{
public static string GetCrossgenPathForVersion(string coreClrVersion)
{
string arch = PlatformServices.Default.Runtime.RuntimeArchitecture;
string packageId;
if (CurrentPlatform.IsWindows)
{
packageId = $"runtime.win7-{arch}.Microsoft.NETCore.Runtime.CoreCLR";
}
else if (CurrentPlatform.IsUbuntu)
{
packageId = "runtime.ubuntu.14.04-x64.Microsoft.NETCore.Runtime.CoreCLR";
}
else if (CurrentPlatform.IsCentOS || CurrentPlatform.IsRHEL)
{
// CentOS runtime is in the runtime.rhel.7-x64... package.
packageId = "runtime.rhel.7-x64.Microsoft.NETCore.Runtime.CoreCLR";
}
else if (CurrentPlatform.IsOSX)
{
packageId = "runtime.osx.10.10-x64.Microsoft.NETCore.Runtime.CoreCLR";
}
else if (CurrentPlatform.IsDebian)
{
packageId = "runtime.debian.8.2-x64.Microsoft.NETCore.Runtime.CoreCLR";
}
else
{
return null;
}
return Path.Combine(
Dirs.NuGetPackages,
packageId,
coreClrVersion,
"tools",
$"crossgen{Constants.ExeSuffix}");
}
}
}

View file

@ -8,12 +8,12 @@ namespace Microsoft.DotNet.Cli.Build
{
public class Monikers
{
public static string GetProductMoniker(BuildTargetContext c)
public static string GetProductMoniker(BuildTargetContext c, string artifactPrefix)
{
string osname = GetOSShortName();
var arch = CurrentArchitecture.Current.ToString();
var version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
return $"dotnet-{osname}-{arch}.{version}";
return $"{artifactPrefix}-{osname}-{arch}.{version}";
}
public static string GetDebianPackageName(BuildTargetContext c)
@ -38,6 +38,13 @@ namespace Microsoft.DotNet.Cli.Build
return packageName;
}
public static string GetDebianSharedFrameworkPackageName(BuildTargetContext c)
{
var sharedFrameworkNugetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
return $"dotnet-sharedframework-{SharedFrameworkTargets.SharedFrameworkName}-{sharedFrameworkNugetVersion}".ToLower();
}
public static string GetOSShortName()
{
string osname = "";

View file

@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
namespace Microsoft.DotNet.Cli.Build
{
@ -34,5 +35,55 @@ namespace Microsoft.DotNet.Cli.Build
throw new PlatformNotSupportedException();
}
}
// Generate a Version 5 (SHA1 Name Based) Guid from a name.
public static Guid GenerateGuidFromName(string name)
{
// Any fixed GUID will do for a namespace.
Guid namespaceId = new Guid("28F1468D-672B-489A-8E0C-7C5B3030630C");
using (SHA1 hasher = SHA1.Create())
{
var nameBytes = System.Text.Encoding.UTF8.GetBytes(name ?? string.Empty);
var namespaceBytes = namespaceId.ToByteArray();
SwapGuidByteOrder(namespaceBytes);
var streamToHash = new byte[namespaceBytes.Length + nameBytes.Length];
Array.Copy(namespaceBytes, streamToHash, namespaceBytes.Length);
Array.Copy(nameBytes, 0, streamToHash, namespaceBytes.Length, nameBytes.Length);
var hashResult = hasher.ComputeHash(streamToHash);
var res = new byte[16];
Array.Copy(hashResult, res, res.Length);
unchecked { res[6] = (byte)(0x50 | (res[6] & 0x0F)); }
unchecked { res[8] = (byte)(0x40 | (res[8] & 0x3F)); }
SwapGuidByteOrder(res);
return new Guid(res);
}
}
// Do a byte order swap, .NET GUIDs store multi byte components in little
// endian.
private static void SwapGuidByteOrder(byte[] b)
{
Swap(b, 0, 3);
Swap(b, 1, 2);
Swap(b, 5, 6);
Swap(b, 7, 8);
}
private static void Swap(byte[] b, int x, int y)
{
byte t = b[x];
b[x] = b[y];
b[y] = t;
}
}
}

View file

@ -8,9 +8,11 @@
"dependencies": {
"NETStandard.Library": "1.0.0-rc2-23901",
"System.IO.Compression.ZipFile": "4.0.1-rc2-23901",
"System.Security.Cryptography.Algorithms": "4.0.0-rc2-23901",
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-16537",
"Microsoft.DotNet.Cli.Build.Framework": "1.0.0-*",
"WindowsAzure.Storage" : "6.2.2-preview"
"WindowsAzure.Storage" : "6.2.2-preview",
"System.Reflection.Metadata" : "1.2.0"
},
"frameworks": {