2016-04-07 00:45:38 +00:00
|
|
|
|
using System;
|
2016-02-02 18:04:50 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.IO;
|
2016-03-18 04:45:03 +00:00
|
|
|
|
using System.Linq;
|
2016-02-02 18:04:50 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
2016-02-18 19:39:36 +00:00
|
|
|
|
using System.Text;
|
2016-04-07 00:45:38 +00:00
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using Microsoft.DotNet.Cli.Build.Framework;
|
2016-04-28 23:30:32 +00:00
|
|
|
|
using Microsoft.DotNet.InternalAbstractions;
|
2016-04-07 00:45:38 +00:00
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
|
2016-02-02 18:04:50 +00:00
|
|
|
|
using static Microsoft.DotNet.Cli.Build.FS;
|
|
|
|
|
using static Microsoft.DotNet.Cli.Build.Utils;
|
2016-05-16 22:30:53 +00:00
|
|
|
|
using System.IO.Compression;
|
2016-02-02 18:04:50 +00:00
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Cli.Build
|
|
|
|
|
{
|
|
|
|
|
public class PrepareTargets
|
|
|
|
|
{
|
2016-05-27 19:37:17 +00:00
|
|
|
|
[Target(nameof(Init), nameof(DownloadHostAndSharedFxArtifacts), nameof(RestorePackages), nameof(ZipTemplates))]
|
2016-02-02 18:04:50 +00:00
|
|
|
|
public static BuildTargetResult Prepare(BuildTargetContext c) => c.Success();
|
|
|
|
|
|
2016-02-20 01:00:41 +00:00
|
|
|
|
[Target(nameof(CheckPrereqCmakePresent), nameof(CheckPlatformDependencies))]
|
2016-02-18 19:39:36 +00:00
|
|
|
|
public static BuildTargetResult CheckPrereqs(BuildTargetContext c) => c.Success();
|
|
|
|
|
|
2016-03-07 22:52:41 +00:00
|
|
|
|
[Target(nameof(CheckCoreclrPlatformDependencies), nameof(CheckInstallerBuildPlatformDependencies))]
|
2016-02-20 01:00:41 +00:00
|
|
|
|
public static BuildTargetResult CheckPlatformDependencies(BuildTargetContext c) => c.Success();
|
|
|
|
|
|
2016-03-07 22:52:41 +00:00
|
|
|
|
[Target(nameof(CheckUbuntuCoreclrAndCoreFxDependencies), nameof(CheckCentOSCoreclrAndCoreFxDependencies))]
|
2016-02-20 01:00:41 +00:00
|
|
|
|
public static BuildTargetResult CheckCoreclrPlatformDependencies(BuildTargetContext c) => c.Success();
|
|
|
|
|
|
|
|
|
|
[Target(nameof(CheckUbuntuDebianPackageBuildDependencies))]
|
|
|
|
|
public static BuildTargetResult CheckInstallerBuildPlatformDependencies(BuildTargetContext c) => c.Success();
|
|
|
|
|
|
2016-02-02 18:04:50 +00:00
|
|
|
|
// All major targets will depend on this in order to ensure variables are set up right if they are run independently
|
2016-05-12 00:20:40 +00:00
|
|
|
|
[Target(
|
2016-05-27 19:37:17 +00:00
|
|
|
|
nameof(GenerateVersions),
|
|
|
|
|
nameof(CheckPrereqs),
|
|
|
|
|
nameof(LocateStage0),
|
2016-05-25 16:21:08 +00:00
|
|
|
|
nameof(ExpectedBuildArtifacts),
|
|
|
|
|
nameof(SetTelemetryProfile))]
|
2016-02-02 18:04:50 +00:00
|
|
|
|
public static BuildTargetResult Init(BuildTargetContext c)
|
|
|
|
|
{
|
|
|
|
|
var configEnv = Environment.GetEnvironmentVariable("CONFIGURATION");
|
|
|
|
|
|
2016-02-15 17:42:17 +00:00
|
|
|
|
if (string.IsNullOrEmpty(configEnv))
|
2016-02-02 18:04:50 +00:00
|
|
|
|
{
|
|
|
|
|
configEnv = "Debug";
|
|
|
|
|
}
|
2016-02-15 17:42:17 +00:00
|
|
|
|
|
2016-02-02 18:04:50 +00:00
|
|
|
|
c.BuildContext["Configuration"] = configEnv;
|
2016-03-07 22:52:41 +00:00
|
|
|
|
c.BuildContext["Channel"] = Environment.GetEnvironmentVariable("CHANNEL");
|
2016-02-02 18:04:50 +00:00
|
|
|
|
|
|
|
|
|
c.Info($"Building {c.BuildContext["Configuration"]} to: {Dirs.Output}");
|
|
|
|
|
c.Info("Build Environment:");
|
2016-04-28 23:30:32 +00:00
|
|
|
|
c.Info($" Operating System: {RuntimeEnvironment.OperatingSystem} {RuntimeEnvironment.OperatingSystemVersion}");
|
|
|
|
|
c.Info($" Platform: {RuntimeEnvironment.OperatingSystemPlatform}");
|
2016-02-02 18:04:50 +00:00
|
|
|
|
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Target]
|
|
|
|
|
public static BuildTargetResult GenerateVersions(BuildTargetContext c)
|
|
|
|
|
{
|
2016-05-20 00:07:33 +00:00
|
|
|
|
var commitCount = GitUtils.GetCommitCount();
|
|
|
|
|
var commitHash = GitUtils.GetCommitHash();
|
2016-02-02 18:04:50 +00:00
|
|
|
|
|
|
|
|
|
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;
|
2016-06-08 22:59:58 +00:00
|
|
|
|
|
|
|
|
|
c.BuildContext["BranchName"] = branchInfo["BRANCH_NAME"];
|
2016-02-02 18:04:50 +00:00
|
|
|
|
c.BuildContext["CommitHash"] = commitHash;
|
|
|
|
|
|
|
|
|
|
c.Info($"Building Version: {buildVersion.SimpleVersion} (NuGet Packages: {buildVersion.NuGetVersion})");
|
|
|
|
|
c.Info($"From Commit: {commitHash}");
|
|
|
|
|
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-27 19:37:17 +00:00
|
|
|
|
[Target]
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-02 18:04:50 +00:00
|
|
|
|
[Target]
|
|
|
|
|
public static BuildTargetResult LocateStage0(BuildTargetContext c)
|
|
|
|
|
{
|
|
|
|
|
// 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))
|
|
|
|
|
{
|
|
|
|
|
return c.Failed($"Stage 0 directory does not exist: {stage0}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Identify the version
|
2016-03-18 04:45:03 +00:00
|
|
|
|
string versionFile = Directory.GetFiles(stage0, ".version", SearchOption.AllDirectories).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(versionFile))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"'.version' file not found in '{stage0}' folder");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var version = File.ReadAllLines(versionFile);
|
2016-02-02 18:04:50 +00:00
|
|
|
|
c.Info($"Using Stage 0 Version: {version[1]}");
|
|
|
|
|
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-07 20:20:50 +00:00
|
|
|
|
[Target]
|
|
|
|
|
public static BuildTargetResult ExpectedBuildArtifacts(BuildTargetContext c)
|
|
|
|
|
{
|
|
|
|
|
var config = Environment.GetEnvironmentVariable("CONFIGURATION");
|
2016-05-30 05:38:14 +00:00
|
|
|
|
var versionBadgeName = $"{Monikers.GetBadgeMoniker()}_{config}_version_badge.svg";
|
2016-03-07 20:20:50 +00:00
|
|
|
|
c.BuildContext["VersionBadge"] = Path.Combine(Dirs.Output, versionBadgeName);
|
|
|
|
|
|
2016-03-24 00:13:58 +00:00
|
|
|
|
var cliVersion = c.BuildContext.Get<BuildVersion>("BuildVersion").NuGetVersion;
|
2016-05-27 20:24:39 +00:00
|
|
|
|
var sharedFrameworkVersion = CliDependencyVersions.SharedFrameworkVersion;
|
|
|
|
|
var hostVersion = CliDependencyVersions.SharedHostVersion;
|
2016-06-12 22:33:02 +00:00
|
|
|
|
var hostFxrVersion = CliDependencyVersions.HostFxrVersion;
|
2016-03-24 00:13:58 +00:00
|
|
|
|
|
2016-05-16 22:30:53 +00:00
|
|
|
|
// Generated Installers + Archives
|
2016-03-24 00:13:58 +00:00
|
|
|
|
AddInstallerArtifactToContext(c, "dotnet-sdk", "Sdk", cliVersion);
|
|
|
|
|
AddInstallerArtifactToContext(c, "dotnet-dev", "CombinedFrameworkSDKHost", cliVersion);
|
2016-04-24 20:01:52 +00:00
|
|
|
|
AddInstallerArtifactToContext(c, "dotnet-sharedframework-sdk", "CombinedFrameworkSDK", cliVersion);
|
2016-04-05 03:13:13 +00:00
|
|
|
|
AddInstallerArtifactToContext(c, "dotnet-sdk-debug", "SdkSymbols", cliVersion);
|
2016-03-07 20:20:50 +00:00
|
|
|
|
|
2016-05-16 22:30:53 +00:00
|
|
|
|
//Downloaded Installers + Archives
|
|
|
|
|
AddInstallerArtifactToContext(c, "dotnet-host", "SharedHost", hostVersion);
|
2016-06-12 22:33:02 +00:00
|
|
|
|
AddInstallerArtifactToContext(c, "dotnet-hostfxr", "HostFxr", hostFxrVersion);
|
2016-05-16 22:30:53 +00:00
|
|
|
|
AddInstallerArtifactToContext(c, "dotnet-sharedframework", "SharedFramework", sharedFrameworkVersion);
|
|
|
|
|
AddInstallerArtifactToContext(c, "dotnet", "CombinedFrameworkHost", sharedFrameworkVersion);
|
|
|
|
|
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Target(
|
2016-05-27 19:37:17 +00:00
|
|
|
|
nameof(ExpectedBuildArtifacts),
|
|
|
|
|
nameof(DownloadHostAndSharedFxArchives),
|
2016-05-16 22:30:53 +00:00
|
|
|
|
nameof(DownloadHostAndSharedFxInstallers))]
|
|
|
|
|
public static BuildTargetResult DownloadHostAndSharedFxArtifacts(BuildTargetContext c) => c.Success();
|
|
|
|
|
|
|
|
|
|
[Target]
|
|
|
|
|
public static BuildTargetResult DownloadHostAndSharedFxArchives(BuildTargetContext c)
|
|
|
|
|
{
|
2016-05-27 20:24:39 +00:00
|
|
|
|
var sharedFrameworkVersion = CliDependencyVersions.SharedFrameworkVersion;
|
|
|
|
|
var sharedFrameworkChannel = CliDependencyVersions.SharedFrameworkChannel;
|
2016-05-16 22:30:53 +00:00
|
|
|
|
|
2016-05-26 19:58:19 +00:00
|
|
|
|
var combinedSharedHostAndFrameworkArchiveDownloadFile =
|
2016-05-27 20:24:39 +00:00
|
|
|
|
Path.Combine(CliDirs.CoreSetupDownload, "combinedSharedHostAndFrameworkArchive");
|
2016-05-16 22:30:53 +00:00
|
|
|
|
|
2016-05-26 19:58:19 +00:00
|
|
|
|
Mkdirp(Path.GetDirectoryName(combinedSharedHostAndFrameworkArchiveDownloadFile));
|
2016-05-16 22:30:53 +00:00
|
|
|
|
|
2016-05-26 19:58:19 +00:00
|
|
|
|
if ( ! File.Exists(combinedSharedHostAndFrameworkArchiveDownloadFile))
|
2016-05-16 22:30:53 +00:00
|
|
|
|
{
|
2016-05-26 19:58:19 +00:00
|
|
|
|
// Needed for computing the blob path
|
|
|
|
|
var combinedSharedHostAndFrameworkArchiveBuildContextFile =
|
|
|
|
|
c.BuildContext.Get<string>("CombinedFrameworkHostCompressedFile");
|
|
|
|
|
|
|
|
|
|
AzurePublisher.DownloadFile(
|
|
|
|
|
AzurePublisher.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);
|
|
|
|
|
}
|
2016-05-16 22:30:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Target]
|
|
|
|
|
[BuildPlatforms(BuildPlatform.Windows, BuildPlatform.OSX, BuildPlatform.Ubuntu)]
|
|
|
|
|
public static BuildTargetResult DownloadHostAndSharedFxInstallers(BuildTargetContext c)
|
|
|
|
|
{
|
2016-05-27 20:24:39 +00:00
|
|
|
|
var sharedFrameworkVersion = CliDependencyVersions.SharedFrameworkVersion;
|
|
|
|
|
var hostVersion = CliDependencyVersions.SharedHostVersion;
|
2016-06-12 22:33:02 +00:00
|
|
|
|
var hostFxrVersion = CliDependencyVersions.HostFxrVersion;
|
2016-05-16 22:30:53 +00:00
|
|
|
|
|
2016-05-27 20:24:39 +00:00
|
|
|
|
var sharedFrameworkChannel = CliDependencyVersions.SharedFrameworkChannel;
|
|
|
|
|
var sharedHostChannel = CliDependencyVersions.SharedHostChannel;
|
2016-06-12 22:33:02 +00:00
|
|
|
|
var hostFxrChannel = CliDependencyVersions.HostFxrChannel;
|
2016-05-16 22:30:53 +00:00
|
|
|
|
|
2016-05-27 20:24:39 +00:00
|
|
|
|
var sharedFrameworkInstallerDownloadFile = Path.Combine(CliDirs.CoreSetupDownload, "sharedFrameworkInstaller");
|
|
|
|
|
var sharedHostInstallerDownloadFile = Path.Combine(CliDirs.CoreSetupDownload, "sharedHostInstaller");
|
2016-06-12 22:33:02 +00:00
|
|
|
|
var hostFxrInstallerDownloadFile = Path.Combine(CliDirs.CoreSetupDownload, "hostFxrInstaller");
|
2016-05-26 19:58:19 +00:00
|
|
|
|
|
|
|
|
|
Mkdirp(Path.GetDirectoryName(sharedFrameworkInstallerDownloadFile));
|
|
|
|
|
Mkdirp(Path.GetDirectoryName(sharedHostInstallerDownloadFile));
|
2016-06-12 22:33:02 +00:00
|
|
|
|
Mkdirp(Path.GetDirectoryName(hostFxrInstallerDownloadFile));
|
2016-06-02 00:12:31 +00:00
|
|
|
|
|
2016-05-26 19:58:19 +00:00
|
|
|
|
if ( ! File.Exists(sharedFrameworkInstallerDownloadFile))
|
|
|
|
|
{
|
|
|
|
|
var sharedFrameworkInstallerDestinationFile = c.BuildContext.Get<string>("SharedFrameworkInstallerFile");
|
|
|
|
|
Mkdirp(Path.GetDirectoryName(sharedFrameworkInstallerDestinationFile));
|
|
|
|
|
|
|
|
|
|
AzurePublisher.DownloadFile(
|
|
|
|
|
AzurePublisher.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(
|
|
|
|
|
AzurePublisher.CalculateInstallerBlob(
|
|
|
|
|
sharedHostInstallerDestinationFile,
|
|
|
|
|
sharedHostChannel,
|
|
|
|
|
hostVersion),
|
|
|
|
|
sharedHostInstallerDownloadFile).Wait();
|
|
|
|
|
|
|
|
|
|
File.Copy(sharedHostInstallerDownloadFile, sharedHostInstallerDestinationFile, true);
|
|
|
|
|
}
|
2016-05-16 22:30:53 +00:00
|
|
|
|
|
2016-06-12 22:33:02 +00:00
|
|
|
|
if ( ! File.Exists(hostFxrInstallerDownloadFile))
|
|
|
|
|
{
|
|
|
|
|
var hostFxrInstallerDestinationFile = c.BuildContext.Get<string>("HostFxrInstallerFile");
|
|
|
|
|
Mkdirp(Path.GetDirectoryName(hostFxrInstallerDestinationFile));
|
|
|
|
|
|
|
|
|
|
AzurePublisher.DownloadFile(
|
|
|
|
|
AzurePublisher.CalculateInstallerBlob(
|
|
|
|
|
hostFxrInstallerDestinationFile,
|
|
|
|
|
hostFxrChannel,
|
|
|
|
|
hostFxrVersion),
|
|
|
|
|
hostFxrInstallerDownloadFile).Wait();
|
|
|
|
|
|
|
|
|
|
File.Copy(hostFxrInstallerDownloadFile, hostFxrInstallerDestinationFile, true);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-07 20:20:50 +00:00
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-02 18:04:50 +00:00
|
|
|
|
[Target]
|
|
|
|
|
public static BuildTargetResult CheckPackageCache(BuildTargetContext c)
|
|
|
|
|
{
|
|
|
|
|
var ciBuild = string.Equals(Environment.GetEnvironmentVariable("CI_BUILD"), "1", StringComparison.Ordinal);
|
2016-06-09 22:05:27 +00:00
|
|
|
|
|
|
|
|
|
// Always set the package cache location local to the build
|
|
|
|
|
Environment.SetEnvironmentVariable("NUGET_PACKAGES", Dirs.NuGetPackages);
|
2016-02-02 18:04:50 +00:00
|
|
|
|
|
|
|
|
|
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
|
2016-02-15 17:42:17 +00:00
|
|
|
|
if (File.Exists(cacheTimeFile))
|
2016-02-02 18:04:50 +00:00
|
|
|
|
{
|
|
|
|
|
var content = File.ReadAllText(cacheTimeFile);
|
2016-02-15 17:42:17 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(content))
|
2016-02-02 18:04:50 +00:00
|
|
|
|
{
|
|
|
|
|
cacheTime = DateTime.ParseExact("O", content, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-15 17:42:17 +00:00
|
|
|
|
catch (Exception ex)
|
2016-02-02 18:04:50 +00:00
|
|
|
|
{
|
|
|
|
|
c.Warn($"Error reading NuGet cache time file, leaving the cache alone");
|
|
|
|
|
c.Warn($"Error Detail: {ex.ToString()}");
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-15 17:42:17 +00:00
|
|
|
|
if (cacheTime == null || (cacheTime.Value.AddHours(cacheExpiration) < DateTime.UtcNow))
|
2016-02-02 18:04:50 +00:00
|
|
|
|
{
|
|
|
|
|
// 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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Target(nameof(CheckPackageCache))]
|
|
|
|
|
public static BuildTargetResult RestorePackages(BuildTargetContext c)
|
|
|
|
|
{
|
|
|
|
|
var dotnet = DotNetCli.Stage0;
|
|
|
|
|
|
2016-05-16 22:30:53 +00:00
|
|
|
|
dotnet.Restore("--verbosity", "verbose", "--disable-parallel")
|
2016-04-07 00:45:38 +00:00
|
|
|
|
.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();
|
2016-02-02 18:04:50 +00:00
|
|
|
|
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-18 19:39:36 +00:00
|
|
|
|
[Target]
|
2016-05-30 05:38:45 +00:00
|
|
|
|
[BuildPlatforms(BuildPlatform.Ubuntu, "14.04")]
|
2016-02-20 01:00:41 +00:00
|
|
|
|
public static BuildTargetResult CheckUbuntuDebianPackageBuildDependencies(BuildTargetContext c)
|
2016-02-18 19:39:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var messageBuilder = new StringBuilder();
|
2016-02-23 23:27:03 +00:00
|
|
|
|
var aptDependencyUtility = new AptDependencyUtility();
|
|
|
|
|
|
2016-02-18 19:39:36 +00:00
|
|
|
|
|
2016-02-23 23:27:03 +00:00
|
|
|
|
foreach (var package in PackageDependencies.DebianPackageBuildDependencies)
|
2016-02-18 19:39:36 +00:00
|
|
|
|
{
|
2016-02-23 23:27:03 +00:00
|
|
|
|
if (!AptDependencyUtility.PackageIsInstalled(package))
|
2016-02-18 19:39:36 +00:00
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (messageBuilder.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return c.Failed(messageBuilder.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Target]
|
2016-05-30 05:38:45 +00:00
|
|
|
|
[BuildPlatforms(BuildPlatform.Ubuntu, "14.04")]
|
2016-02-23 23:27:03 +00:00
|
|
|
|
public static BuildTargetResult CheckUbuntuCoreclrAndCoreFxDependencies(BuildTargetContext c)
|
2016-02-18 19:39:36 +00:00
|
|
|
|
{
|
|
|
|
|
var errorMessageBuilder = new StringBuilder();
|
2016-02-23 23:27:03 +00:00
|
|
|
|
var stage0 = DotNetCli.Stage0.BinPath;
|
2016-02-18 19:39:36 +00:00
|
|
|
|
|
2016-02-23 23:27:03 +00:00
|
|
|
|
foreach (var package in PackageDependencies.UbuntuCoreclrAndCoreFxDependencies)
|
2016-02-18 19:39:36 +00:00
|
|
|
|
{
|
2016-02-23 23:27:03 +00:00
|
|
|
|
if (!AptDependencyUtility.PackageIsInstalled(package))
|
2016-02-18 19:39:36 +00:00
|
|
|
|
{
|
2016-02-20 01:00:41 +00:00
|
|
|
|
errorMessageBuilder.Append($"Error: Coreclr package dependency {package} missing.");
|
|
|
|
|
errorMessageBuilder.Append(Environment.NewLine);
|
|
|
|
|
errorMessageBuilder.Append($"-> install with apt-get install {package}");
|
|
|
|
|
errorMessageBuilder.Append(Environment.NewLine);
|
|
|
|
|
}
|
2016-02-18 19:39:36 +00:00
|
|
|
|
}
|
2016-02-20 01:00:41 +00:00
|
|
|
|
|
|
|
|
|
if (errorMessageBuilder.Length == 0)
|
2016-02-18 19:39:36 +00:00
|
|
|
|
{
|
2016-02-20 01:00:41 +00:00
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return c.Failed(errorMessageBuilder.ToString());
|
2016-02-18 19:39:36 +00:00
|
|
|
|
}
|
2016-02-20 01:00:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Target]
|
|
|
|
|
[BuildPlatforms(BuildPlatform.CentOS)]
|
2016-02-23 23:27:03 +00:00
|
|
|
|
public static BuildTargetResult CheckCentOSCoreclrAndCoreFxDependencies(BuildTargetContext c)
|
2016-02-20 01:00:41 +00:00
|
|
|
|
{
|
|
|
|
|
var errorMessageBuilder = new StringBuilder();
|
2016-03-07 22:52:41 +00:00
|
|
|
|
|
2016-02-23 23:27:03 +00:00
|
|
|
|
foreach (var package in PackageDependencies.CentosCoreclrAndCoreFxDependencies)
|
2016-02-20 01:00:41 +00:00
|
|
|
|
{
|
2016-02-23 23:27:03 +00:00
|
|
|
|
if (!YumDependencyUtility.PackageIsInstalled(package))
|
2016-02-18 19:39:36 +00:00
|
|
|
|
{
|
|
|
|
|
errorMessageBuilder.Append($"Error: Coreclr package dependency {package} missing.");
|
|
|
|
|
errorMessageBuilder.Append(Environment.NewLine);
|
2016-02-20 01:00:41 +00:00
|
|
|
|
errorMessageBuilder.Append($"-> install with yum install {package}");
|
|
|
|
|
errorMessageBuilder.Append(Environment.NewLine);
|
2016-02-18 19:39:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (errorMessageBuilder.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return c.Failed(errorMessageBuilder.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Target]
|
|
|
|
|
public static BuildTargetResult CheckPrereqCmakePresent(BuildTargetContext c)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Command.Create("cmake", "--version")
|
|
|
|
|
.CaptureStdOut()
|
|
|
|
|
.CaptureStdErr()
|
|
|
|
|
.Execute();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
string message = $@"Error running cmake: {ex.Message}
|
|
|
|
|
cmake is required to build the native host 'corehost'";
|
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
|
|
{
|
|
|
|
|
message += Environment.NewLine + "Download it from https://www.cmake.org";
|
|
|
|
|
}
|
|
|
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
|
|
|
{
|
|
|
|
|
message += Environment.NewLine + "Ubuntu: 'sudo apt-get install cmake'";
|
|
|
|
|
}
|
|
|
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
|
|
|
{
|
|
|
|
|
message += Environment.NewLine + "OS X w/Homebrew: 'brew install cmake'";
|
|
|
|
|
}
|
|
|
|
|
return c.Failed(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-25 16:21:08 +00:00
|
|
|
|
[Target]
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-17 00:54:44 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-02 18:04:50 +00:00
|
|
|
|
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:");
|
2016-02-15 17:42:17 +00:00
|
|
|
|
foreach (var line in lines)
|
2016-02-02 18:04:50 +00:00
|
|
|
|
{
|
2016-02-15 17:42:17 +00:00
|
|
|
|
if (!line.Trim().StartsWith("#") && !string.IsNullOrWhiteSpace(line))
|
2016-02-02 18:04:50 +00:00
|
|
|
|
{
|
|
|
|
|
var splat = line.Split(new[] { '=' }, 2);
|
|
|
|
|
dict[splat[0]] = splat[1];
|
|
|
|
|
c.Verbose($" {splat[0]} = {splat[1]}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return dict;
|
|
|
|
|
}
|
2016-03-08 21:39:41 +00:00
|
|
|
|
|
2016-03-24 00:13:58 +00:00
|
|
|
|
private static void AddInstallerArtifactToContext(
|
2016-05-27 19:37:17 +00:00
|
|
|
|
BuildTargetContext c,
|
|
|
|
|
string artifactPrefix,
|
2016-03-24 00:13:58 +00:00
|
|
|
|
string contextPrefix,
|
|
|
|
|
string version)
|
2016-03-08 21:39:41 +00:00
|
|
|
|
{
|
2016-03-24 00:13:58 +00:00
|
|
|
|
var productName = Monikers.GetProductMoniker(c, artifactPrefix, version);
|
2016-03-08 21:39:41 +00:00
|
|
|
|
|
|
|
|
|
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:
|
2016-05-16 22:30:53 +00:00
|
|
|
|
if (contextPrefix.Contains("Combined"))
|
|
|
|
|
{
|
|
|
|
|
installer = productName + ".exe";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
installer = productName + ".msi";
|
|
|
|
|
}
|
2016-03-08 21:39:41 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2016-02-02 18:04:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|