diff --git a/scripts/dotnet-cli-build/CompileTargets.cs b/scripts/dotnet-cli-build/CompileTargets.cs index f78b0a2a8..d05bf4e2c 100644 --- a/scripts/dotnet-cli-build/CompileTargets.cs +++ b/scripts/dotnet-cli-build/CompileTargets.cs @@ -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("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("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); diff --git a/scripts/dotnet-cli-build/InstallerTargets.cs b/scripts/dotnet-cli-build/InstallerTargets.cs index 097d37f18..ba657769f 100644 --- a/scripts/dotnet-cli-build/InstallerTargets.cs +++ b/scripts/dotnet-cli-build/InstallerTargets.cs @@ -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("SharedFrameworkNugetVersion"), "--obj-root", objRoot, "--version", version) .Execute() diff --git a/scripts/dotnet-cli-build/MsiTargets.cs b/scripts/dotnet-cli-build/MsiTargets.cs index f4f82f695..5d2adf871 100644 --- a/scripts/dotnet-cli-build/MsiTargets.cs +++ b/scripts/dotnet-cli-build/MsiTargets.cs @@ -64,7 +64,7 @@ namespace Microsoft.DotNet.Cli.Build [BuildPlatforms(BuildPlatform.Windows)] public static BuildTargetResult InitMsi(BuildTargetContext c) { - SdkBundle = c.BuildContext.Get("SdkInstallerFile"); + SdkBundle = c.BuildContext.Get("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("SharedFrameworkPublishRoot"); - var sharedFrameworkNuGetName = SharedFrameworkTargets.SharedFrameworkName; + var sharedFrameworkNuGetName = Monikers.SharedFrameworkName; var sharedFrameworkNuGetVersion = c.BuildContext.Get("SharedFrameworkNugetVersion"); var upgradeCode = Utils.GenerateGuidFromName($"{sharedFrameworkNuGetName}-{sharedFrameworkNuGetVersion}-{Arch}").ToString().ToUpper(); var wixObjRoot = Path.Combine(Dirs.Output, "obj", "wix", "sharedframework"); diff --git a/scripts/dotnet-cli-build/PackageTargets.cs b/scripts/dotnet-cli-build/PackageTargets.cs index 0ef59c1f2..2719439e4 100644 --- a/scripts/dotnet-cli-build/PackageTargets.cs +++ b/scripts/dotnet-cli-build/PackageTargets.cs @@ -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").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("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("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("SharedHostPublishRoot"), c.BuildContext.Get("SharedHostCompressedFile")); - CreateZipFromDirectory(c.BuildContext.Get("SharedFrameworkPublishRoot"), c.BuildContext.Get("SharedFrameworkCompressedFile")); - CreateZipFromDirectory(c.BuildContext.Get("CLISDKRoot"), c.BuildContext.Get("SdkCompressedFile")); CreateZipFromDirectory(c.BuildContext.Get("CombinedFrameworkSDKHostRoot"), c.BuildContext.Get("CombinedFrameworkSDKHostCompressedFile")); CreateZipFromDirectory(c.BuildContext.Get("CombinedFrameworkHostRoot"), c.BuildContext.Get("CombinedFrameworkHostCompressedFile")); @@ -143,9 +162,6 @@ namespace Microsoft.DotNet.Cli.Build [BuildPlatforms(BuildPlatform.Unix)] public static BuildTargetResult GenerateTarBall(BuildTargetContext c) { - CreateTarBallFromDirectory(c.BuildContext.Get("SharedHostPublishRoot"), c.BuildContext.Get("SharedHostCompressedFile")); - CreateTarBallFromDirectory(c.BuildContext.Get("SharedFrameworkPublishRoot"), c.BuildContext.Get("SharedFrameworkCompressedFile")); - CreateTarBallFromDirectory(c.BuildContext.Get("CLISDKRoot"), c.BuildContext.Get("SdkCompressedFile")); CreateTarBallFromDirectory(c.BuildContext.Get("CombinedFrameworkSDKHostRoot"), c.BuildContext.Get("CombinedFrameworkSDKHostCompressedFile")); CreateTarBallFromDirectory(c.BuildContext.Get("CombinedFrameworkHostRoot"), c.BuildContext.Get("CombinedFrameworkHostCompressedFile")); @@ -159,7 +175,7 @@ namespace Microsoft.DotNet.Cli.Build var versionSuffix = c.BuildContext.Get("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(); diff --git a/scripts/dotnet-cli-build/PkgTargets.cs b/scripts/dotnet-cli-build/PkgTargets.cs index 1f082b069..56b37026f 100644 --- a/scripts/dotnet-cli-build/PkgTargets.cs +++ b/scripts/dotnet-cli-build/PkgTargets.cs @@ -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("SharedFrameworkNugetVersion"); string version = c.BuildContext.Get("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("SharedFrameworkNugetVersion"); Directory.CreateDirectory(Path.Combine(Dirs.Output, "obj", "pkg")); string version = c.BuildContext.Get("BuildVersion").SimpleVersion; diff --git a/scripts/dotnet-cli-build/PrepareTargets.cs b/scripts/dotnet-cli-build/PrepareTargets.cs index 0dcfa1538..33a2eaf43 100644 --- a/scripts/dotnet-cli-build/PrepareTargets.cs +++ b/scripts/dotnet-cli-build/PrepareTargets.cs @@ -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) diff --git a/scripts/dotnet-cli-build/SharedFrameworkTargets.cs b/scripts/dotnet-cli-build/SharedFrameworkTargets.cs deleted file mode 100644 index 7dffd64c4..000000000 --- a/scripts/dotnet-cli-build/SharedFrameworkTargets.cs +++ /dev/null @@ -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("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; - } - } -} diff --git a/scripts/dotnet-cli-build/Utils/Monikers.cs b/scripts/dotnet-cli-build/Utils/Monikers.cs index b69c0d05b..7fb3562e4 100644 --- a/scripts/dotnet-cli-build/Utils/Monikers.cs +++ b/scripts/dotnet-cli-build/Utils/Monikers.cs @@ -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("SharedFrameworkNugetVersion"); - return $"dotnet-sharedframework-{SharedFrameworkTargets.SharedFrameworkName}-{sharedFrameworkNugetVersion}".ToLower(); + return $"dotnet-sharedframework-{SharedFrameworkName}-{sharedFrameworkNugetVersion}".ToLower(); } public static string GetOSShortName() diff --git a/scripts/dotnet-cli-build/Utils/Utils.cs b/scripts/dotnet-cli-build/Utils/Utils.cs index d9dd937a0..b94343249 100644 --- a/scripts/dotnet-cli-build/Utils/Utils.cs +++ b/scripts/dotnet-cli-build/Utils/Utils.cs @@ -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); diff --git a/test/Installer/testmsi.ps1 b/test/Installer/testmsi.ps1 index 3f4f0d3cc..d1b82f67b 100644 --- a/test/Installer/testmsi.ps1 +++ b/test/Installer/testmsi.ps1 @@ -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 `