Merge pull request #1504 from dotnet/brthor/build-conditional-targets
Build Conditional Targets & Coreclr/Deb Package Dependencies Check
This commit is contained in:
commit
ca7bab6c11
20 changed files with 713 additions and 89 deletions
|
@ -42,7 +42,13 @@ namespace Microsoft.DotNet.Cli.Build.Framework
|
|||
BuildTarget target;
|
||||
if (!Targets.TryGetValue(name, out target))
|
||||
{
|
||||
Reporter.Verbose.WriteLine($"Skipping undefined target: {name}");
|
||||
throw new UndefinedTargetException($"Undefined target: {name}");
|
||||
}
|
||||
|
||||
if (!EvaluateTargetConditions(target))
|
||||
{
|
||||
Reporter.Verbose.WriteLine($"Skipping, Target Conditions not met: {target.Name}");
|
||||
return new BuildTargetResult(target, success: true);
|
||||
}
|
||||
|
||||
// Check if it's been completed
|
||||
|
@ -53,7 +59,6 @@ namespace Microsoft.DotNet.Cli.Build.Framework
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
// It hasn't, or we're forcing, so run it
|
||||
result = ExecTarget(target);
|
||||
_completedTargets[target.Name] = result;
|
||||
|
@ -80,8 +85,36 @@ namespace Microsoft.DotNet.Cli.Build.Framework
|
|||
Reporter.Error.WriteLine("error".Red().Bold() + $": {message}");
|
||||
}
|
||||
|
||||
private bool EvaluateTargetConditions(BuildTarget target)
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
throw new ArgumentNullException("target");
|
||||
}
|
||||
|
||||
if (target.Conditions == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (var condition in target.Conditions)
|
||||
{
|
||||
if (!condition())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private BuildTargetResult ExecTarget(BuildTarget target)
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
throw new ArgumentNullException("target");
|
||||
}
|
||||
|
||||
var sectionName = $"{target.Name.PadRight(_maxTargetLen + 2).Yellow()} ({target.Source.White()})";
|
||||
BuildReporter.BeginSection("TARGET", sectionName);
|
||||
|
||||
|
|
|
@ -52,8 +52,6 @@ namespace Microsoft.DotNet.Cli.Build.Framework
|
|||
|
||||
public int Run(string[] args)
|
||||
{
|
||||
DebugHelper.HandleDebugSwitch(ref args);
|
||||
|
||||
var targets = new[] { BuildContext.DefaultTarget };
|
||||
if(args.Length > 0)
|
||||
{
|
||||
|
@ -104,18 +102,40 @@ namespace Microsoft.DotNet.Cli.Build.Framework
|
|||
private static IEnumerable<BuildTarget> CollectTargets(Type typ)
|
||||
{
|
||||
return from m in typ.GetMethods()
|
||||
let attr = m.GetCustomAttribute<TargetAttribute>()
|
||||
where attr != null
|
||||
select CreateTarget(m, attr);
|
||||
let targetAttribute = m.GetCustomAttribute<TargetAttribute>()
|
||||
let conditionalAttributes = m.GetCustomAttributes<TargetConditionAttribute>(false)
|
||||
where targetAttribute != null
|
||||
select CreateTarget(m, targetAttribute, conditionalAttributes);
|
||||
}
|
||||
|
||||
private static BuildTarget CreateTarget(MethodInfo m, TargetAttribute attr)
|
||||
private static BuildTarget CreateTarget(
|
||||
MethodInfo methodInfo,
|
||||
TargetAttribute targetAttribute,
|
||||
IEnumerable<TargetConditionAttribute> targetConditionAttributes)
|
||||
{
|
||||
var name = targetAttribute.Name ?? methodInfo.Name;
|
||||
|
||||
var conditions = ExtractTargetConditionsFromAttributes(targetConditionAttributes);
|
||||
|
||||
return new BuildTarget(
|
||||
attr.Name ?? m.Name,
|
||||
$"{m.DeclaringType.FullName}.{m.Name}",
|
||||
attr.Dependencies,
|
||||
(Func<BuildTargetContext, BuildTargetResult>)m.CreateDelegate(typeof(Func<BuildTargetContext, BuildTargetResult>)));
|
||||
name,
|
||||
$"{methodInfo.DeclaringType.FullName}.{methodInfo.Name}",
|
||||
targetAttribute.Dependencies,
|
||||
conditions,
|
||||
(Func<BuildTargetContext, BuildTargetResult>)methodInfo.CreateDelegate(typeof(Func<BuildTargetContext, BuildTargetResult>)));
|
||||
}
|
||||
|
||||
private static IEnumerable<Func<bool>> ExtractTargetConditionsFromAttributes(
|
||||
IEnumerable<TargetConditionAttribute> targetConditionAttributes)
|
||||
{
|
||||
if (targetConditionAttributes == null || targetConditionAttributes.Count() == 0)
|
||||
{
|
||||
return Enumerable.Empty<Func<bool>>();
|
||||
}
|
||||
|
||||
return targetConditionAttributes
|
||||
.Select<TargetConditionAttribute, Func<bool>>(c => c.EvaluateCondition)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private string GenerateSourceString(string file, int? line, string member)
|
||||
|
|
|
@ -4,21 +4,28 @@ using System.Linq;
|
|||
|
||||
namespace Microsoft.DotNet.Cli.Build.Framework
|
||||
{
|
||||
public class BuildTarget
|
||||
{
|
||||
public string Name { get; }
|
||||
public class BuildTarget
|
||||
{
|
||||
public string Name { get; }
|
||||
public string Source { get; }
|
||||
public IEnumerable<string> Dependencies { get; }
|
||||
public Func<BuildTargetContext, BuildTargetResult> Body { get; }
|
||||
public IEnumerable<string> Dependencies { get; }
|
||||
public IEnumerable<Func<bool>> Conditions { get; }
|
||||
public Func<BuildTargetContext, BuildTargetResult> Body { get; }
|
||||
|
||||
public BuildTarget(string name, string source) : this(name, source, Enumerable.Empty<string>(), null) { }
|
||||
public BuildTarget(string name, string source, IEnumerable<string> dependencies) : this(name, source, dependencies, null) { }
|
||||
public BuildTarget(string name, string source, IEnumerable<string> dependencies, Func<BuildTargetContext, BuildTargetResult> body)
|
||||
{
|
||||
Name = name;
|
||||
public BuildTarget(string name, string source) : this(name, source, Enumerable.Empty<string>(), Enumerable.Empty<Func<bool>>(), null) { }
|
||||
public BuildTarget(string name, string source, IEnumerable<string> dependencies) : this(name, source, dependencies, Enumerable.Empty<Func<bool>>(), null) { }
|
||||
public BuildTarget(
|
||||
string name,
|
||||
string source,
|
||||
IEnumerable<string> dependencies,
|
||||
IEnumerable<Func<bool>> conditions,
|
||||
Func<BuildTargetContext, BuildTargetResult> body)
|
||||
{
|
||||
Name = name;
|
||||
Source = source;
|
||||
Dependencies = dependencies;
|
||||
Body = body;
|
||||
}
|
||||
}
|
||||
Dependencies = dependencies;
|
||||
Conditions = conditions;
|
||||
Body = body;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,6 +25,7 @@ namespace Microsoft.DotNet.Cli.Build.Framework
|
|||
private Action<string> _stdErrHandler;
|
||||
|
||||
private bool _running = false;
|
||||
private bool _quietBuildReporter = false;
|
||||
|
||||
private Command(string executable, string args)
|
||||
{
|
||||
|
@ -148,6 +149,12 @@ namespace Microsoft.DotNet.Cli.Build.Framework
|
|||
return this;
|
||||
}
|
||||
|
||||
public Command QuietBuildReporter()
|
||||
{
|
||||
_quietBuildReporter = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandResult Execute()
|
||||
{
|
||||
ThrowIfRunning();
|
||||
|
@ -172,7 +179,7 @@ namespace Microsoft.DotNet.Cli.Build.Framework
|
|||
_process.EnableRaisingEvents = true;
|
||||
|
||||
var sw = Stopwatch.StartNew();
|
||||
BuildReporter.BeginSection("EXEC", FormatProcessInfo(_process.StartInfo));
|
||||
ReportExecBegin();
|
||||
|
||||
_process.Start();
|
||||
|
||||
|
@ -190,15 +197,7 @@ namespace Microsoft.DotNet.Cli.Build.Framework
|
|||
|
||||
var exitCode = _process.ExitCode;
|
||||
|
||||
var message = $"{FormatProcessInfo(_process.StartInfo)} exited with {exitCode}";
|
||||
if (exitCode == 0)
|
||||
{
|
||||
BuildReporter.EndSection("EXEC", message.Green(), success: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
BuildReporter.EndSection("EXEC", message.Red().Bold(), success: false);
|
||||
}
|
||||
ReportExecEnd(exitCode);
|
||||
|
||||
return new CommandResult(
|
||||
_process.StartInfo,
|
||||
|
@ -299,6 +298,30 @@ namespace Microsoft.DotNet.Cli.Build.Framework
|
|||
return info.FileName + " " + info.Arguments;
|
||||
}
|
||||
|
||||
private void ReportExecBegin()
|
||||
{
|
||||
if (!_quietBuildReporter)
|
||||
{
|
||||
BuildReporter.BeginSection("EXEC", FormatProcessInfo(_process.StartInfo));
|
||||
}
|
||||
}
|
||||
|
||||
private void ReportExecEnd(int exitCode)
|
||||
{
|
||||
if (!_quietBuildReporter)
|
||||
{
|
||||
var message = $"{FormatProcessInfo(_process.StartInfo)} exited with {exitCode}";
|
||||
if (exitCode == 0)
|
||||
{
|
||||
BuildReporter.EndSection("EXEC", message.Green(), success: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
BuildReporter.EndSection("EXEC", message.Red().Bold(), success: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ThrowIfRunning([CallerMemberName] string memberName = null)
|
||||
{
|
||||
if (_running)
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Build.Framework
|
||||
{
|
||||
public static class CurrentArchitecture
|
||||
{
|
||||
public static BuildArchitecture Current
|
||||
{
|
||||
get
|
||||
{
|
||||
return DetermineCurrentArchitecture();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool Isx86
|
||||
{
|
||||
get
|
||||
{
|
||||
var archName = PlatformServices.Default.Runtime.RuntimeArchitecture;
|
||||
return string.Equals(archName, "x86", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool Isx64
|
||||
{
|
||||
get
|
||||
{
|
||||
var archName = PlatformServices.Default.Runtime.RuntimeArchitecture;
|
||||
return string.Equals(archName, "x64", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
|
||||
private static BuildArchitecture DetermineCurrentArchitecture()
|
||||
{
|
||||
if (Isx86)
|
||||
{
|
||||
return BuildArchitecture.x86;
|
||||
}
|
||||
else if (Isx64)
|
||||
{
|
||||
return BuildArchitecture.x64;
|
||||
}
|
||||
else
|
||||
{
|
||||
return default(BuildArchitecture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Build.Framework
|
||||
{
|
||||
public static class CurrentPlatform
|
||||
{
|
||||
public static BuildPlatform Current
|
||||
{
|
||||
get
|
||||
{
|
||||
return DetermineCurrentPlatform();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsWindows
|
||||
{
|
||||
get
|
||||
{
|
||||
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsOSX
|
||||
{
|
||||
get
|
||||
{
|
||||
return RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsUbuntu
|
||||
{
|
||||
get
|
||||
{
|
||||
var osname = PlatformServices.Default.Runtime.OperatingSystem;
|
||||
return string.Equals(osname, "ubuntu", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsCentOS
|
||||
{
|
||||
get
|
||||
{
|
||||
var osname = PlatformServices.Default.Runtime.OperatingSystem;
|
||||
return string.Equals(osname, "centos", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
|
||||
private static BuildPlatform DetermineCurrentPlatform()
|
||||
{
|
||||
if (IsWindows)
|
||||
{
|
||||
return BuildPlatform.Windows;
|
||||
}
|
||||
else if (IsOSX)
|
||||
{
|
||||
return BuildPlatform.OSX;
|
||||
}
|
||||
else if (IsUbuntu)
|
||||
{
|
||||
return BuildPlatform.Ubuntu;
|
||||
}
|
||||
else if (IsCentOS)
|
||||
{
|
||||
return BuildPlatform.CentOS;
|
||||
}
|
||||
else
|
||||
{
|
||||
return default(BuildPlatform);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
namespace Microsoft.DotNet.Cli.Build.Framework
|
||||
{
|
||||
public enum BuildArchitecture
|
||||
{
|
||||
x86 = 1,
|
||||
x64 = 2
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
namespace Microsoft.DotNet.Cli.Build.Framework
|
||||
{
|
||||
public enum BuildPlatform
|
||||
{
|
||||
Windows = 1,
|
||||
OSX = 2,
|
||||
Ubuntu = 3,
|
||||
CentOS = 4
|
||||
}
|
||||
}
|
|
@ -5,8 +5,8 @@ using System.Linq;
|
|||
namespace Microsoft.DotNet.Cli.Build.Framework
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
|
||||
public class TargetAttribute : Attribute
|
||||
{
|
||||
public class TargetAttribute : Attribute
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public IEnumerable<string> Dependencies { get; }
|
||||
|
||||
|
@ -20,5 +20,5 @@ namespace Microsoft.DotNet.Cli.Build.Framework
|
|||
{
|
||||
Dependencies = dependencies;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Build.Framework
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
|
||||
public class BuildArchitecturesAttribute : TargetConditionAttribute
|
||||
{
|
||||
private IEnumerable<BuildArchitecture> _buildArchitectures;
|
||||
|
||||
public BuildArchitecturesAttribute(params BuildArchitecture[] architectures)
|
||||
{
|
||||
if (architectures == null)
|
||||
{
|
||||
throw new ArgumentNullException("architectures");
|
||||
}
|
||||
|
||||
_buildArchitectures = architectures;
|
||||
}
|
||||
|
||||
public override bool EvaluateCondition()
|
||||
{
|
||||
var currentArchitecture = CurrentArchitecture.Current;
|
||||
|
||||
if (currentArchitecture == default(BuildArchitecture))
|
||||
{
|
||||
throw new Exception("Unrecognized Architecture");
|
||||
}
|
||||
|
||||
foreach (var architecture in _buildArchitectures)
|
||||
{
|
||||
if (architecture == currentArchitecture)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Build.Framework
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
|
||||
public class BuildPlatformsAttribute : TargetConditionAttribute
|
||||
{
|
||||
private IEnumerable<BuildPlatform> _buildPlatforms;
|
||||
|
||||
public BuildPlatformsAttribute(params BuildPlatform[] platforms)
|
||||
{
|
||||
if (platforms == null)
|
||||
{
|
||||
throw new ArgumentNullException("platforms");
|
||||
}
|
||||
|
||||
_buildPlatforms = platforms;
|
||||
}
|
||||
|
||||
public override bool EvaluateCondition()
|
||||
{
|
||||
var currentPlatform = CurrentPlatform.Current;
|
||||
|
||||
if (currentPlatform == default(BuildPlatform))
|
||||
{
|
||||
throw new Exception("Unrecognized Platform.");
|
||||
}
|
||||
|
||||
foreach (var platform in _buildPlatforms)
|
||||
{
|
||||
if (platform == currentPlatform)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
using System;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Build.Framework
|
||||
{
|
||||
public abstract class TargetConditionAttribute : Attribute
|
||||
{
|
||||
public abstract bool EvaluateCondition();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
using System;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Build.Framework
|
||||
{
|
||||
public class UndefinedTargetException : Exception
|
||||
{
|
||||
public UndefinedTargetException(string message) : base(message) { }
|
||||
}
|
||||
}
|
|
@ -3,7 +3,8 @@
|
|||
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.0.0-rc2-23811",
|
||||
"System.Diagnostics.Process": "4.1.0-rc2-23811"
|
||||
"System.Diagnostics.Process": "4.1.0-rc2-23811",
|
||||
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-16537"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
|
|
|
@ -6,39 +6,80 @@
|
|||
# Dockerfile that creates a container suitable to build dotnet-cli
|
||||
FROM ubuntu:14.04
|
||||
|
||||
# Misc Dependencies for build
|
||||
RUN apt-get update && apt-get -qqy install curl unzip gettext sudo
|
||||
|
||||
# This could become a "microsoft/coreclr" image, since it just installs the dependencies for CoreCLR (and stdlib)
|
||||
# Install CoreCLR and CoreFx dependencies
|
||||
RUN apt-get update && \
|
||||
apt-get -qqy install unzip curl libicu-dev libunwind8 gettext libssl-dev libcurl3-gnutls zlib1g liblttng-ust-dev lldb-3.6-dev lldb-3.6
|
||||
RUN echo "deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.6 main" | tee /etc/apt/sources.list.d/llvm.list && \
|
||||
curl http://llvm.org/apt/llvm-snapshot.gpg.key | apt-key add - && \
|
||||
apt-get update && apt-get -qqy install\
|
||||
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
|
||||
|
||||
# Install Dotnet CLI dependencies.
|
||||
# clang is required for dotnet-compile-native
|
||||
RUN apt-get -qqy install clang-3.5
|
||||
|
||||
# Install Build Prereqs
|
||||
RUN echo "deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.6 main" | tee /etc/apt/sources.list.d/llvm.list && \
|
||||
curl http://llvm.org/apt/llvm-snapshot.gpg.key | apt-key add - && \
|
||||
apt-get update && \
|
||||
apt-get install -y debhelper build-essential devscripts git cmake
|
||||
RUN apt-get -qq install -y debhelper build-essential devscripts git cmake
|
||||
|
||||
# Use clang as c++ compiler
|
||||
RUN update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-3.5 100
|
||||
RUN update-alternatives --set c++ /usr/bin/clang++-3.5
|
||||
|
||||
# Install azure cli. We need this to publish artifacts.
|
||||
RUN apt-get -y install nodejs-legacy && \
|
||||
apt-get -y install npm && \
|
||||
RUN apt-get -qqy install nodejs-legacy && \
|
||||
apt-get -qqy install npm && \
|
||||
npm install -g azure-cli
|
||||
|
||||
|
||||
RUN apt-get install -qqy sudo
|
||||
|
||||
# Setup User to match Host User, and give superuser permissions
|
||||
ARG USER_ID=0
|
||||
RUN useradd -m code_executor -u ${USER_ID} -g sudo
|
||||
RUN echo 'code_executor ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
|
||||
|
||||
# With the User Change, we need to change permssions on these directories
|
||||
# With the User Change, we need to change permissions on these directories
|
||||
RUN chmod -R a+rwx /usr/local
|
||||
RUN chmod -R a+rwx /home
|
||||
RUN chmod -R 755 /usr/lib/sudo
|
||||
|
|
96
scripts/dotnet-cli-build/PackageDependencies.cs
Normal file
96
scripts/dotnet-cli-build/PackageDependencies.cs
Normal 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
|
||||
{
|
||||
internal static string[] DebianPackageBuildDependencies
|
||||
{
|
||||
get
|
||||
{
|
||||
return new string[]
|
||||
{
|
||||
"devscripts",
|
||||
"debhelper",
|
||||
"build-essential"
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
internal 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"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
internal static string[] CentosCoreclrAndCoreFxDependencies
|
||||
{
|
||||
get
|
||||
{
|
||||
return new string[]
|
||||
{
|
||||
"unzip",
|
||||
"libunwind",
|
||||
"gettext",
|
||||
"libcurl-devel",
|
||||
"openssl-devel",
|
||||
"zlib",
|
||||
"libicu-devel"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
|||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
using static Microsoft.DotNet.Cli.Build.FS;
|
||||
using static Microsoft.DotNet.Cli.Build.Utils;
|
||||
|
@ -17,6 +18,18 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
[Target(nameof(Init), nameof(RestorePackages))]
|
||||
public static BuildTargetResult Prepare(BuildTargetContext c) => c.Success();
|
||||
|
||||
[Target(nameof(CheckPrereqCmakePresent), nameof(CheckPlatformDependencies))]
|
||||
public static BuildTargetResult CheckPrereqs(BuildTargetContext c) => c.Success();
|
||||
|
||||
[Target(nameof(CheckCoreclrPlatformDependencies), nameof(CheckInstallerBuildPlatformDependencies))]
|
||||
public static BuildTargetResult CheckPlatformDependencies(BuildTargetContext c) => c.Success();
|
||||
|
||||
[Target(nameof(CheckUbuntuCoreclrAndCoreFxDependencies), nameof(CheckCentOSCoreclrAndCoreFxDependencies))]
|
||||
public static BuildTargetResult CheckCoreclrPlatformDependencies(BuildTargetContext c) => c.Success();
|
||||
|
||||
[Target(nameof(CheckUbuntuDebianPackageBuildDependencies))]
|
||||
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(CheckPrereqs), nameof(LocateStage0))]
|
||||
public static BuildTargetResult Init(BuildTargetContext c)
|
||||
|
@ -91,38 +104,6 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
public static BuildTargetResult CheckPrereqs(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();
|
||||
}
|
||||
|
||||
[Target]
|
||||
public static BuildTargetResult CheckPackageCache(BuildTargetContext c)
|
||||
{
|
||||
|
@ -200,6 +181,134 @@ cmake is required to build the native host 'corehost'";
|
|||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
[BuildPlatforms(BuildPlatform.Ubuntu)]
|
||||
public static BuildTargetResult CheckUbuntuDebianPackageBuildDependencies(BuildTargetContext c)
|
||||
{
|
||||
|
||||
var messageBuilder = new StringBuilder();
|
||||
var aptDependencyUtility = new AptDependencyUtility();
|
||||
|
||||
|
||||
foreach (var package in PackageDependencies.DebianPackageBuildDependencies)
|
||||
{
|
||||
if (!AptDependencyUtility.PackageIsInstalled(package))
|
||||
{
|
||||
messageBuilder.Append($"Error: Debian package build dependency {package} missing.");
|
||||
messageBuilder.Append(Environment.NewLine);
|
||||
messageBuilder.Append($"-> install with apt-get install {package}");
|
||||
messageBuilder.Append(Environment.NewLine);
|
||||
}
|
||||
}
|
||||
|
||||
if (messageBuilder.Length == 0)
|
||||
{
|
||||
return c.Success();
|
||||
}
|
||||
else
|
||||
{
|
||||
return c.Failed(messageBuilder.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[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();
|
||||
}
|
||||
|
||||
private static bool AptPackageIsInstalled(string packageName)
|
||||
{
|
||||
var result = Command.Create("dpkg", "-s", packageName)
|
||||
.CaptureStdOut()
|
||||
.CaptureStdErr()
|
||||
.QuietBuildReporter()
|
||||
.Execute();
|
||||
|
||||
return result.ExitCode == 0;
|
||||
}
|
||||
|
||||
private static IDictionary<string, string> ReadBranchInfo(BuildTargetContext c, string path)
|
||||
{
|
||||
var lines = File.ReadAllLines(path);
|
||||
|
|
|
@ -4,9 +4,14 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
{
|
||||
public class Program
|
||||
{
|
||||
public static int Main(string[] args) => BuildSetup.Create(".NET Core CLI")
|
||||
.UseStandardGoals()
|
||||
.UseAllTargetsFromAssembly<Program>()
|
||||
.Run(args);
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
DebugHelper.HandleDebugSwitch(ref args);
|
||||
|
||||
return BuildSetup.Create(".NET Core CLI")
|
||||
.UseStandardGoals()
|
||||
.UseAllTargetsFromAssembly<Program>()
|
||||
.Run(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
24
scripts/dotnet-cli-build/Utils/AptDependencyUtility.cs
Normal file
24
scripts/dotnet-cli-build/Utils/AptDependencyUtility.cs
Normal file
|
@ -0,0 +1,24 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.DotNet.Cli.Build.Framework;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Build
|
||||
{
|
||||
public class AptDependencyUtility
|
||||
{
|
||||
internal static bool PackageIsInstalled(string packageName)
|
||||
{
|
||||
var result = Command.Create("dpkg", "-s", packageName)
|
||||
.CaptureStdOut()
|
||||
.CaptureStdErr()
|
||||
.QuietBuildReporter()
|
||||
.Execute();
|
||||
|
||||
return result.ExitCode == 0;
|
||||
}
|
||||
}
|
||||
}
|
22
scripts/dotnet-cli-build/Utils/YumDependencyUtility.cs
Normal file
22
scripts/dotnet-cli-build/Utils/YumDependencyUtility.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.DotNet.Cli.Build.Framework;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Build
|
||||
{
|
||||
public class YumDependencyUtility
|
||||
{
|
||||
internal static bool PackageIsInstalled(string packageName)
|
||||
{
|
||||
var result = Command.Create("yum", "list", "installed", packageName)
|
||||
.CaptureStdOut()
|
||||
.CaptureStdErr()
|
||||
.QuietBuildReporter()
|
||||
.Execute();
|
||||
|
||||
return result.ExitCode == 0;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue