Bring Host build into separate project
This commit is contained in:
parent
07b785c183
commit
7bf08c5bd5
76 changed files with 1065 additions and 320 deletions
232
build_projects/dotnet-host-build/CompileTargets.cs
Normal file
232
build_projects/dotnet-host-build/CompileTargets.cs
Normal file
|
@ -0,0 +1,232 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Microsoft.DotNet.Cli.Build.Framework;
|
||||
using Microsoft.DotNet.InternalAbstractions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Microsoft.DotNet.Cli.Build;
|
||||
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
|
||||
using static Microsoft.DotNet.Cli.Build.FS;
|
||||
|
||||
namespace Microsoft.DotNet.Host.Build
|
||||
{
|
||||
public class CompileTargets
|
||||
{
|
||||
public static readonly bool IsWinx86 = CurrentPlatform.IsWindows && CurrentArchitecture.Isx86;
|
||||
|
||||
public static string HostPackagePlatformRid => HostPackageSupportedRids[
|
||||
(RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
|
||||
? $"win7-{RuntimeEnvironment.RuntimeArchitecture}"
|
||||
: RuntimeEnvironment.GetRuntimeIdentifier()];
|
||||
|
||||
public static readonly Dictionary<string, string> HostPackageSupportedRids = new Dictionary<string, string>()
|
||||
{
|
||||
// Key: Current platform RID. Value: The actual publishable (non-dummy) package name produced by the build system for this RID.
|
||||
{ "win7-x64", "win7-x64" },
|
||||
{ "win7-x86", "win7-x86" },
|
||||
{ "osx.10.10-x64", "osx.10.10-x64" },
|
||||
{ "osx.10.11-x64", "osx.10.10-x64" },
|
||||
{ "ubuntu.14.04-x64", "ubuntu.14.04-x64" },
|
||||
{ "centos.7-x64", "rhel.7-x64" },
|
||||
{ "rhel.7-x64", "rhel.7-x64" },
|
||||
{ "rhel.7.2-x64", "rhel.7-x64" },
|
||||
{ "debian.8-x64", "debian.8-x64" }
|
||||
};
|
||||
|
||||
|
||||
private static string DotnetHostBaseName => $"dotnet{Constants.ExeSuffix}";
|
||||
private static string DotnetHostFxrBaseName => $"{Constants.DynamicLibPrefix}hostfxr{Constants.DynamicLibSuffix}";
|
||||
private static string HostPolicyBaseName => $"{Constants.DynamicLibPrefix}hostpolicy{Constants.DynamicLibSuffix}";
|
||||
|
||||
[Target(nameof(PrepareTargets.Init),
|
||||
nameof(CompileCoreHost),
|
||||
nameof(PackagePkgProjects))]
|
||||
public static BuildTargetResult Compile(BuildTargetContext c)
|
||||
{
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
// We need to generate stub host packages so we can restore our standalone test assets against the metapackage
|
||||
// we built earlier in the build
|
||||
// https://github.com/dotnet/cli/issues/2438
|
||||
[Target]
|
||||
public static BuildTargetResult GenerateStubHostPackages(BuildTargetContext c)
|
||||
{
|
||||
var hostVersion = c.BuildContext.Get<HostVersion>("HostVersion");
|
||||
var currentRid = HostPackagePlatformRid;
|
||||
|
||||
var stubPackageBuilder = new StubPackageBuilder(DotNetCli.Stage0, Dirs.Intermediate, Dirs.CorehostDummyPackages);
|
||||
|
||||
foreach (var hostPackage in hostVersion.LatestHostPackages)
|
||||
{
|
||||
foreach (var rid in HostPackageSupportedRids.Values.Distinct())
|
||||
{
|
||||
if (!rid.Equals(currentRid))
|
||||
{
|
||||
var basePackageId = hostPackage.Key;
|
||||
var packageVersion = hostPackage.Value;
|
||||
|
||||
var packageId = $"runtime.{rid}.{basePackageId}";
|
||||
|
||||
stubPackageBuilder.GeneratePackage(packageId, packageVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
public static BuildTargetResult CompileCoreHost(BuildTargetContext c)
|
||||
{
|
||||
var hostVersion = c.BuildContext.Get<HostVersion>("HostVersion");
|
||||
|
||||
// Generate build files
|
||||
var cmakeOut = Path.Combine(Dirs.CorehostLatest, "cmake");
|
||||
|
||||
Rmdir(cmakeOut);
|
||||
Mkdirp(cmakeOut);
|
||||
|
||||
var configuration = c.BuildContext.Get<string>("Configuration");
|
||||
|
||||
// Run the build
|
||||
string rid = DotNetCli.Stage0.GetRuntimeId();
|
||||
string corehostSrcDir = Path.Combine(c.BuildContext.BuildDirectory, "src", "corehost");
|
||||
string commitHash = c.BuildContext.Get<string>("CommitHash");
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
// Why does Windows directly call cmake but Linux/Mac calls "build.sh" in the corehost dir?
|
||||
// See the comment in "src/corehost/build.sh" for details. It doesn't work for some reason.
|
||||
var visualStudio = IsWinx86 ? "Visual Studio 14 2015" : "Visual Studio 14 2015 Win64";
|
||||
var archMacro = IsWinx86 ? "-DCLI_CMAKE_PLATFORM_ARCH_I386=1" : "-DCLI_CMAKE_PLATFORM_ARCH_AMD64=1";
|
||||
var ridMacro = $"-DCLI_CMAKE_RUNTIME_ID:STRING={rid}";
|
||||
var arch = IsWinx86 ? "x86" : "x64";
|
||||
var baseSupportedRid = $"win7-{arch}";
|
||||
var cmakeHostPolicyVer = $"-DCLI_CMAKE_HOST_POLICY_VER:STRING={hostVersion.LatestHostPolicyVersion}";
|
||||
var cmakeHostFxrVer = $"-DCLI_CMAKE_HOST_FXR_VER:STRING={hostVersion.LatestHostFxrVersion}";
|
||||
var cmakeBaseRid = $"-DCLI_CMAKE_PKG_RID:STRING={baseSupportedRid}";
|
||||
var cmakeCommitHash = $"-DCLI_CMAKE_COMMIT_HASH:STRING={commitHash}";
|
||||
|
||||
ExecIn(cmakeOut, "cmake",
|
||||
corehostSrcDir,
|
||||
archMacro,
|
||||
ridMacro,
|
||||
cmakeHostFxrVer,
|
||||
cmakeHostPolicyVer,
|
||||
cmakeBaseRid,
|
||||
cmakeCommitHash,
|
||||
"-G",
|
||||
visualStudio);
|
||||
|
||||
var pf32 = RuntimeInformation.OSArchitecture == Architecture.X64 ?
|
||||
Environment.GetEnvironmentVariable("ProgramFiles(x86)") :
|
||||
Environment.GetEnvironmentVariable("ProgramFiles");
|
||||
|
||||
if (configuration.Equals("Release"))
|
||||
{
|
||||
// Cmake calls it "RelWithDebInfo" in the generated MSBuild
|
||||
configuration = "RelWithDebInfo";
|
||||
}
|
||||
|
||||
Exec(Path.Combine(pf32, "MSBuild", "14.0", "Bin", "MSBuild.exe"),
|
||||
Path.Combine(cmakeOut, "ALL_BUILD.vcxproj"),
|
||||
$"/p:Configuration={configuration}");
|
||||
|
||||
// Copy the output out
|
||||
File.Copy(Path.Combine(cmakeOut, "cli", configuration, "dotnet.exe"), Path.Combine(Dirs.CorehostLatest, "dotnet.exe"), overwrite: true);
|
||||
File.Copy(Path.Combine(cmakeOut, "cli", configuration, "dotnet.pdb"), Path.Combine(Dirs.CorehostLatest, "dotnet.pdb"), overwrite: true);
|
||||
File.Copy(Path.Combine(cmakeOut, "cli", "dll", configuration, "hostpolicy.dll"), Path.Combine(Dirs.CorehostLatest, "hostpolicy.dll"), overwrite: true);
|
||||
File.Copy(Path.Combine(cmakeOut, "cli", "dll", configuration, "hostpolicy.pdb"), Path.Combine(Dirs.CorehostLatest, "hostpolicy.pdb"), overwrite: true);
|
||||
File.Copy(Path.Combine(cmakeOut, "cli", "fxr", configuration, "hostfxr.dll"), Path.Combine(Dirs.CorehostLatest, "hostfxr.dll"), overwrite: true);
|
||||
File.Copy(Path.Combine(cmakeOut, "cli", "fxr", configuration, "hostfxr.pdb"), Path.Combine(Dirs.CorehostLatest, "hostfxr.pdb"), overwrite: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
ExecIn(cmakeOut, Path.Combine(c.BuildContext.BuildDirectory, "src", "corehost", "build.sh"),
|
||||
"--arch",
|
||||
"x64",
|
||||
"--fxrver",
|
||||
hostVersion.LatestHostFxrVersion,
|
||||
"--policyver",
|
||||
hostVersion.LatestHostPolicyVersion,
|
||||
"--rid",
|
||||
rid,
|
||||
"--commithash",
|
||||
commitHash);
|
||||
|
||||
// Copy the output out
|
||||
File.Copy(Path.Combine(cmakeOut, "cli", "dotnet"), Path.Combine(Dirs.CorehostLatest, "dotnet"), overwrite: true);
|
||||
File.Copy(Path.Combine(cmakeOut, "cli", "dll", HostPolicyBaseName), Path.Combine(Dirs.CorehostLatest, HostPolicyBaseName), overwrite: true);
|
||||
File.Copy(Path.Combine(cmakeOut, "cli", "fxr", DotnetHostFxrBaseName), Path.Combine(Dirs.CorehostLatest, DotnetHostFxrBaseName), overwrite: true);
|
||||
}
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target(nameof(CompileTargets.GenerateStubHostPackages))]
|
||||
public static BuildTargetResult PackagePkgProjects(BuildTargetContext c)
|
||||
{
|
||||
var arch = IsWinx86 ? "x86" : "x64";
|
||||
|
||||
var hostVersion = c.BuildContext.Get<HostVersion>("HostVersion");
|
||||
var hostNugetversion = hostVersion.LatestHostVersion;
|
||||
var content = $@"{c.BuildContext["CommitHash"]}{Environment.NewLine}{hostNugetversion}{Environment.NewLine}";
|
||||
var pkgDir = Path.Combine(c.BuildContext.BuildDirectory, "pkg");
|
||||
File.WriteAllText(Path.Combine(pkgDir, "version.txt"), content);
|
||||
|
||||
if (CurrentPlatform.IsWindows)
|
||||
{
|
||||
Command.Create(Path.Combine(pkgDir, "pack.cmd"))
|
||||
// Workaround to arg escaping adding backslashes for arguments to .cmd scripts.
|
||||
.Environment("__WorkaroundCliCoreHostBuildArch", arch)
|
||||
.Environment("__WorkaroundCliCoreHostBinDir", Dirs.CorehostLatest)
|
||||
.Environment("__WorkaroundCliCoreHostPolicyVer", hostVersion.LatestHostPolicyVersionNoSuffix)
|
||||
.Environment("__WorkaroundCliCoreHostFxrVer", hostVersion.LatestHostFxrVersionNoSuffix)
|
||||
.Environment("__WorkaroundCliCoreHostVer", hostVersion.LatestHostVersionNoSuffix)
|
||||
.Environment("__WorkaroundCliCoreHostBuildMajor", hostVersion.LatestHostBuildMajor)
|
||||
.Environment("__WorkaroundCliCoreHostVersionTag", hostVersion.LatestHostPrerelease)
|
||||
.ForwardStdOut()
|
||||
.ForwardStdErr()
|
||||
.Execute()
|
||||
.EnsureSuccessful();
|
||||
}
|
||||
else
|
||||
{
|
||||
Exec(Path.Combine(pkgDir, "pack.sh"),
|
||||
"--arch",
|
||||
"x64",
|
||||
"--hostbindir",
|
||||
Dirs.CorehostLatest,
|
||||
"--policyver",
|
||||
hostVersion.LatestHostPolicyVersionNoSuffix,
|
||||
"--fxrver",
|
||||
hostVersion.LatestHostFxrVersionNoSuffix,
|
||||
"--hostver",
|
||||
hostVersion.LatestHostVersionNoSuffix,
|
||||
"--build",
|
||||
hostVersion.LatestHostBuildMajor,
|
||||
"--vertag",
|
||||
hostVersion.LatestHostPrerelease);
|
||||
}
|
||||
foreach (var file in Directory.GetFiles(Path.Combine(pkgDir, "bin", "packages"), "*.nupkg"))
|
||||
{
|
||||
var fileName = Path.GetFileName(file);
|
||||
File.Copy(file, Path.Combine(Dirs.CorehostLocalPackages, fileName), true);
|
||||
|
||||
Console.WriteLine($"Copying package {fileName} to artifacts directory {Dirs.CorehostLocalPackages}.");
|
||||
}
|
||||
foreach (var item in hostVersion.LatestHostPackages)
|
||||
{
|
||||
var fileFilter = $"runtime.{HostPackagePlatformRid}.{item.Key}.{item.Value}.nupkg";
|
||||
if (Directory.GetFiles(Dirs.CorehostLocalPackages, fileFilter).Length == 0)
|
||||
{
|
||||
throw new BuildFailureException($"Nupkg for {fileFilter} was not created.");
|
||||
}
|
||||
}
|
||||
return c.Success();
|
||||
}
|
||||
}
|
||||
}
|
207
build_projects/dotnet-host-build/PrepareTargets.cs
Normal file
207
build_projects/dotnet-host-build/PrepareTargets.cs
Normal file
|
@ -0,0 +1,207 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.DotNet.Cli.Build.Framework;
|
||||
using Microsoft.DotNet.InternalAbstractions;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Microsoft.DotNet.Cli.Build;
|
||||
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.Host.Build
|
||||
{
|
||||
public class PrepareTargets
|
||||
{
|
||||
[Target(nameof(Init))]
|
||||
public static BuildTargetResult Prepare(BuildTargetContext c) => c.Success();
|
||||
|
||||
[Target(nameof(CheckPrereqCmakePresent), nameof(CheckPlatformDependencies))]
|
||||
public static BuildTargetResult CheckPrereqs(BuildTargetContext c) => c.Success();
|
||||
|
||||
[Target(nameof(CheckCoreclrPlatformDependencies))]
|
||||
public static BuildTargetResult CheckPlatformDependencies(BuildTargetContext c) => c.Success();
|
||||
|
||||
[Target(nameof(CheckUbuntuCoreclrAndCoreFxDependencies), nameof(CheckCentOSCoreclrAndCoreFxDependencies))]
|
||||
public static BuildTargetResult CheckCoreclrPlatformDependencies(BuildTargetContext c) => c.Success();
|
||||
|
||||
// All major targets will depend on this in order to ensure variables are set up right if they are run independently
|
||||
[Target(nameof(GenerateVersions), nameof(CheckPrereqs), nameof(LocateStage0), nameof(ExpectedBuildArtifacts))]
|
||||
public static BuildTargetResult Init(BuildTargetContext 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();
|
||||
}
|
||||
|
||||
[Target]
|
||||
public static BuildTargetResult GenerateVersions(BuildTargetContext c)
|
||||
{
|
||||
var gitResult = Cmd("git", "rev-list", "--count", "HEAD")
|
||||
.CaptureStdOut()
|
||||
.Execute();
|
||||
gitResult.EnsureSuccessful();
|
||||
var commitCount = int.Parse(gitResult.StdOut);
|
||||
|
||||
gitResult = Cmd("git", "rev-parse", "HEAD")
|
||||
.CaptureStdOut()
|
||||
.Execute();
|
||||
gitResult.EnsureSuccessful();
|
||||
var commitHash = gitResult.StdOut.Trim();
|
||||
|
||||
var hostVersion = new HostVersion()
|
||||
{
|
||||
CommitCount = commitCount
|
||||
};
|
||||
|
||||
c.BuildContext["HostVersion"] = hostVersion;
|
||||
c.BuildContext["CommitHash"] = commitHash;
|
||||
|
||||
c.Info($"Building Version: {hostVersion.LatestHostVersionNoSuffix} (NuGet Packages: {hostVersion.LatestHostVersion})");
|
||||
c.Info($"From Commit: {commitHash}");
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[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
|
||||
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);
|
||||
c.Info($"Using Stage 0 Version: {version[1]}");
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
public static BuildTargetResult ExpectedBuildArtifacts(BuildTargetContext c)
|
||||
{
|
||||
var config = Environment.GetEnvironmentVariable("CONFIGURATION");
|
||||
var versionBadgeName = $"{CurrentPlatform.Current}_{CurrentArchitecture.Current}_{config}_version_badge.svg";
|
||||
c.BuildContext["VersionBadge"] = Path.Combine(Dirs.Output, versionBadgeName);
|
||||
|
||||
var hostVersion = c.BuildContext.Get<HostVersion>("HostVersion").LockedHostVersion;
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
[BuildPlatforms(BuildPlatform.Ubuntu)]
|
||||
public static BuildTargetResult CheckUbuntuCoreclrAndCoreFxDependencies(BuildTargetContext c)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if (errorMessageBuilder.Length == 0)
|
||||
{
|
||||
return c.Success();
|
||||
}
|
||||
else
|
||||
{
|
||||
return c.Failed(errorMessageBuilder.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[Target]
|
||||
[BuildPlatforms(BuildPlatform.CentOS)]
|
||||
public static BuildTargetResult CheckCentOSCoreclrAndCoreFxDependencies(BuildTargetContext c)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
17
build_projects/dotnet-host-build/Program.cs
Normal file
17
build_projects/dotnet-host-build/Program.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using Microsoft.DotNet.Cli.Build.Framework;
|
||||
|
||||
namespace Microsoft.DotNet.Host.Build
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
DebugHelper.HandleDebugSwitch(ref args);
|
||||
|
||||
return BuildSetup.Create(".NET Core Host")
|
||||
.UseStandardGoals()
|
||||
.UseAllTargetsFromAssembly<Program>()
|
||||
.Run(args);
|
||||
}
|
||||
}
|
||||
}
|
102
build_projects/dotnet-host-build/StubPackageBuilder.cs
Normal file
102
build_projects/dotnet-host-build/StubPackageBuilder.cs
Normal file
|
@ -0,0 +1,102 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using Microsoft.DotNet.Cli.Build.Framework;
|
||||
using Microsoft.WindowsAzure.Storage;
|
||||
using Microsoft.WindowsAzure.Storage.Blob;
|
||||
using Microsoft.DotNet.Cli.Build;
|
||||
|
||||
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
|
||||
|
||||
namespace Microsoft.DotNet.Host.Build
|
||||
{
|
||||
public class StubPackageBuilder
|
||||
{
|
||||
private DotNetCli _dotnet;
|
||||
private string _intermediateDirectory;
|
||||
private string _outputDirectory;
|
||||
|
||||
private bool _stubBitsBuilt = false;
|
||||
|
||||
public StubPackageBuilder(DotNetCli dotnet, string intermediateDirectory, string outputDirectory)
|
||||
{
|
||||
_dotnet = dotnet;
|
||||
_intermediateDirectory = intermediateDirectory;
|
||||
_outputDirectory = outputDirectory;
|
||||
}
|
||||
|
||||
public void GeneratePackage(string packageId, string version)
|
||||
{
|
||||
if (! _stubBitsBuilt)
|
||||
{
|
||||
BuildStubBits(_dotnet, _intermediateDirectory);
|
||||
}
|
||||
|
||||
CreateStubPackage(_dotnet, packageId, version, _intermediateDirectory, _outputDirectory);
|
||||
}
|
||||
|
||||
private void BuildStubBits(DotNetCli dotnet, string intermediateDirectory)
|
||||
{
|
||||
var projectJson = new StringBuilder();
|
||||
projectJson.Append("{");
|
||||
projectJson.Append(" \"dependencies\": { \"NETStandard.Library\": \"1.5.0-rc2-24008\" },");
|
||||
projectJson.Append(" \"frameworks\": { \"netcoreapp1.0\": { \"imports\": [\"netstandard1.5\", \"dnxcore50\"] } },");
|
||||
projectJson.Append(" \"runtimes\": { \"win7-x64\": { } },");
|
||||
projectJson.Append("}");
|
||||
|
||||
var programCs = "using System; namespace ConsoleApplication { public class Program { public static void Main(string[] args) { Console.WriteLine(\"Hello World!\"); } } }";
|
||||
|
||||
var tempPjDirectory = Path.Combine(intermediateDirectory, "dummyNuGetPackageIntermediate");
|
||||
FS.Rmdir(tempPjDirectory);
|
||||
|
||||
Directory.CreateDirectory(tempPjDirectory);
|
||||
|
||||
var tempPjFile = Path.Combine(tempPjDirectory, "project.json");
|
||||
var tempSourceFile = Path.Combine(tempPjDirectory, "Program.cs");
|
||||
|
||||
File.WriteAllText(tempPjFile, projectJson.ToString());
|
||||
File.WriteAllText(tempSourceFile, programCs.ToString());
|
||||
|
||||
dotnet.Restore("--verbosity", "verbose", "--disable-parallel")
|
||||
.WorkingDirectory(tempPjDirectory)
|
||||
.Execute()
|
||||
.EnsureSuccessful();
|
||||
dotnet.Build(tempPjFile, "--runtime", "win7-x64")
|
||||
.WorkingDirectory(tempPjDirectory)
|
||||
.Execute()
|
||||
.EnsureSuccessful();
|
||||
|
||||
_stubBitsBuilt = true;
|
||||
}
|
||||
|
||||
private static void CreateStubPackage(DotNetCli dotnet,
|
||||
string packageId,
|
||||
string version,
|
||||
string intermediateDirectory,
|
||||
string outputDirectory)
|
||||
{
|
||||
var projectJson = new StringBuilder();
|
||||
projectJson.Append("{");
|
||||
projectJson.Append($" \"version\": \"{version}\",");
|
||||
projectJson.Append($" \"name\": \"{packageId}\",");
|
||||
projectJson.Append(" \"dependencies\": { \"NETStandard.Library\": \"1.5.0-rc2-24008\" },");
|
||||
projectJson.Append(" \"frameworks\": { \"netcoreapp1.0\": { \"imports\": [\"netstandard1.5\", \"dnxcore50\"] } },");
|
||||
projectJson.Append("}");
|
||||
|
||||
var tempPjDirectory = Path.Combine(intermediateDirectory, "dummyNuGetPackageIntermediate");
|
||||
var tempPjFile = Path.Combine(tempPjDirectory, "project.json");
|
||||
|
||||
File.WriteAllText(tempPjFile, projectJson.ToString());
|
||||
|
||||
dotnet.Pack(
|
||||
tempPjFile, "--no-build",
|
||||
"--output", outputDirectory)
|
||||
.WorkingDirectory(tempPjDirectory)
|
||||
.Execute()
|
||||
.EnsureSuccessful();
|
||||
}
|
||||
}
|
||||
}
|
81
build_projects/dotnet-host-build/build.ps1
Normal file
81
build_projects/dotnet-host-build/build.ps1
Normal file
|
@ -0,0 +1,81 @@
|
|||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
param(
|
||||
[string]$Configuration="Debug",
|
||||
[string]$Architecture="x64",
|
||||
[string[]]$Targets=@("Default"),
|
||||
[switch]$NoPackage,
|
||||
[switch]$Help)
|
||||
|
||||
if($Help)
|
||||
{
|
||||
Write-Host "Usage: .\build.ps1 [-Configuration <CONFIGURATION>] [-NoPackage] [-Help] [-Targets <TARGETS...>]"
|
||||
Write-Host ""
|
||||
Write-Host "Options:"
|
||||
Write-Host " -Configuration <CONFIGURATION> Build the specified Configuration (Debug or Release, default: Debug)"
|
||||
Write-Host " -Architecture <ARCHITECTURE> Build the specified architecture (x64 or x86 (supported only on Windows), default: x64)"
|
||||
Write-Host " -Targets <TARGETS...> Comma separated build targets to run (Init, Compile, Publish, etc.; Default is a full build and publish)"
|
||||
Write-Host " -NoPackage Skip packaging targets"
|
||||
Write-Host " -Help Display this help message"
|
||||
exit 0
|
||||
}
|
||||
|
||||
$env:CONFIGURATION = $Configuration;
|
||||
$RepoRoot = "$PSScriptRoot\..\.."
|
||||
|
||||
if($NoPackage)
|
||||
{
|
||||
$env:DOTNET_BUILD_SKIP_PACKAGING=1
|
||||
}
|
||||
else
|
||||
{
|
||||
$env:DOTNET_BUILD_SKIP_PACKAGING=0
|
||||
}
|
||||
|
||||
# Load Branch Info
|
||||
cat "$RepoRoot\branchinfo.txt" | ForEach-Object {
|
||||
if(!$_.StartsWith("#") -and ![String]::IsNullOrWhiteSpace($_)) {
|
||||
$splat = $_.Split([char[]]@("="), 2)
|
||||
Set-Content "env:\$($splat[0])" -Value $splat[1]
|
||||
}
|
||||
}
|
||||
|
||||
# Use a repo-local install directory (but not the artifacts directory because that gets cleaned a lot
|
||||
if (!$env:DOTNET_INSTALL_DIR)
|
||||
{
|
||||
$env:DOTNET_INSTALL_DIR="$RepoRoot\.dotnet_stage0\Windows\$Architecture"
|
||||
}
|
||||
|
||||
if (!(Test-Path $env:DOTNET_INSTALL_DIR))
|
||||
{
|
||||
mkdir $env:DOTNET_INSTALL_DIR | Out-Null
|
||||
}
|
||||
|
||||
# Install a stage 0
|
||||
Write-Host "Installing .NET Core CLI Stage 0 from branchinfo channel"
|
||||
& "$RepoRoot\scripts\obtain\dotnet-install.ps1" -Channel $env:CHANNEL -Architecture $Architecture -Verbose
|
||||
if($LASTEXITCODE -ne 0) { throw "Failed to install stage0" }
|
||||
|
||||
# Put the stage0 on the path
|
||||
$env:PATH = "$env:DOTNET_INSTALL_DIR;$env:PATH"
|
||||
|
||||
# Restore the build scripts
|
||||
Write-Host "Restoring Build Script projects..."
|
||||
pushd "$PSScriptRoot\.."
|
||||
dotnet restore --infer-runtimes
|
||||
if($LASTEXITCODE -ne 0) { throw "Failed to restore" }
|
||||
popd
|
||||
|
||||
# Publish the builder
|
||||
Write-Host "Compiling Build Scripts..."
|
||||
dotnet publish "$PSScriptRoot" -o "$PSScriptRoot\bin" --framework netcoreapp1.0
|
||||
if($LASTEXITCODE -ne 0) { throw "Failed to compile build scripts" }
|
||||
|
||||
# Run the builder
|
||||
Write-Host "Invoking Build Scripts..."
|
||||
Write-Host " Configuration: $env:CONFIGURATION"
|
||||
& "$PSScriptRoot\bin\dotnet-host-build.exe" @Targets
|
||||
if($LASTEXITCODE -ne 0) { throw "Build failed" }
|
118
build_projects/dotnet-host-build/build.sh
Executable file
118
build_projects/dotnet-host-build/build.sh
Executable file
|
@ -0,0 +1,118 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
set -e
|
||||
|
||||
SOURCE="${BASH_SOURCE[0]}"
|
||||
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
SOURCE="$(readlink "$SOURCE")"
|
||||
[[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
||||
done
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
OLDPATH="$PATH"
|
||||
|
||||
REPOROOT="$DIR/../.."
|
||||
source "$REPOROOT/scripts/common/_prettyprint.sh"
|
||||
|
||||
while [[ $# > 0 ]]; do
|
||||
lowerI="$(echo $1 | awk '{print tolower($0)}')"
|
||||
case $lowerI in
|
||||
-c|--configuration)
|
||||
export CONFIGURATION=$2
|
||||
shift
|
||||
;;
|
||||
--targets)
|
||||
IFS=',' read -r -a targets <<< $2
|
||||
shift
|
||||
;;
|
||||
--nopackage)
|
||||
export DOTNET_BUILD_SKIP_PACKAGING=1
|
||||
;;
|
||||
--skip-prereqs)
|
||||
# Allow CI to disable prereqs check since the CI has the pre-reqs but not ldconfig it seems
|
||||
export DOTNET_INSTALL_SKIP_PREREQS=1
|
||||
;;
|
||||
--help)
|
||||
echo "Usage: $0 [--configuration <CONFIGURATION>] [--skip-prereqs] [--nopackage] [--docker <IMAGENAME>] [--help] [--targets <TARGETS...>]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " --configuration <CONFIGURATION> Build the specified Configuration (Debug or Release, default: Debug)"
|
||||
echo " --targets <TARGETS...> Comma separated build targets to run (Init, Compile, Publish, etc.; Default is a full build and publish)"
|
||||
echo " --nopackage Skip packaging targets"
|
||||
echo " --skip-prereqs Skip checks for pre-reqs in dotnet_install"
|
||||
echo " --docker <IMAGENAME> Build in Docker using the Dockerfile located in scripts/docker/IMAGENAME"
|
||||
echo " --help Display this help message"
|
||||
echo " <TARGETS...> The build targets to run (Init, Compile, Publish, etc.; Default is a full build and publish)"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
|
||||
shift
|
||||
done
|
||||
|
||||
# Set up the environment to be used for building with clang.
|
||||
if which "clang-3.5" > /dev/null 2>&1; then
|
||||
export CC="$(which clang-3.5)"
|
||||
export CXX="$(which clang++-3.5)"
|
||||
elif which "clang-3.6" > /dev/null 2>&1; then
|
||||
export CC="$(which clang-3.6)"
|
||||
export CXX="$(which clang++-3.6)"
|
||||
elif which clang > /dev/null 2>&1; then
|
||||
export CC="$(which clang)"
|
||||
export CXX="$(which clang++)"
|
||||
else
|
||||
error "Unable to find Clang Compiler"
|
||||
error "Install clang-3.5 or clang3.6"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Load Branch Info
|
||||
while read line; do
|
||||
if [[ $line != \#* ]]; then
|
||||
IFS='=' read -ra splat <<< "$line"
|
||||
export ${splat[0]}="${splat[1]}"
|
||||
fi
|
||||
done < "$REPOROOT/branchinfo.txt"
|
||||
|
||||
# Use a repo-local install directory (but not the artifacts directory because that gets cleaned a lot
|
||||
[ -z "$DOTNET_INSTALL_DIR" ] && export DOTNET_INSTALL_DIR=$REPOROOT/.dotnet_stage0/$(uname)
|
||||
[ -d "$DOTNET_INSTALL_DIR" ] || mkdir -p $DOTNET_INSTALL_DIR
|
||||
|
||||
$REPOROOT/scripts/obtain/dotnet-install.sh --channel $CHANNEL --verbose
|
||||
|
||||
# Put stage 0 on the PATH (for this shell only)
|
||||
PATH="$DOTNET_INSTALL_DIR:$PATH"
|
||||
|
||||
# Increases the file descriptors limit for this bash. It prevents an issue we were hitting during restore
|
||||
FILE_DESCRIPTOR_LIMIT=$( ulimit -n )
|
||||
if [ $FILE_DESCRIPTOR_LIMIT -lt 1024 ]
|
||||
then
|
||||
echo "Increasing file description limit to 1024"
|
||||
ulimit -n 1024
|
||||
fi
|
||||
|
||||
# Restore the build scripts
|
||||
echo "Restoring Build Script projects..."
|
||||
(
|
||||
cd "$DIR/.."
|
||||
dotnet restore --infer-runtimes
|
||||
)
|
||||
|
||||
# Build the builder
|
||||
echo "Compiling Build Scripts..."
|
||||
dotnet publish "$DIR" -o "$DIR/bin" --framework netcoreapp1.0
|
||||
|
||||
export PATH="$OLDPATH"
|
||||
# Run the builder
|
||||
echo "Invoking Build Scripts..."
|
||||
echo "Configuration: $CONFIGURATION"
|
||||
|
||||
$DIR/bin/dotnet-host-build ${targets[@]}
|
||||
exit $?
|
18
build_projects/dotnet-host-build/dotnet-host-build.xproj
Normal file
18
build_projects/dotnet-host-build/dotnet-host-build.xproj
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>d7b9695d-23eb-4ea8-b8ab-707a0092e1d5</ProjectGuid>
|
||||
<RootNamespace>Microsoft.DotNet.Cli.Build</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
28
build_projects/dotnet-host-build/project.json
Normal file
28
build_projects/dotnet-host-build/project.json
Normal file
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"description": "Build scripts for dotnet-cli",
|
||||
"compilationOptions": {
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.5.0-rc2-24027",
|
||||
"Microsoft.CSharp": "4.0.1-rc2-24027",
|
||||
"System.Dynamic.Runtime": "4.0.11-rc2-24027",
|
||||
"System.Reflection.Metadata": "1.3.0-rc2-24027",
|
||||
"System.Runtime.Serialization.Primitives": "4.1.1-rc2-24027",
|
||||
"System.Xml.XmlSerializer": "4.0.11-rc2-24027",
|
||||
"WindowsAzure.Storage": "6.2.2-preview",
|
||||
|
||||
"Microsoft.DotNet.Cli.Build.Framework": {"target":"project"},
|
||||
"shared-build-targets-utils": {"target": "project"}
|
||||
|
||||
},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"imports": [
|
||||
"dnxcore50",
|
||||
"portable-net45+win8"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue