diff --git a/build_projects/dotnet-cli-build/CompileTargets.cs b/build_projects/dotnet-cli-build/CompileTargets.cs index 1c1b6332d..6ec05002c 100644 --- a/build_projects/dotnet-cli-build/CompileTargets.cs +++ b/build_projects/dotnet-cli-build/CompileTargets.cs @@ -107,14 +107,15 @@ namespace Microsoft.DotNet.Cli.Build } Directory.CreateDirectory(Dirs.Stage2); - var result = CompileCliSdk(c, + var result = CompileCliSdkAndGenerateNuGetPackagesArchive(c, dotnet: DotNetCli.Stage1, - rootOutputDirectory: Dirs.Stage2); + rootOutputDirectory: Dirs.Stage2, + currentDotnet: DotNetCli.Stage2); if (!result.Success) { return result; - } + } if (CurrentPlatform.IsWindows) { @@ -157,7 +158,26 @@ namespace Microsoft.DotNet.Cli.Build FS.RmFilesInDirRecursive(directory, "*.pdb"); } - private static BuildTargetResult CompileCliSdk(BuildTargetContext c, DotNetCli dotnet, string rootOutputDirectory) + private static BuildTargetResult CompileCliSdkAndGenerateNuGetPackagesArchive( + BuildTargetContext c, + DotNetCli dotnet, + string rootOutputDirectory, + DotNetCli currentDotnet) + { + var buildVersion = c.BuildContext.Get("BuildVersion"); + var sdkOutputDirectory = Path.Combine(rootOutputDirectory, "sdk", buildVersion.NuGetVersion); + + CompileCliSdk(c, dotnet, rootOutputDirectory); + + GenerateNuGetPackagesArchive(c, currentDotnet, sdkOutputDirectory); + + return c.Success(); + } + + private static BuildTargetResult CompileCliSdk( + BuildTargetContext c, + DotNetCli dotnet, + string rootOutputDirectory) { var configuration = c.BuildContext.Get("Configuration"); var buildVersion = c.BuildContext.Get("BuildVersion"); @@ -236,7 +256,7 @@ namespace Microsoft.DotNet.Cli.Build var sharedFrameworkNameVersionPath = SharedFrameworkPublisher.GetSharedFrameworkPublishPath( rootOutputDirectory, sharedFrameworkNugetVersion); - + // Copy Host to SDK Directory File.Copy( Path.Combine(sharedFrameworkNameVersionPath, HostArtifactNames.DotnetHostBaseName), @@ -250,7 +270,7 @@ namespace Microsoft.DotNet.Cli.Build Path.Combine(sharedFrameworkNameVersionPath, HostArtifactNames.HostPolicyBaseName), Path.Combine(sdkOutputDirectory, HostArtifactNames.HostPolicyBaseName), overwrite: true); - + CrossgenUtil.CrossgenDirectory( sharedFrameworkNameVersionPath, sdkOutputDirectory); @@ -258,9 +278,77 @@ namespace Microsoft.DotNet.Cli.Build // Generate .version file var version = buildVersion.NuGetVersion; var content = $@"{c.BuildContext["CommitHash"]}{Environment.NewLine}{version}{Environment.NewLine}"; - File.WriteAllText(Path.Combine(sdkOutputDirectory, ".version"), content); + File.WriteAllText(Path.Combine(sdkOutputDirectory, ".version"), content); return c.Success(); + } + + private static void GenerateNuGetPackagesArchive( + BuildTargetContext c, + DotNetCli dotnet, + string sdkOutputDirectory) + { + var nuGetPackagesArchiveProject = Path.Combine(Dirs.Intermediate, "NuGetPackagesArchiveProject"); + var nuGetPackagesArchiveFolder = Path.Combine(Dirs.Intermediate, "nuGetPackagesArchiveFolder"); + + RestoreNuGetPackagesArchive(dotnet, nuGetPackagesArchiveProject, nuGetPackagesArchiveFolder); + + CompressNuGetPackagesArchive(c, dotnet, nuGetPackagesArchiveFolder, sdkOutputDirectory); + } + + private static void RestoreNuGetPackagesArchive( + DotNetCli dotnet, + string nuGetPackagesArchiveProject, + string nuGetPackagesArchiveFolder) + { + Rmdir(nuGetPackagesArchiveProject); + Mkdirp(nuGetPackagesArchiveProject); + + Rmdir(nuGetPackagesArchiveFolder); + Mkdirp(nuGetPackagesArchiveFolder); + + dotnet.New() + .WorkingDirectory(nuGetPackagesArchiveProject) + .Execute() + .EnsureSuccessful(); + + dotnet.Restore("--packages", nuGetPackagesArchiveFolder) + .WorkingDirectory(nuGetPackagesArchiveProject) + .Execute() + .EnsureSuccessful(); + } + + private static void CompressNuGetPackagesArchive( + BuildTargetContext c, + DotNetCli dotnet, + string nuGetPackagesArchiveFolder, + string sdkOutputDirectory) + { + var configuration = c.BuildContext.Get("Configuration"); + var archiver = Path.Combine(Dirs.Output, "tools", $"Archiver{Constants.ExeSuffix}"); + var intermediateArchive = Path.Combine(Dirs.Intermediate, "nuGetPackagesArchive.lzma"); + var finalArchive = Path.Combine(sdkOutputDirectory, "nuGetPackagesArchive.lzma"); + + Rm(intermediateArchive); + Rm($"{intermediateArchive}.zip"); + + c.Info("Publishing Archiver"); + dotnet.Publish("--output", Path.Combine(Dirs.Output, "tools"), "--configuration", configuration) + .WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "tools", "Archiver")) + .Execute() + .EnsureSuccessful(); + + var packagesToArchive = new List { "-a", intermediateArchive }; + var nuGetPackagesArchiveDirectory = new DirectoryInfo(nuGetPackagesArchiveFolder); + foreach (var directory in nuGetPackagesArchiveDirectory.GetDirectories()) + { + packagesToArchive.Add(directory.FullName); + } + + Cmd(archiver, packagesToArchive) + .Execute(); + + File.Copy(intermediateArchive, finalArchive); } private static void RemoveAssetFromDepsPackages(string depsFile, string sectionName, string assetPath) diff --git a/build_projects/shared-build-targets-utils/Utils/DotNetCli.cs b/build_projects/shared-build-targets-utils/Utils/DotNetCli.cs index 2d9570388..82762ce56 100644 --- a/build_projects/shared-build-targets-utils/Utils/DotNetCli.cs +++ b/build_projects/shared-build-targets-utils/Utils/DotNetCli.cs @@ -38,6 +38,7 @@ namespace Microsoft.DotNet.Cli.Build public Command Pack(params string[] args) => Exec("pack", args); public Command Test(params string[] args) => Exec("test", args); public Command Publish(params string[] args) => Exec("publish", args); + public Command New(params string[] args) => Exec("new", args); public string GetRuntimeId() { diff --git a/src/Microsoft.DotNet.Archive/ConsoleProgressReport.cs b/src/Microsoft.DotNet.Archive/ConsoleProgressReport.cs new file mode 100644 index 000000000..a3e1b8a52 --- /dev/null +++ b/src/Microsoft.DotNet.Archive/ConsoleProgressReport.cs @@ -0,0 +1,51 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Diagnostics; + +namespace Microsoft.DotNet.Archive +{ + public class ConsoleProgressReport : IProgress + { + string currentPhase; + int lastLineLength = 0; + double lastProgress = -1; + Stopwatch stopwatch; + + public void Report(ProgressReport value) + { + long progress = (long)(100 * ((double)value.Ticks / value.Total)); + + if (progress == lastProgress && value.Phase == currentPhase) + { + return; + } + lastProgress = progress; + + lock (this) + { + string line = $"{value.Phase} {progress}%"; + if (value.Phase == currentPhase) + { + Console.Write(new string('\b', lastLineLength)); + + Console.Write(line); + lastLineLength = line.Length; + + if (progress == 100) + { + Console.WriteLine($" {stopwatch.ElapsedMilliseconds} ms"); + } + } + else + { + Console.Write(line); + currentPhase = value.Phase; + lastLineLength = line.Length; + stopwatch = Stopwatch.StartNew(); + } + } + } + } +} \ No newline at end of file diff --git a/src/dotnet-archive/Program.cs b/src/dotnet-archive/Program.cs index 448aabaa8..5457c8c7f 100644 --- a/src/dotnet-archive/Program.cs +++ b/src/dotnet-archive/Program.cs @@ -103,49 +103,6 @@ namespace Microsoft.DotNet.Tools.Archive #endif return 1; } - } - - public class ConsoleProgressReport : IProgress - { - string currentPhase; - int lastLineLength = 0; - double lastProgress = -1; - Stopwatch stopwatch; - - public void Report(ProgressReport value) - { - long progress = (long)(100 * ((double)value.Ticks / value.Total)); - - if (progress == lastProgress && value.Phase == currentPhase) - { - return; - } - lastProgress = progress; - - lock (this) - { - string line = $"{value.Phase} {progress}%"; - if (value.Phase == currentPhase) - { - Console.Write(new string('\b', lastLineLength)); - - Console.Write(line); - lastLineLength = line.Length; - - if (progress == 100) - { - Console.WriteLine($" {stopwatch.ElapsedMilliseconds} ms"); - } - } - else - { - Console.Write(line); - currentPhase = value.Phase; - lastLineLength = line.Length; - stopwatch = Stopwatch.StartNew(); - } - } - } - } + } } } diff --git a/tools/Archiver/project.json b/tools/Archiver/project.json new file mode 100644 index 000000000..fa12a278d --- /dev/null +++ b/tools/Archiver/project.json @@ -0,0 +1,20 @@ +{ + "buildOptions": { + "emitEntryPoint": true, + "compile": { + "include": [ + "../../src/dotnet-archive/*.cs", + "../../src/dotnet/CommandLine/*.cs" + ] + } + }, + "dependencies": { + "Microsoft.DotNet.Archive": { + "target": "project" + }, + "Microsoft.NETCore.App": "1.0.0-rc3-004391" + }, + "frameworks": { + "netcoreapp1.0": {} + } +}