Build Cleanup: Part 2 (#3890)
* Remove deprecated build_projects sources * Remove BuildSetup, StandardGoals, and Target Attributes * Incremental restore of tasks dll * CheckPreReq conforms with MSBuild Error Handling guidelines * Eliminate deprecated content * PR Feedback
This commit is contained in:
parent
354a43ff83
commit
24d2e638d5
31 changed files with 95 additions and 2111 deletions
|
@ -14,113 +14,96 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
{
|
||||
public override bool Execute()
|
||||
{
|
||||
Run(s => Log.LogMessage(s));
|
||||
|
||||
return true;
|
||||
return CheckCoreclrPlatformDependencies() &&
|
||||
CheckInstallerBuildPlatformDependencies() &&
|
||||
LocateStage0();
|
||||
}
|
||||
|
||||
public static void Run(Action<string> logInfo)
|
||||
private bool CheckCoreclrPlatformDependencies()
|
||||
{
|
||||
CheckCoreclrPlatformDependencies();
|
||||
CheckInstallerBuildPlatformDependencies();
|
||||
|
||||
LocateStage0(logInfo);
|
||||
return CheckUbuntuCoreclrAndCoreFxDependencies() &&
|
||||
CheckCentOSCoreclrAndCoreFxDependencies();
|
||||
}
|
||||
|
||||
private static void CheckCoreclrPlatformDependencies()
|
||||
private bool CheckInstallerBuildPlatformDependencies()
|
||||
{
|
||||
CheckUbuntuCoreclrAndCoreFxDependencies();
|
||||
CheckCentOSCoreclrAndCoreFxDependencies();
|
||||
return CheckUbuntuDebianPackageBuildDependencies();
|
||||
}
|
||||
|
||||
private static void CheckInstallerBuildPlatformDependencies()
|
||||
private bool CheckUbuntuCoreclrAndCoreFxDependencies()
|
||||
{
|
||||
CheckUbuntuDebianPackageBuildDependencies();
|
||||
}
|
||||
bool isSuccessful = true;
|
||||
|
||||
private static void CheckUbuntuCoreclrAndCoreFxDependencies()
|
||||
{
|
||||
if (CurrentPlatform.IsPlatform(BuildPlatform.Ubuntu, "14.04"))
|
||||
{
|
||||
var errorMessageBuilder = new StringBuilder();
|
||||
var stage0 = DotNetCli.Stage0.BinPath;
|
||||
|
||||
foreach (var package in PackageDependencies.UbuntuCoreclrAndCoreFxDependencies)
|
||||
{
|
||||
if (!AptDependencyUtility.PackageIsInstalled(package))
|
||||
{
|
||||
errorMessageBuilder.Append($"Error: Coreclr package dependency {package} missing.");
|
||||
errorMessageBuilder.Append(Environment.NewLine);
|
||||
errorMessageBuilder.Append($"-> install with apt-get install {package}");
|
||||
errorMessageBuilder.Append(Environment.NewLine);
|
||||
isSuccessful = false;
|
||||
|
||||
Log.LogError($"Coreclr package dependency {package} missing. Install with `apt-get install {package}`");
|
||||
}
|
||||
}
|
||||
|
||||
if (errorMessageBuilder.Length > 0)
|
||||
{
|
||||
throw new BuildFailureException(errorMessageBuilder.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
return isSuccessful;
|
||||
}
|
||||
|
||||
private static void CheckCentOSCoreclrAndCoreFxDependencies()
|
||||
private bool CheckCentOSCoreclrAndCoreFxDependencies()
|
||||
{
|
||||
var isSuccessful = true;
|
||||
|
||||
if (CurrentPlatform.IsPlatform(BuildPlatform.CentOS))
|
||||
{
|
||||
var errorMessageBuilder = new StringBuilder();
|
||||
|
||||
foreach (var package in PackageDependencies.CentosCoreclrAndCoreFxDependencies)
|
||||
{
|
||||
if (!YumDependencyUtility.PackageIsInstalled(package))
|
||||
{
|
||||
errorMessageBuilder.Append($"Error: Coreclr package dependency {package} missing.");
|
||||
errorMessageBuilder.Append(Environment.NewLine);
|
||||
errorMessageBuilder.Append($"-> install with yum install {package}");
|
||||
errorMessageBuilder.Append(Environment.NewLine);
|
||||
isSuccessful = false;
|
||||
|
||||
Log.LogError($"Coreclr package dependency {package} missing. Install with yum install {package}");
|
||||
}
|
||||
}
|
||||
|
||||
if (errorMessageBuilder.Length > 0)
|
||||
{
|
||||
throw new BuildFailureException(errorMessageBuilder.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
return isSuccessful;
|
||||
}
|
||||
|
||||
private static void CheckUbuntuDebianPackageBuildDependencies()
|
||||
private bool CheckUbuntuDebianPackageBuildDependencies()
|
||||
{
|
||||
var isSuccessful = true;
|
||||
|
||||
if (CurrentPlatform.IsPlatform(BuildPlatform.Ubuntu, "14.04"))
|
||||
{
|
||||
var messageBuilder = new StringBuilder();
|
||||
var aptDependencyUtility = new AptDependencyUtility();
|
||||
|
||||
|
||||
foreach (var package in PackageDependencies.DebianPackageBuildDependencies)
|
||||
{
|
||||
if (!AptDependencyUtility.PackageIsInstalled(package))
|
||||
{
|
||||
messageBuilder.Append($"Error: Debian package build dependency {package} missing.");
|
||||
messageBuilder.Append(Environment.NewLine);
|
||||
messageBuilder.Append($"-> install with apt-get install {package}");
|
||||
messageBuilder.Append(Environment.NewLine);
|
||||
isSuccessful = false;
|
||||
|
||||
Log.LogError($"Debian package build dependency {package} missing. Install with apt-get install {package}");
|
||||
}
|
||||
}
|
||||
|
||||
if (messageBuilder.Length > 0)
|
||||
{
|
||||
throw new BuildFailureException(messageBuilder.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
return isSuccessful;
|
||||
}
|
||||
|
||||
private static void LocateStage0(Action<string> logInfo)
|
||||
private bool LocateStage0()
|
||||
{
|
||||
// We should have been run in the repo root, so locate the stage 0 relative to current directory
|
||||
var stage0 = DotNetCli.Stage0.BinPath;
|
||||
|
||||
if (!Directory.Exists(stage0))
|
||||
{
|
||||
throw new BuildFailureException($"Stage 0 directory does not exist: {stage0}");
|
||||
Log.LogError($"Stage 0 directory does not exist: {stage0}");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Identify the version
|
||||
|
@ -128,11 +111,16 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
|
||||
if (string.IsNullOrEmpty(versionFile))
|
||||
{
|
||||
throw new Exception($"'.version' file not found in '{stage0}' folder");
|
||||
Log.LogError($"'.version' file not found in '{stage0}' folder");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
var version = File.ReadAllLines(versionFile);
|
||||
logInfo($"Using Stage 0 Version: {version[1]}");
|
||||
|
||||
Log.LogMessage($"Using Stage 0 Version: {version[1]}");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
// 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.IO;
|
||||
using Microsoft.DotNet.InternalAbstractions;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Build
|
||||
{
|
||||
public static class CliDirs
|
||||
{
|
||||
public static readonly string CoreSetupDownload = Path.Combine(
|
||||
Dirs.Intermediate,
|
||||
"coreSetupDownload",
|
||||
CliDependencyVersions.SharedFrameworkVersion);
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
// 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 Microsoft.DotNet.Cli.Build.Framework;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Build
|
||||
{
|
||||
public static class CliMonikers
|
||||
{
|
||||
public static string GetSdkDebianPackageName(BuildTargetContext c)
|
||||
{
|
||||
var nugetVersion = c.BuildContext.Get<BuildVersion>("BuildVersion").NuGetVersion;
|
||||
|
||||
return $"dotnet-dev-{nugetVersion}";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,391 +0,0 @@
|
|||
// 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.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using Microsoft.Build.Utilities;
|
||||
using Microsoft.DotNet.Cli.Build.Framework;
|
||||
using Microsoft.DotNet.InternalAbstractions;
|
||||
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
|
||||
using static Microsoft.DotNet.Cli.Build.FS;
|
||||
using static Microsoft.DotNet.Cli.Build.Utils;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Build
|
||||
{
|
||||
public class PrepareTargets
|
||||
{
|
||||
|
||||
// All major targets will depend on this in order to ensure variables are set up right if they are run independently
|
||||
public static BuildTargetResult Init(BuildTargetContext c)
|
||||
{
|
||||
GenerateVersions(c);
|
||||
CheckPrereqs.Run(s => c.Info(s));
|
||||
ExpectedBuildArtifacts(c);
|
||||
SetTelemetryProfile(c);
|
||||
|
||||
var configEnv = Environment.GetEnvironmentVariable("CONFIGURATION");
|
||||
|
||||
if (string.IsNullOrEmpty(configEnv))
|
||||
{
|
||||
configEnv = "Debug";
|
||||
}
|
||||
|
||||
c.BuildContext["Configuration"] = configEnv;
|
||||
c.BuildContext["Channel"] = Environment.GetEnvironmentVariable("CHANNEL");
|
||||
|
||||
c.Info($"Building {c.BuildContext["Configuration"]} to: {Dirs.Output}");
|
||||
c.Info("Build Environment:");
|
||||
c.Info($" Operating System: {RuntimeEnvironment.OperatingSystem} {RuntimeEnvironment.OperatingSystemVersion}");
|
||||
c.Info($" Platform: {RuntimeEnvironment.OperatingSystemPlatform}");
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
public static BuildTargetResult GenerateVersions(BuildTargetContext c)
|
||||
{
|
||||
var commitCount = GitUtils.GetCommitCount();
|
||||
var commitHash = GitUtils.GetCommitHash();
|
||||
|
||||
var branchInfo = ReadBranchInfo(c, Path.Combine(c.BuildContext.BuildDirectory, "branchinfo.txt"));
|
||||
var buildVersion = new BuildVersion()
|
||||
{
|
||||
Major = int.Parse(branchInfo["MAJOR_VERSION"]),
|
||||
Minor = int.Parse(branchInfo["MINOR_VERSION"]),
|
||||
Patch = int.Parse(branchInfo["PATCH_VERSION"]),
|
||||
ReleaseSuffix = branchInfo["RELEASE_SUFFIX"],
|
||||
CommitCount = commitCount
|
||||
};
|
||||
c.BuildContext["BuildVersion"] = buildVersion;
|
||||
|
||||
c.BuildContext["BranchName"] = branchInfo["BRANCH_NAME"];
|
||||
c.BuildContext["CommitHash"] = commitHash;
|
||||
|
||||
c.Info($"Building Version: {buildVersion.SimpleVersion} (NuGet Packages: {buildVersion.NuGetVersion})");
|
||||
c.Info($"From Commit: {commitHash}");
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
public static BuildTargetResult ZipTemplates(BuildTargetContext c)
|
||||
{
|
||||
var templateDirectories = Directory.GetDirectories(
|
||||
Path.Combine(Dirs.RepoRoot, "src", "dotnet", "commands", "dotnet-new"));
|
||||
|
||||
foreach (var directory in templateDirectories)
|
||||
{
|
||||
var zipFile = Path.Combine(Path.GetDirectoryName(directory), Path.GetFileName(directory) + ".zip");
|
||||
if (File.Exists(zipFile))
|
||||
{
|
||||
File.Delete(zipFile);
|
||||
}
|
||||
|
||||
ZipFile.CreateFromDirectory(directory, zipFile);
|
||||
}
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static BuildTargetResult ExpectedBuildArtifacts(BuildTargetContext c)
|
||||
{
|
||||
var config = Environment.GetEnvironmentVariable("CONFIGURATION");
|
||||
var versionBadgeName = $"{Monikers.GetBadgeMoniker()}_{config}_version_badge.svg";
|
||||
c.BuildContext["VersionBadge"] = Path.Combine(Dirs.Output, versionBadgeName);
|
||||
|
||||
var cliVersion = c.BuildContext.Get<BuildVersion>("BuildVersion").NuGetVersion;
|
||||
var sharedFrameworkVersion = CliDependencyVersions.SharedFrameworkVersion;
|
||||
var hostVersion = CliDependencyVersions.SharedHostVersion;
|
||||
var hostFxrVersion = CliDependencyVersions.HostFxrVersion;
|
||||
|
||||
// Generated Installers + Archives
|
||||
AddInstallerArtifactToContext(c, "dotnet-sdk", "Sdk", cliVersion);
|
||||
AddInstallerArtifactToContext(c, "dotnet-dev", "CombinedFrameworkSDKHost", cliVersion);
|
||||
AddInstallerArtifactToContext(c, "dotnet-sharedframework-sdk", "CombinedFrameworkSDK", cliVersion);
|
||||
AddInstallerArtifactToContext(c, "dotnet-sdk-debug", "SdkSymbols", cliVersion);
|
||||
|
||||
//Downloaded Installers + Archives
|
||||
AddInstallerArtifactToContext(c, "dotnet-host", "SharedHost", hostVersion);
|
||||
AddInstallerArtifactToContext(c, "dotnet-hostfxr", "HostFxr", hostFxrVersion);
|
||||
AddInstallerArtifactToContext(c, "dotnet-sharedframework", "SharedFramework", sharedFrameworkVersion);
|
||||
AddInstallerArtifactToContext(c, "dotnet", "CombinedFrameworkHost", sharedFrameworkVersion);
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
public static BuildTargetResult DownloadHostAndSharedFxArtifacts(BuildTargetContext c)
|
||||
{
|
||||
ExpectedBuildArtifacts(c);
|
||||
DownloadHostAndSharedFxArchives(c);
|
||||
DownloadHostAndSharedFxInstallers(c);
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
public static BuildTargetResult DownloadHostAndSharedFxArchives(BuildTargetContext c)
|
||||
{
|
||||
var sharedFrameworkVersion = CliDependencyVersions.SharedFrameworkVersion;
|
||||
var sharedFrameworkChannel = CliDependencyVersions.SharedFrameworkChannel;
|
||||
|
||||
var combinedSharedHostAndFrameworkArchiveDownloadFile =
|
||||
Path.Combine(CliDirs.CoreSetupDownload, "combinedSharedHostAndFrameworkArchive");
|
||||
|
||||
Mkdirp(Path.GetDirectoryName(combinedSharedHostAndFrameworkArchiveDownloadFile));
|
||||
|
||||
if (!File.Exists(combinedSharedHostAndFrameworkArchiveDownloadFile))
|
||||
{
|
||||
// Needed for computing the blob path
|
||||
var combinedSharedHostAndFrameworkArchiveBuildContextFile =
|
||||
c.BuildContext.Get<string>("CombinedFrameworkHostCompressedFile");
|
||||
|
||||
AzurePublisher.DownloadFile(
|
||||
CalculateArchiveBlob(
|
||||
combinedSharedHostAndFrameworkArchiveBuildContextFile,
|
||||
sharedFrameworkChannel,
|
||||
sharedFrameworkVersion),
|
||||
combinedSharedHostAndFrameworkArchiveDownloadFile).Wait();
|
||||
|
||||
|
||||
// Unpack the combined archive to shared framework publish directory
|
||||
Rmdir(Dirs.SharedFrameworkPublish);
|
||||
Mkdirp(Dirs.SharedFrameworkPublish);
|
||||
if (CurrentPlatform.IsWindows)
|
||||
{
|
||||
ZipFile.ExtractToDirectory(combinedSharedHostAndFrameworkArchiveDownloadFile, Dirs.SharedFrameworkPublish);
|
||||
}
|
||||
else
|
||||
{
|
||||
Exec("tar", "xf", combinedSharedHostAndFrameworkArchiveDownloadFile, "-C", Dirs.SharedFrameworkPublish);
|
||||
}
|
||||
}
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
public static BuildTargetResult DownloadHostAndSharedFxInstallers(BuildTargetContext c)
|
||||
{
|
||||
if (CurrentPlatform.IsAnyPlatform(BuildPlatform.Windows, BuildPlatform.OSX, BuildPlatform.Ubuntu))
|
||||
{
|
||||
var sharedFrameworkVersion = CliDependencyVersions.SharedFrameworkVersion;
|
||||
var hostVersion = CliDependencyVersions.SharedHostVersion;
|
||||
var hostFxrVersion = CliDependencyVersions.HostFxrVersion;
|
||||
|
||||
var sharedFrameworkChannel = CliDependencyVersions.SharedFrameworkChannel;
|
||||
var sharedHostChannel = CliDependencyVersions.SharedHostChannel;
|
||||
var hostFxrChannel = CliDependencyVersions.HostFxrChannel;
|
||||
|
||||
var sharedFrameworkInstallerDownloadFile = Path.Combine(CliDirs.CoreSetupDownload, "sharedFrameworkInstaller");
|
||||
var sharedHostInstallerDownloadFile = Path.Combine(CliDirs.CoreSetupDownload, "sharedHostInstaller");
|
||||
var hostFxrInstallerDownloadFile = Path.Combine(CliDirs.CoreSetupDownload, "hostFxrInstaller");
|
||||
|
||||
Mkdirp(Path.GetDirectoryName(sharedFrameworkInstallerDownloadFile));
|
||||
Mkdirp(Path.GetDirectoryName(sharedHostInstallerDownloadFile));
|
||||
Mkdirp(Path.GetDirectoryName(hostFxrInstallerDownloadFile));
|
||||
|
||||
if (!File.Exists(sharedFrameworkInstallerDownloadFile))
|
||||
{
|
||||
var sharedFrameworkInstallerDestinationFile = c.BuildContext.Get<string>("SharedFrameworkInstallerFile");
|
||||
Mkdirp(Path.GetDirectoryName(sharedFrameworkInstallerDestinationFile));
|
||||
|
||||
AzurePublisher.DownloadFile(
|
||||
CalculateInstallerBlob(
|
||||
sharedFrameworkInstallerDestinationFile,
|
||||
sharedFrameworkChannel,
|
||||
sharedFrameworkVersion),
|
||||
sharedFrameworkInstallerDownloadFile).Wait();
|
||||
|
||||
File.Copy(sharedFrameworkInstallerDownloadFile, sharedFrameworkInstallerDestinationFile, true);
|
||||
}
|
||||
|
||||
if (!File.Exists(sharedHostInstallerDownloadFile))
|
||||
{
|
||||
var sharedHostInstallerDestinationFile = c.BuildContext.Get<string>("SharedHostInstallerFile");
|
||||
Mkdirp(Path.GetDirectoryName(sharedHostInstallerDestinationFile));
|
||||
|
||||
AzurePublisher.DownloadFile(
|
||||
CalculateInstallerBlob(
|
||||
sharedHostInstallerDestinationFile,
|
||||
sharedHostChannel,
|
||||
hostVersion),
|
||||
sharedHostInstallerDownloadFile).Wait();
|
||||
|
||||
File.Copy(sharedHostInstallerDownloadFile, sharedHostInstallerDestinationFile, true);
|
||||
}
|
||||
|
||||
if (!File.Exists(hostFxrInstallerDownloadFile))
|
||||
{
|
||||
var hostFxrInstallerDestinationFile = c.BuildContext.Get<string>("HostFxrInstallerFile");
|
||||
Mkdirp(Path.GetDirectoryName(hostFxrInstallerDestinationFile));
|
||||
|
||||
AzurePublisher.DownloadFile(
|
||||
CalculateInstallerBlob(
|
||||
hostFxrInstallerDestinationFile,
|
||||
hostFxrChannel,
|
||||
hostFxrVersion),
|
||||
hostFxrInstallerDownloadFile).Wait();
|
||||
|
||||
File.Copy(hostFxrInstallerDownloadFile, hostFxrInstallerDestinationFile, true);
|
||||
}
|
||||
}
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
public static BuildTargetResult CheckPackageCache(BuildTargetContext c)
|
||||
{
|
||||
var ciBuild = string.Equals(Environment.GetEnvironmentVariable("CI_BUILD"), "1", StringComparison.Ordinal);
|
||||
|
||||
// Always set the package cache location local to the build
|
||||
Environment.SetEnvironmentVariable("NUGET_PACKAGES", Dirs.NuGetPackages);
|
||||
|
||||
CleanNuGetTempCache();
|
||||
|
||||
// Determine cache expiration time
|
||||
var cacheExpiration = 7 * 24; // cache expiration in hours
|
||||
var cacheExpirationStr = Environment.GetEnvironmentVariable("NUGET_PACKAGES_CACHE_TIME_LIMIT");
|
||||
if (!string.IsNullOrEmpty(cacheExpirationStr))
|
||||
{
|
||||
cacheExpiration = int.Parse(cacheExpirationStr);
|
||||
}
|
||||
|
||||
if (ciBuild)
|
||||
{
|
||||
var cacheTimeFile = Path.Combine(Dirs.NuGetPackages, "packageCacheTime.txt");
|
||||
|
||||
DateTime? cacheTime = null;
|
||||
try
|
||||
{
|
||||
// Read the cache file
|
||||
if (File.Exists(cacheTimeFile))
|
||||
{
|
||||
var content = File.ReadAllText(cacheTimeFile);
|
||||
if (!string.IsNullOrEmpty(content))
|
||||
{
|
||||
cacheTime = DateTime.ParseExact("O", content, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
c.Warn($"Error reading NuGet cache time file, leaving the cache alone");
|
||||
c.Warn($"Error Detail: {ex.ToString()}");
|
||||
}
|
||||
|
||||
if (cacheTime == null || (cacheTime.Value.AddHours(cacheExpiration) < DateTime.UtcNow))
|
||||
{
|
||||
// Cache has expired or the status is unknown, clear it and write the file
|
||||
c.Info("Clearing NuGet cache");
|
||||
Rmdir(Dirs.NuGetPackages);
|
||||
Mkdirp(Dirs.NuGetPackages);
|
||||
File.WriteAllText(cacheTimeFile, DateTime.UtcNow.ToString("O"));
|
||||
}
|
||||
}
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
public static BuildTargetResult RestorePackages(BuildTargetContext c)
|
||||
{
|
||||
CheckPackageCache(c);
|
||||
|
||||
var dotnet = DotNetCli.Stage0;
|
||||
|
||||
dotnet.Restore("--verbosity", "verbose", "--disable-parallel")
|
||||
.WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "src"))
|
||||
.Execute()
|
||||
.EnsureSuccessful();
|
||||
dotnet.Restore("--verbosity", "verbose", "--disable-parallel", "--infer-runtimes")
|
||||
.WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "tools"))
|
||||
.Execute()
|
||||
.EnsureSuccessful();
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
public static BuildTargetResult SetTelemetryProfile(BuildTargetContext c)
|
||||
{
|
||||
var gitResult = Cmd("git", "rev-parse", "HEAD")
|
||||
.CaptureStdOut()
|
||||
.Execute();
|
||||
gitResult.EnsureSuccessful();
|
||||
|
||||
var commitHash = gitResult.StdOut.Trim();
|
||||
|
||||
Environment.SetEnvironmentVariable("DOTNET_CLI_TELEMETRY_PROFILE", $"https://github.com/dotnet/cli;{commitHash}");
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
private static IDictionary<string, string> ReadBranchInfo(BuildTargetContext c, string path)
|
||||
{
|
||||
var lines = File.ReadAllLines(path);
|
||||
var dict = new Dictionary<string, string>();
|
||||
c.Verbose("Branch Info:");
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (!line.Trim().StartsWith("#") && !string.IsNullOrWhiteSpace(line))
|
||||
{
|
||||
var splat = line.Split(new[] { '=' }, 2);
|
||||
dict[splat[0]] = splat[1];
|
||||
c.Verbose($" {splat[0]} = {splat[1]}");
|
||||
}
|
||||
}
|
||||
return dict;
|
||||
}
|
||||
|
||||
private static void AddInstallerArtifactToContext(
|
||||
BuildTargetContext c,
|
||||
string artifactPrefix,
|
||||
string contextPrefix,
|
||||
string version)
|
||||
{
|
||||
var productName = Monikers.GetProductMoniker(c, artifactPrefix, version);
|
||||
|
||||
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:
|
||||
if (contextPrefix.Contains("Combined"))
|
||||
{
|
||||
installer = productName + ".exe";
|
||||
}
|
||||
else
|
||||
{
|
||||
installer = productName + ".msi";
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// The following CalculateBlob methods are temporary until the core-setup repo up-takes the new Azure Publish layout and
|
||||
// CLI consumes newer Shared FX versions.
|
||||
private static string CalculateArchiveBlob(string archiveFile, string channel, string version)
|
||||
{
|
||||
return $"{channel}/Binaries/{version}/{Path.GetFileName(archiveFile)}";
|
||||
}
|
||||
|
||||
private static string CalculateInstallerBlob(string installerFile, string channel, string version)
|
||||
{
|
||||
return $"{channel}/Installers/{version}/{Path.GetFileName(installerFile)}";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,295 +0,0 @@
|
|||
// 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.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.DotNet.Cli.Build.Framework;
|
||||
using Microsoft.Build.Utilities;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Build
|
||||
{
|
||||
public class PublishTargets : Task
|
||||
{
|
||||
private static AzurePublisher AzurePublisherTool { get; set; }
|
||||
|
||||
private static DebRepoPublisher DebRepoPublisherTool { get; set; }
|
||||
|
||||
private static string Channel { get; set; }
|
||||
|
||||
private static string CommitHash { get; set; }
|
||||
|
||||
private static string CliNuGetVersion { get; set; }
|
||||
|
||||
private static string SharedFrameworkNugetVersion { get; set; }
|
||||
|
||||
public override bool Execute()
|
||||
{
|
||||
BuildContext context = new BuildSetup("MSBuild").UseAllTargetsFromAssembly<PublishTargets>().CreateBuildContext();
|
||||
BuildTargetContext c = new BuildTargetContext(context, null, null);
|
||||
|
||||
return Publish(c).Success;
|
||||
}
|
||||
|
||||
public static BuildTargetResult InitPublish(BuildTargetContext c)
|
||||
{
|
||||
AzurePublisherTool = new AzurePublisher();
|
||||
DebRepoPublisherTool = new DebRepoPublisher(Dirs.Packages);
|
||||
|
||||
CliNuGetVersion = c.BuildContext.Get<BuildVersion>("BuildVersion").NuGetVersion;
|
||||
SharedFrameworkNugetVersion = CliDependencyVersions.SharedFrameworkVersion;
|
||||
Channel = c.BuildContext.Get<string>("Channel");
|
||||
CommitHash = c.BuildContext.Get<string>("CommitHash");
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
public static BuildTargetResult Publish(BuildTargetContext c)
|
||||
{
|
||||
if (EnvVars.GetBool("PUBLISH_TO_AZURE_BLOB")) // This is set by CI systems
|
||||
{
|
||||
PrepareTargets.Init(c);
|
||||
|
||||
InitPublish(c);
|
||||
PublishArtifacts(c);
|
||||
FinalizeBuild(c);
|
||||
}
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
public static BuildTargetResult FinalizeBuild(BuildTargetContext c)
|
||||
{
|
||||
if (CheckIfAllBuildsHavePublished())
|
||||
{
|
||||
string targetContainer = $"{AzurePublisher.Product.Sdk}/{Channel}";
|
||||
string targetVersionFile = $"{targetContainer}/{CommitHash}";
|
||||
string semaphoreBlob = $"{targetContainer}/publishSemaphore";
|
||||
AzurePublisherTool.CreateBlobIfNotExists(semaphoreBlob);
|
||||
string leaseId = AzurePublisherTool.AcquireLeaseOnBlob(semaphoreBlob);
|
||||
|
||||
// Prevent race conditions by dropping a version hint of what version this is. If we see this file
|
||||
// and it is the same as our version then we know that a race happened where two+ builds finished
|
||||
// at the same time and someone already took care of publishing and we have no work to do.
|
||||
if (AzurePublisherTool.IsLatestSpecifiedVersion(targetVersionFile))
|
||||
{
|
||||
AzurePublisherTool.ReleaseLeaseOnBlob(semaphoreBlob, leaseId);
|
||||
return c.Success();
|
||||
}
|
||||
else
|
||||
{
|
||||
Regex versionFileRegex = new Regex(@"(?<CommitHash>[\w\d]{40})");
|
||||
|
||||
// Delete old version files
|
||||
AzurePublisherTool.ListBlobs(targetContainer)
|
||||
.Where(s => versionFileRegex.IsMatch(s))
|
||||
.ToList()
|
||||
.ForEach(f => AzurePublisherTool.TryDeleteBlob(f));
|
||||
|
||||
// Drop the version file signaling such for any race-condition builds (see above comment).
|
||||
AzurePublisherTool.DropLatestSpecifiedVersion(targetVersionFile);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
CopyBlobsToLatest(targetContainer);
|
||||
|
||||
string cliVersion = Utils.GetCliVersionFileContent(c);
|
||||
AzurePublisherTool.PublishStringToBlob($"{targetContainer}/latest.version", cliVersion);
|
||||
|
||||
UpdateVersionsRepo(c);
|
||||
}
|
||||
finally
|
||||
{
|
||||
AzurePublisherTool.ReleaseLeaseOnBlob(semaphoreBlob, leaseId);
|
||||
}
|
||||
}
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
private static void CopyBlobsToLatest(string destinationFolder)
|
||||
{
|
||||
foreach (string blob in AzurePublisherTool.ListBlobs(AzurePublisher.Product.Sdk, CliNuGetVersion))
|
||||
{
|
||||
string targetName = Path.GetFileName(blob)
|
||||
.Replace(CliNuGetVersion, "latest");
|
||||
|
||||
string target = $"{destinationFolder}/{targetName}";
|
||||
AzurePublisherTool.CopyBlob(blob, target);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool CheckIfAllBuildsHavePublished()
|
||||
{
|
||||
Dictionary<string, bool> badges = new Dictionary<string, bool>()
|
||||
{
|
||||
{ "Windows_x86", false },
|
||||
{ "Windows_x64", false },
|
||||
{ "Ubuntu_x64", false },
|
||||
{ "Ubuntu_16_04_x64", false },
|
||||
{ "RHEL_x64", false },
|
||||
{ "OSX_x64", false },
|
||||
{ "Debian_x64", false },
|
||||
{ "CentOS_x64", false },
|
||||
{ "Fedora_23_x64", false },
|
||||
{ "openSUSE_13_2_x64", false }
|
||||
};
|
||||
|
||||
var versionBadgeName = $"{Monikers.GetBadgeMoniker()}";
|
||||
if (!badges.ContainsKey(versionBadgeName))
|
||||
{
|
||||
throw new ArgumentException($"A new OS build '{versionBadgeName}' was added without adding the moniker to the {nameof(badges)} lookup");
|
||||
}
|
||||
|
||||
IEnumerable<string> blobs = AzurePublisherTool.ListBlobs(AzurePublisher.Product.Sdk, CliNuGetVersion);
|
||||
foreach (string file in blobs)
|
||||
{
|
||||
string name = Path.GetFileName(file);
|
||||
foreach (string img in badges.Keys)
|
||||
{
|
||||
if ((name.StartsWith($"{img}")) && (name.EndsWith(".svg")))
|
||||
{
|
||||
badges[img] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return badges.Values.All(v => v);
|
||||
}
|
||||
|
||||
public static BuildTargetResult PublishArtifacts(BuildTargetContext c)
|
||||
{
|
||||
PublishInstallerFilesToAzure(c);
|
||||
PublishArchivesToAzure(c);
|
||||
PublishDebFilesToDebianRepo(c);
|
||||
PublishCliVersionBadge(c);
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
public static BuildTargetResult PublishInstallerFilesToAzure(BuildTargetContext c)
|
||||
{
|
||||
PublishSdkInstallerFileToAzure(c);
|
||||
PublishCombinedFrameworkSDKHostInstallerFileToAzure(c);
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
public static BuildTargetResult PublishArchivesToAzure(BuildTargetContext c)
|
||||
{
|
||||
PublishCombinedHostFrameworkSdkArchiveToAzure(c);
|
||||
PublishCombinedFrameworkSDKArchiveToAzure(c);
|
||||
PublishSDKSymbolsArchiveToAzure(c);
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
public static BuildTargetResult PublishDebFilesToDebianRepo(BuildTargetContext c)
|
||||
{
|
||||
if (CurrentPlatform.IsPlatform(BuildPlatform.Ubuntu))
|
||||
{
|
||||
PublishSdkDebToDebianRepo(c);
|
||||
}
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
public static BuildTargetResult PublishCliVersionBadge(BuildTargetContext c)
|
||||
{
|
||||
var versionBadge = c.BuildContext.Get<string>("VersionBadge");
|
||||
UploadFile(versionBadge);
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
public static BuildTargetResult PublishSdkInstallerFileToAzure(BuildTargetContext c)
|
||||
{
|
||||
if (CurrentPlatform.IsPlatform(BuildPlatform.Ubuntu))
|
||||
{
|
||||
var installerFile = c.BuildContext.Get<string>("SdkInstallerFile");
|
||||
UploadFile(installerFile);
|
||||
}
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
public static BuildTargetResult PublishCombinedFrameworkSDKHostInstallerFileToAzure(BuildTargetContext c)
|
||||
{
|
||||
if (CurrentPlatform.IsAnyPlatform(BuildPlatform.Windows, BuildPlatform.OSX))
|
||||
{
|
||||
var installerFile = c.BuildContext.Get<string>("CombinedFrameworkSDKHostInstallerFile");
|
||||
UploadFile(installerFile);
|
||||
}
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
public static BuildTargetResult PublishCombinedFrameworkSDKArchiveToAzure(BuildTargetContext c)
|
||||
{
|
||||
if (CurrentPlatform.IsPlatform(BuildPlatform.Windows))
|
||||
{
|
||||
var archiveFile = c.BuildContext.Get<string>("CombinedFrameworkSDKCompressedFile");
|
||||
UploadFile(archiveFile);
|
||||
}
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
public static BuildTargetResult PublishCombinedHostFrameworkSdkArchiveToAzure(BuildTargetContext c)
|
||||
{
|
||||
var archiveFile = c.BuildContext.Get<string>("CombinedFrameworkSDKHostCompressedFile");
|
||||
UploadFile(archiveFile);
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
public static BuildTargetResult PublishSDKSymbolsArchiveToAzure(BuildTargetContext c)
|
||||
{
|
||||
var archiveFile = c.BuildContext.Get<string>("SdkSymbolsCompressedFile");
|
||||
UploadFile(archiveFile);
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
public static BuildTargetResult PublishSdkDebToDebianRepo(BuildTargetContext c)
|
||||
{
|
||||
if (CurrentPlatform.IsPlatform(BuildPlatform.Ubuntu))
|
||||
{
|
||||
var version = CliNuGetVersion;
|
||||
|
||||
var packageName = CliMonikers.GetSdkDebianPackageName(c);
|
||||
var installerFile = c.BuildContext.Get<string>("SdkInstallerFile");
|
||||
var uploadUrl = AzurePublisher.CalculateFullUrlForFile(installerFile, AzurePublisher.Product.Sdk, version);
|
||||
|
||||
DebRepoPublisherTool.PublishDebFileToDebianRepo(
|
||||
packageName,
|
||||
version,
|
||||
uploadUrl);
|
||||
}
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
private static void UpdateVersionsRepo(BuildTargetContext c)
|
||||
{
|
||||
string githubAuthToken = EnvVars.EnsureVariable("GITHUB_PASSWORD");
|
||||
string nupkgFilePath = Dirs.Packages;
|
||||
string branchName = c.BuildContext.Get<string>("BranchName");
|
||||
string versionsRepoPath = $"build-info/dotnet/cli/{branchName}/Latest";
|
||||
|
||||
VersionRepoUpdater repoUpdater = new VersionRepoUpdater(githubAuthToken);
|
||||
repoUpdater.UpdatePublishedVersions(nupkgFilePath, versionsRepoPath).Wait();
|
||||
}
|
||||
|
||||
private static string UploadFile(string file)
|
||||
{
|
||||
return AzurePublisherTool.UploadFile(file, AzurePublisher.Product.Sdk, CliNuGetVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue