Generating the archive in the sdk folder of stage2.

This commit is contained in:
Livar Cunha 2016-06-08 13:42:03 -07:00
parent 4c5f097d67
commit 5f220a1677
5 changed files with 168 additions and 51 deletions

View file

@ -107,9 +107,10 @@ 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)
{
@ -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>("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<string>("Configuration");
var buildVersion = c.BuildContext.Get<BuildVersion>("BuildVersion");
@ -263,6 +283,74 @@ namespace Microsoft.DotNet.Cli.Build
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<string>("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<string> { "-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)
{
JToken deps;

View file

@ -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()
{

View file

@ -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<ProgressReport>
{
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();
}
}
}
}
}

View file

@ -104,48 +104,5 @@ namespace Microsoft.DotNet.Tools.Archive
return 1;
}
}
public class ConsoleProgressReport : IProgress<ProgressReport>
{
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();
}
}
}
}
}
}

View file

@ -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": {}
}
}