Bring Host build into separate project

This commit is contained in:
Bryan 2016-05-11 17:20:40 -07:00 committed by Eric Erhardt
parent 07b785c183
commit 7bf08c5bd5
76 changed files with 1065 additions and 320 deletions

View file

@ -3,4 +3,5 @@
REM Copyright (c) .NET Foundation and contributors. All rights reserved.
REM Licensed under the MIT license. See LICENSE file in the project root for full license information.
powershell -NoProfile -NoLogo -Command "%~dp0scripts\run-build.ps1 %*; exit $LastExitCode;"
powershell -NoProfile -NoLogo -Command "%~dp0build_projects\dotnet-host-build\build.ps1 %*; exit $LastExitCode;"
powershell -NoProfile -NoLogo -Command "%~dp0build_projects\dotnet-cli-build\build.ps1 %*; exit $LastExitCode;"

View file

@ -47,9 +47,16 @@ done
temp="${args[@]}"
args=($temp)
dockerbuild()
{
BUILD_COMMAND=/opt/code/build_projects/dotnet-host-build/build.sh $DIR/scripts/dockerrun.sh --non-interactive "$@"
BUILD_COMMAND=/opt/code/build_projects/dotnet-cli-build/build.sh $DIR/scripts/dockerrun.sh --non-interactive "$@"
}
# Check if we need to build in docker
if [ ! -z "$BUILD_IN_DOCKER" ]; then
$DIR/scripts/dockerbuild.sh "${args[@]}"
dockerbuild "${args[@]}"
else
$DIR/scripts/run-build.sh "${args[@]}"
$DIR/build_projects/dotnet-host-build/build.sh "${args[@]}"
$DIR/build_projects/dotnet-cli-build/build.sh "${args[@]}"
fi

View file

@ -67,47 +67,20 @@ namespace Microsoft.DotNet.Cli.Build
return c.Success();
}
// Moving PrepareTargets.RestorePackages after PackagePkgProjects because managed code depends on the
// Microsoft.NETCore.App package that is created during PackagePkgProjects.
[Target(nameof(PrepareTargets.Init), nameof(CompileCoreHost), nameof(PackagePkgProjects), nameof(RestoreLockedCoreHost), nameof(PrepareTargets.RestorePackages), nameof(CompileStage1), nameof(CompileStage2))]
[Target(nameof(PrepareTargets.Init), nameof(RestoreLockedCoreHost), nameof(CompileStage1), nameof(CompileStage2))]
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;
PrepareDummyRuntimeNuGetPackage(DotNetCli.Stage0);
foreach (var hostPackage in hostVersion.LatestHostPackages)
{
foreach (var rid in HostPackageSupportedRids.Values.Distinct())
{
if (!rid.Equals(currentRid))
{
CreateDummyRuntimeNuGetPackage(
DotNetCli.Stage0,
hostPackage.Key,
rid,
hostPackage.Value,
Dirs.CorehostDummyPackages);
}
}
}
return c.Success();
}
[Target(nameof(PrepareTargets.Init))]
public static BuildTargetResult RestoreLockedCoreHost(BuildTargetContext c)
{
var hostVersion = c.BuildContext.Get<HostVersion>("HostVersion");
var lockedHostFxrVersion = hostVersion.LockedHostFxrVersion;
var currentRid = HostPackagePlatformRid;
string projectJson = $@"{{
""dependencies"": {{
""Microsoft.NETCore.DotNetHostResolver"" : ""{lockedHostFxrVersion}""
@ -146,176 +119,6 @@ namespace Microsoft.DotNet.Cli.Build
return c.Success();
}
[Target(nameof(PrepareTargets.Init))]
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 = 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();
}
private static string GetRuntimeId()
{
string info = DotNetCli.Stage0.Exec("", "--info").CaptureStdOut().Execute().StdOut;
string rid = Array.Find<string>(info.Split(Environment.NewLine.ToCharArray()), (e) => e.Contains("RID:"))?.Replace("RID:", "").Trim();
// TODO: when Stage0 is updated with the new --info, remove this legacy check for --version
if (string.IsNullOrEmpty(rid))
{
string version = DotNetCli.Stage0.Exec("", "--version").CaptureStdOut().Execute().StdOut;
rid = Array.Find<string>(version.Split(Environment.NewLine.ToCharArray()), (e) => e.Contains("Runtime Id:")).Replace("Runtime Id:", "").Trim();
}
if (string.IsNullOrEmpty(rid))
{
throw new BuildFailureException("Could not find the Runtime ID from Stage0 --info or --version");
}
return rid;
}
[Target(nameof(PrepareTargets.Init))]
public static BuildTargetResult CompileStage1(BuildTargetContext c)
{
@ -393,64 +196,6 @@ namespace Microsoft.DotNet.Cli.Build
return c.Success();
}
private static void PrepareDummyRuntimeNuGetPackage(DotNetCli dotnet)
{
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(Dirs.Intermediate, "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();
}
private static void CreateDummyRuntimeNuGetPackage(DotNetCli dotnet, string basePackageId, string rid, string version, string outputDir)
{
var packageId = $"runtime.{rid}.{basePackageId}";
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(Dirs.Intermediate, "dummyNuGetPackageIntermediate");
var tempPjFile = Path.Combine(tempPjDirectory, "project.json");
File.WriteAllText(tempPjFile, projectJson.ToString());
dotnet.Pack(
tempPjFile, "--no-build",
"--output", outputDir)
.WorkingDirectory(tempPjDirectory)
.Execute()
.EnsureSuccessful();
}
private static void CleanOutputDir(string directory)
{
foreach (var file in FilesToClean)

View file

@ -33,7 +33,13 @@ namespace Microsoft.DotNet.Cli.Build
public static BuildTargetResult CheckInstallerBuildPlatformDependencies(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(UpdateTemplateVersions), nameof(CheckPrereqs), nameof(LocateStage0), nameof(ExpectedBuildArtifacts))]
[Target(
nameof(GenerateVersions),
nameof(UpdateTemplateVersions),
nameof(CheckPrereqs),
nameof(LocateStage0),
nameof(ExpectedBuildArtifacts),
nameof(RestorePackages))]
public static BuildTargetResult Init(BuildTargetContext c)
{
var configEnv = Environment.GetEnvironmentVariable("CONFIGURATION");

View file

@ -552,3 +552,4 @@ namespace Microsoft.DotNet.Cli.Build
}
}
}

View file

@ -8,24 +8,23 @@ param(
[string]$Architecture="x64",
[string[]]$Targets=@("Default"),
[switch]$NoPackage,
[switch]$RunInstallerTestsInDocker,
[switch]$Help)
if($Help)
{
Write-Host "Usage: .\build.cmd [-Configuration <CONFIGURATION>] [-NoPackage] [-Help] [-Targets <TARGETS...>]"
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 " -RunInstallerTestsInDocker Runs the .msi installer tests in a Docker container. Requires Windows 2016 TP4 or higher"
Write-Host " -Help Display this help message"
exit 0
}
$env:CONFIGURATION = $Configuration;
$RepoRoot = "$PSScriptRoot\..\.."
if($NoPackage)
{
@ -36,13 +35,8 @@ else
$env:DOTNET_BUILD_SKIP_PACKAGING=0
}
if ($RunInstallerTestsInDocker)
{
$env:RunInstallerTestsInDocker=1
}
# Load Branch Info
cat "$PSScriptRoot\..\branchinfo.txt" | ForEach-Object {
cat "$RepoRoot\branchinfo.txt" | ForEach-Object {
if(!$_.StartsWith("#") -and ![String]::IsNullOrWhiteSpace($_)) {
$splat = $_.Split([char[]]@("="), 2)
Set-Content "env:\$($splat[0])" -Value $splat[1]
@ -52,7 +46,7 @@ cat "$PSScriptRoot\..\branchinfo.txt" | ForEach-Object {
# 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="$PSScriptRoot\..\.dotnet_stage0\Windows\$Architecture"
$env:DOTNET_INSTALL_DIR="$RepoRoot\.dotnet_stage0\Windows\$Architecture"
}
if (!(Test-Path $env:DOTNET_INSTALL_DIR))
@ -61,26 +55,27 @@ if (!(Test-Path $env:DOTNET_INSTALL_DIR))
}
# Install a stage 0
Write-Host "Installing .NET Core CLI ($Architecture) Stage 0 from '$env:CHANNEL' channel"
& "$PSScriptRoot\obtain\dotnet-install.ps1" -Channel $env:CHANNEL -Architecture $Architecture -Verbose
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
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\dotnet-cli-build" -o "$PSScriptRoot/dotnet-cli-build/bin" --framework netstandardapp1.5
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\dotnet-cli-build\bin\dotnet-cli-build.exe" @Targets
& "$PSScriptRoot\bin\dotnet-cli-build.exe" @Targets
if($LASTEXITCODE -ne 0) { throw "Build failed" }

View file

@ -15,7 +15,8 @@ done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
OLDPATH="$PATH"
source "$DIR/common/_prettyprint.sh"
REPOROOT="$DIR/../.."
source "$REPOROOT/scripts/common/_prettyprint.sh"
while [[ $# > 0 ]]; do
lowerI="$(echo $1 | awk '{print tolower($0)}')"
@ -78,13 +79,13 @@ while read line; do
IFS='=' read -ra splat <<< "$line"
export ${splat[0]}="${splat[1]}"
fi
done < "$DIR/../branchinfo.txt"
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=$DIR/../.dotnet_stage0/$(uname)
[ -d $DOTNET_INSTALL_DIR ] || mkdir -p $DOTNET_INSTALL_DIR
[ -z "$DOTNET_INSTALL_DIR" ] && export DOTNET_INSTALL_DIR=$REPOROOT/.dotnet_stage0/$(uname)
[ -d "$DOTNET_INSTALL_DIR" ] || mkdir -p $DOTNET_INSTALL_DIR
$DIR/obtain/dotnet-install.sh --channel $CHANNEL --verbose
$REPOROOT/scripts/obtain/dotnet-install.sh --channel $CHANNEL --verbose
# Put stage 0 on the PATH (for this shell only)
PATH="$DOTNET_INSTALL_DIR:$PATH"
@ -100,24 +101,18 @@ fi
# Restore the build scripts
echo "Restoring Build Script projects..."
(
cd $DIR
cd "$DIR/.."
dotnet restore --infer-runtimes
)
# Build the builder
echo "Compiling Build Scripts..."
dotnet publish "$DIR/dotnet-cli-build" -o "$DIR/dotnet-cli-build/bin" --framework netstandardapp1.5
dotnet publish "$DIR" -o "$DIR/bin" --framework netcoreapp1.0
export PATH="$OLDPATH"
# Run the builder
echo "Invoking Build Scripts..."
echo "Configuration: $CONFIGURATION"
if [ -f "$DIR/dotnet-cli-build/bin/dotnet-cli-build" ]; then
$DIR/dotnet-cli-build/bin/dotnet-cli-build ${targets[@]}
$DIR/bin/dotnet-cli-build ${targets[@]}
exit $?
else
# We're on an older CLI. This is temporary while Ubuntu and CentOS VSO builds are stalled.
$DIR/dotnet-cli-build/bin/Debug/dnxcore50/dotnet-cli-build "${targets[@]}"
exit $?
fi

View file

@ -0,0 +1,27 @@
{
"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"
]
}
}
}

View 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();
}
}
}

View 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();
}
}
}

View 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);
}
}
}

View 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();
}
}
}

View 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" }

View 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 $?

View 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>

View 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"
]
}
}
}

View file

@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.DotNet.Cli.Build
{
public class PackageDependencies
{
public static string[] DebianPackageBuildDependencies
{
get
{
return new string[]
{
"devscripts",
"debhelper",
"build-essential"
};
}
}
public static string[] UbuntuCoreclrAndCoreFxDependencies
{
get
{
return new string[]
{
"libc6",
"libedit2",
"libffi6",
"libgcc1",
"libicu52",
"liblldb-3.6",
"libllvm3.6",
"liblttng-ust0",
"liblzma5",
"libncurses5",
"libpython2.7",
"libstdc++6",
"libtinfo5",
"libunwind8",
"liburcu1",
"libuuid1",
"zlib1g",
"libasn1-8-heimdal",
"libcomerr2",
"libcurl3",
"libgcrypt11",
"libgnutls26",
"libgpg-error0",
"libgssapi3-heimdal",
"libgssapi-krb5-2",
"libhcrypto4-heimdal",
"libheimbase1-heimdal",
"libheimntlm0-heimdal",
"libhx509-5-heimdal",
"libidn11",
"libk5crypto3",
"libkeyutils1",
"libkrb5-26-heimdal",
"libkrb5-3",
"libkrb5support0",
"libldap-2.4-2",
"libp11-kit0",
"libroken18-heimdal",
"librtmp0",
"libsasl2-2",
"libsqlite3-0",
"libssl1.0.0",
"libtasn1-6",
"libwind0-heimdal"
};
}
}
public static string[] CentosCoreclrAndCoreFxDependencies
{
get
{
return new string[]
{
"unzip",
"libunwind",
"gettext",
"libcurl-devel",
"openssl-devel",
"zlib",
"libicu-devel"
};
}
}
}
}

View file

@ -10,7 +10,7 @@ namespace Microsoft.DotNet.Cli.Build
{
public class AptDependencyUtility
{
internal static bool PackageIsInstalled(string packageName)
public static bool PackageIsInstalled(string packageName)
{
var result = Command.Create("dpkg", "-s", packageName)
.CaptureStdOut()

View file

@ -0,0 +1,47 @@
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 static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
namespace Microsoft.DotNet.Cli.Build
{
public class BranchInfo
{
private static readonly string s_branchInfoFileName = "branchinfo.txt";
private string _repoRoot;
private string _branchInfoFile;
public IDictionary<string, string> Entries { get; set; }
public BranchInfo(string repoRoot)
{
_repoRoot = repoRoot;
_branchInfoFile = Path.Combine(_repoRoot, s_branchInfoFileName);
Entries = ReadBranchInfo(_branchInfoFile);
}
private IDictionary<string, string> ReadBranchInfo(string path)
{
var lines = File.ReadAllLines(path);
var dict = new Dictionary<string, string>();
foreach (var line in lines)
{
if (!line.Trim().StartsWith("#") && !string.IsNullOrWhiteSpace(line))
{
var splat = line.Split(new[] { '=' }, 2);
dict[splat[0]] = splat[1];
}
}
return dict;
}
}
}

View file

@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Build.Framework;
@ -38,6 +39,19 @@ namespace Microsoft.DotNet.Cli.Build
public Command Test(params string[] args) => Exec("test", args);
public Command Publish(params string[] args) => Exec("publish", args);
public string GetRuntimeId()
{
string info = Exec("", "--info").CaptureStdOut().Execute().StdOut;
string rid = Array.Find<string>(info.Split(Environment.NewLine.ToCharArray()), (e) => e.Contains("RID:"))?.Replace("RID:", "").Trim();
if (string.IsNullOrEmpty(rid))
{
throw new BuildFailureException("Could not find the Runtime ID from Stage0 --info or --version");
}
return rid;
}
private static string GetStage0Path()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))

View file

@ -136,6 +136,11 @@ namespace Microsoft.DotNet.Cli.Build
}
}
public static string GetVersionFileContent(string commitHash, string version)
{
return $@"{commitHash}{Environment.NewLine}{version}{Environment.NewLine}";
}
public static string GetSharedFrameworkVersionFileContent(BuildTargetContext c)
{
string SharedFrameworkNugetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");

View file

@ -8,7 +8,7 @@ namespace Microsoft.DotNet.Cli.Build
{
public class YumDependencyUtility
{
internal static bool PackageIsInstalled(string packageName)
public static bool PackageIsInstalled(string packageName)
{
var result = Command.Create("yum", "list", "installed", packageName)
.CaptureStdOut()

View file

@ -1,9 +1,6 @@
{
"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",
@ -15,7 +12,7 @@
"WindowsAzure.Storage": "6.2.2-preview"
},
"frameworks": {
"netstandardapp1.5": {
"netstandard1.5": {
"imports": [
"dnxcore50",
"portable-net45+win8"

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0.25123" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.25123</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>b768bd29-12bf-4c7c-b093-03193fe244d1</ProjectGuid>
<RootNamespace>shared-build-targets-utils</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View file

@ -1,13 +0,0 @@
#!/usr/bin/env bash
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 )"
BUILD_COMMAND=/opt/code/scripts/run-build.sh $DIR/dockerrun.sh --non-interactive "$@"