From adc6aa7eff4dadff955a29bf282e97c4879d0ea4 Mon Sep 17 00:00:00 2001 From: Bryan Date: Thu, 18 Feb 2016 11:39:36 -0800 Subject: [PATCH 1/3] Fixes #832, add debian package and coreclr prereq check to the build. PR Feedback --- .../BuildContext.cs | 7 +- .../CurrentPlatform.cs | 48 +++++ .../project.json | 3 +- scripts/dotnet-cli-build/PrepareTargets.cs | 192 +++++++++++++++--- 4 files changed, 216 insertions(+), 34 deletions(-) create mode 100644 scripts/Microsoft.DotNet.Cli.Build.Framework/CurrentPlatform.cs diff --git a/scripts/Microsoft.DotNet.Cli.Build.Framework/BuildContext.cs b/scripts/Microsoft.DotNet.Cli.Build.Framework/BuildContext.cs index a7b059ce0..499f93a7b 100644 --- a/scripts/Microsoft.DotNet.Cli.Build.Framework/BuildContext.cs +++ b/scripts/Microsoft.DotNet.Cli.Build.Framework/BuildContext.cs @@ -42,7 +42,7 @@ namespace Microsoft.DotNet.Cli.Build.Framework BuildTarget target; if (!Targets.TryGetValue(name, out target)) { - Reporter.Verbose.WriteLine($"Skipping undefined target: {name}"); + throw new Exception($"Undefined target: {name}"); } // Check if it's been completed @@ -82,6 +82,11 @@ namespace Microsoft.DotNet.Cli.Build.Framework 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); diff --git a/scripts/Microsoft.DotNet.Cli.Build.Framework/CurrentPlatform.cs b/scripts/Microsoft.DotNet.Cli.Build.Framework/CurrentPlatform.cs new file mode 100644 index 000000000..0e1cd030d --- /dev/null +++ b/scripts/Microsoft.DotNet.Cli.Build.Framework/CurrentPlatform.cs @@ -0,0 +1,48 @@ +using System; +using System.Runtime.InteropServices; +using Microsoft.Extensions.PlatformAbstractions; + +public static class CurrentPlatform +{ + public static bool IsWindows + { + get + { + return RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + } + } + + public static bool IsOSX + { + get + { + return RuntimeInformation.IsOSPlatform(OSPlatform.OSX); + } + } + + public static bool IsLinux + { + get + { + return RuntimeInformation.IsOSPlatform(OSPlatform.Linux); + } + } + + 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); + } + } +} \ No newline at end of file diff --git a/scripts/Microsoft.DotNet.Cli.Build.Framework/project.json b/scripts/Microsoft.DotNet.Cli.Build.Framework/project.json index dd887545d..ff3a3dbc6 100644 --- a/scripts/Microsoft.DotNet.Cli.Build.Framework/project.json +++ b/scripts/Microsoft.DotNet.Cli.Build.Framework/project.json @@ -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": { diff --git a/scripts/dotnet-cli-build/PrepareTargets.cs b/scripts/dotnet-cli-build/PrepareTargets.cs index dc4905c9d..ce39e4ba4 100644 --- a/scripts/dotnet-cli-build/PrepareTargets.cs +++ b/scripts/dotnet-cli-build/PrepareTargets.cs @@ -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,9 @@ namespace Microsoft.DotNet.Cli.Build [Target(nameof(Init), nameof(RestorePackages))] public static BuildTargetResult Prepare(BuildTargetContext c) => c.Success(); + [Target(nameof(CheckPrereqCmakePresent), nameof(CheckPrereqDebianPackageBuildComponents), nameof(CheckPrereqCoreclrDependencyPackages))] + public static BuildTargetResult CheckPrereqs(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 +95,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 +172,162 @@ cmake is required to build the native host 'corehost'"; return c.Success(); } + [Target] + public static BuildTargetResult CheckPrereqDebianPackageBuildComponents(BuildTargetContext c) + { + if (!CurrentPlatform.IsUbuntu) + { + return c.Success(); + } + + var debianPackageBuildDependencies = new string[] + { + "devscripts", + "debhelper", + "build-essential" + }; + + var messageBuilder = new StringBuilder(); + + foreach (var package in debianPackageBuildDependencies) + { + if (!AptPackageIsInstalled(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] + public static BuildTargetResult CheckPrereqCoreclrDependencyPackages(BuildTargetContext c) + { + if (!CurrentPlatform.IsUbuntu && !CurrentPlatform.IsCentOS) + { + return c.Success(); + } + + var errorMessageBuilder = new StringBuilder(); + var platformPackageCheckAction = default(Func); + var platformCoreclrDependencies = default(string[]); + + if (CurrentPlatform.IsUbuntu) + { + platformCoreclrDependencies = new string[] + { + "unzip", + "curl", + "libicu-dev", + "libunwind8", + "gettext", + "libssl-dev", + "libcurl3-gnutls", + "zlib1g", + "liblttng-ust-dev", + "lldb-3.6-dev", + "lldb-3.6" + }; + + platformPackageCheckAction = AptPackageIsInstalled; + } + else if (CurrentPlatform.IsCentOS) + { + platformCoreclrDependencies = new string[] + { + "unzip", + "libunwind", + "gettext", + "libcurl-devel", + "openssl-devel", + "zlib", + "libicu-devel" + }; + + platformPackageCheckAction = YumPackageIsInstalled; + } + + foreach (var package in platformCoreclrDependencies) + { + if (!platformPackageCheckAction(package)) + { + errorMessageBuilder.Append($"Error: Coreclr package dependency {package} missing."); + 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() + .Execute(); + + return result.ExitCode == 0; + } + + private static bool YumPackageIsInstalled(string packageName) + { + var result = Command.Create("yum", "list", "installed", packageName) + .CaptureStdOut() + .CaptureStdErr() + .Execute(); + + return result.ExitCode == 0; + } + private static IDictionary ReadBranchInfo(BuildTargetContext c, string path) { var lines = File.ReadAllLines(path); From 6d8b622451ddcce1623b3ed61119005d65be79be Mon Sep 17 00:00:00 2001 From: Bryan Thornbury Date: Fri, 19 Feb 2016 17:00:41 -0800 Subject: [PATCH 2/3] Add Conditional Target capabilities to the build scripts Make Attribute properties immutable PR Feedback, bugfixes PR Feedback --- .../BuildContext.cs | 32 ++++- .../BuildSetup.cs | 40 +++++-- .../BuildTarget.cs | 35 +++--- .../Command.cs | 43 +++++-- .../CurrentArchitecture.cs | 50 ++++++++ .../CurrentPlatform.cs | 79 ++++++++---- .../Enumerations/BuildArchitecture.cs | 8 ++ .../Enumerations/BuildPlatform.cs | 10 ++ .../TargetAttribute.cs | 6 +- .../BuildArchitecturesAttribute.cs | 41 +++++++ .../BuildPlatformsAttribute.cs | 41 +++++++ .../TargetConditionAttribute.cs | 9 ++ .../UndefinedTargetException.cs | 9 ++ scripts/docker/ubuntu/Dockerfile | 2 +- scripts/dotnet-cli-build/PrepareTargets.cs | 113 +++++++++++------- scripts/dotnet-cli-build/Program.cs | 13 +- 16 files changed, 415 insertions(+), 116 deletions(-) create mode 100644 scripts/Microsoft.DotNet.Cli.Build.Framework/CurrentArchitecture.cs create mode 100644 scripts/Microsoft.DotNet.Cli.Build.Framework/Enumerations/BuildArchitecture.cs create mode 100644 scripts/Microsoft.DotNet.Cli.Build.Framework/Enumerations/BuildPlatform.cs create mode 100644 scripts/Microsoft.DotNet.Cli.Build.Framework/TargetConditions/BuildArchitecturesAttribute.cs create mode 100644 scripts/Microsoft.DotNet.Cli.Build.Framework/TargetConditions/BuildPlatformsAttribute.cs create mode 100644 scripts/Microsoft.DotNet.Cli.Build.Framework/TargetConditions/TargetConditionAttribute.cs create mode 100644 scripts/Microsoft.DotNet.Cli.Build.Framework/UndefinedTargetException.cs diff --git a/scripts/Microsoft.DotNet.Cli.Build.Framework/BuildContext.cs b/scripts/Microsoft.DotNet.Cli.Build.Framework/BuildContext.cs index 499f93a7b..e4d8846f4 100644 --- a/scripts/Microsoft.DotNet.Cli.Build.Framework/BuildContext.cs +++ b/scripts/Microsoft.DotNet.Cli.Build.Framework/BuildContext.cs @@ -42,7 +42,13 @@ namespace Microsoft.DotNet.Cli.Build.Framework BuildTarget target; if (!Targets.TryGetValue(name, out target)) { - throw new Exception($"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,6 +85,29 @@ 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) diff --git a/scripts/Microsoft.DotNet.Cli.Build.Framework/BuildSetup.cs b/scripts/Microsoft.DotNet.Cli.Build.Framework/BuildSetup.cs index 34eb86afa..17847ccaa 100644 --- a/scripts/Microsoft.DotNet.Cli.Build.Framework/BuildSetup.cs +++ b/scripts/Microsoft.DotNet.Cli.Build.Framework/BuildSetup.cs @@ -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 CollectTargets(Type typ) { return from m in typ.GetMethods() - let attr = m.GetCustomAttribute() - where attr != null - select CreateTarget(m, attr); + let targetAttribute = m.GetCustomAttribute() + let conditionalAttributes = m.GetCustomAttributes(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 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)m.CreateDelegate(typeof(Func))); + name, + $"{methodInfo.DeclaringType.FullName}.{methodInfo.Name}", + targetAttribute.Dependencies, + conditions, + (Func)methodInfo.CreateDelegate(typeof(Func))); + } + + private static IEnumerable> ExtractTargetConditionsFromAttributes( + IEnumerable targetConditionAttributes) + { + if (targetConditionAttributes == null || targetConditionAttributes.Count() == 0) + { + return Enumerable.Empty>(); + } + + return targetConditionAttributes + .Select>(c => c.EvaluateCondition) + .ToArray(); } private string GenerateSourceString(string file, int? line, string member) diff --git a/scripts/Microsoft.DotNet.Cli.Build.Framework/BuildTarget.cs b/scripts/Microsoft.DotNet.Cli.Build.Framework/BuildTarget.cs index 303e0ae66..d3b161885 100644 --- a/scripts/Microsoft.DotNet.Cli.Build.Framework/BuildTarget.cs +++ b/scripts/Microsoft.DotNet.Cli.Build.Framework/BuildTarget.cs @@ -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 Dependencies { get; } - public Func Body { get; } + public IEnumerable Dependencies { get; } + public IEnumerable> Conditions { get; } + public Func Body { get; } - public BuildTarget(string name, string source) : this(name, source, Enumerable.Empty(), null) { } - public BuildTarget(string name, string source, IEnumerable dependencies) : this(name, source, dependencies, null) { } - public BuildTarget(string name, string source, IEnumerable dependencies, Func body) - { - Name = name; + public BuildTarget(string name, string source) : this(name, source, Enumerable.Empty(), Enumerable.Empty>(), null) { } + public BuildTarget(string name, string source, IEnumerable dependencies) : this(name, source, dependencies, Enumerable.Empty>(), null) { } + public BuildTarget( + string name, + string source, + IEnumerable dependencies, + IEnumerable> conditions, + Func body) + { + Name = name; Source = source; - Dependencies = dependencies; - Body = body; - } - } + Dependencies = dependencies; + Conditions = conditions; + Body = body; + } + } } \ No newline at end of file diff --git a/scripts/Microsoft.DotNet.Cli.Build.Framework/Command.cs b/scripts/Microsoft.DotNet.Cli.Build.Framework/Command.cs index 70faf13c2..89c0e9f16 100644 --- a/scripts/Microsoft.DotNet.Cli.Build.Framework/Command.cs +++ b/scripts/Microsoft.DotNet.Cli.Build.Framework/Command.cs @@ -25,6 +25,7 @@ namespace Microsoft.DotNet.Cli.Build.Framework private Action _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) diff --git a/scripts/Microsoft.DotNet.Cli.Build.Framework/CurrentArchitecture.cs b/scripts/Microsoft.DotNet.Cli.Build.Framework/CurrentArchitecture.cs new file mode 100644 index 000000000..71aedf03c --- /dev/null +++ b/scripts/Microsoft.DotNet.Cli.Build.Framework/CurrentArchitecture.cs @@ -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); + } + } + } +} \ No newline at end of file diff --git a/scripts/Microsoft.DotNet.Cli.Build.Framework/CurrentPlatform.cs b/scripts/Microsoft.DotNet.Cli.Build.Framework/CurrentPlatform.cs index 0e1cd030d..fb70d37c1 100644 --- a/scripts/Microsoft.DotNet.Cli.Build.Framework/CurrentPlatform.cs +++ b/scripts/Microsoft.DotNet.Cli.Build.Framework/CurrentPlatform.cs @@ -2,47 +2,74 @@ using System; using System.Runtime.InteropServices; using Microsoft.Extensions.PlatformAbstractions; -public static class CurrentPlatform +namespace Microsoft.DotNet.Cli.Build.Framework { - public static bool IsWindows + public static class CurrentPlatform { - get + public static BuildPlatform Current { - return RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + get + { + return DetermineCurrentPlatform(); + } } - } - public static bool IsOSX - { - get + public static bool IsWindows { - return RuntimeInformation.IsOSPlatform(OSPlatform.OSX); + get + { + return RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + } } - } - public static bool IsLinux - { - get + public static bool IsOSX { - return RuntimeInformation.IsOSPlatform(OSPlatform.Linux); + get + { + return RuntimeInformation.IsOSPlatform(OSPlatform.OSX); + } } - } - public static bool IsUbuntu - { - get + public static bool IsUbuntu { - var osname = PlatformServices.Default.Runtime.OperatingSystem; - return string.Equals(osname, "ubuntu", StringComparison.OrdinalIgnoreCase); + get + { + var osname = PlatformServices.Default.Runtime.OperatingSystem; + return string.Equals(osname, "ubuntu", StringComparison.OrdinalIgnoreCase); + } } - } - public static bool IsCentOS - { - get + public static bool IsCentOS { - var osname = PlatformServices.Default.Runtime.OperatingSystem; - return string.Equals(osname, "centos", StringComparison.OrdinalIgnoreCase); + 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); + } } } } \ No newline at end of file diff --git a/scripts/Microsoft.DotNet.Cli.Build.Framework/Enumerations/BuildArchitecture.cs b/scripts/Microsoft.DotNet.Cli.Build.Framework/Enumerations/BuildArchitecture.cs new file mode 100644 index 000000000..b2137ea07 --- /dev/null +++ b/scripts/Microsoft.DotNet.Cli.Build.Framework/Enumerations/BuildArchitecture.cs @@ -0,0 +1,8 @@ +namespace Microsoft.DotNet.Cli.Build.Framework +{ + public enum BuildArchitecture + { + x86 = 1, + x64 = 2 + } +} \ No newline at end of file diff --git a/scripts/Microsoft.DotNet.Cli.Build.Framework/Enumerations/BuildPlatform.cs b/scripts/Microsoft.DotNet.Cli.Build.Framework/Enumerations/BuildPlatform.cs new file mode 100644 index 000000000..d594ca604 --- /dev/null +++ b/scripts/Microsoft.DotNet.Cli.Build.Framework/Enumerations/BuildPlatform.cs @@ -0,0 +1,10 @@ +namespace Microsoft.DotNet.Cli.Build.Framework +{ + public enum BuildPlatform + { + Windows = 1, + OSX = 2, + Ubuntu = 3, + CentOS = 4 + } +} \ No newline at end of file diff --git a/scripts/Microsoft.DotNet.Cli.Build.Framework/TargetAttribute.cs b/scripts/Microsoft.DotNet.Cli.Build.Framework/TargetAttribute.cs index 6cc6771fc..c7b851808 100644 --- a/scripts/Microsoft.DotNet.Cli.Build.Framework/TargetAttribute.cs +++ b/scripts/Microsoft.DotNet.Cli.Build.Framework/TargetAttribute.cs @@ -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 Dependencies { get; } @@ -20,5 +20,5 @@ namespace Microsoft.DotNet.Cli.Build.Framework { Dependencies = dependencies; } - } + } } \ No newline at end of file diff --git a/scripts/Microsoft.DotNet.Cli.Build.Framework/TargetConditions/BuildArchitecturesAttribute.cs b/scripts/Microsoft.DotNet.Cli.Build.Framework/TargetConditions/BuildArchitecturesAttribute.cs new file mode 100644 index 000000000..b166dd36f --- /dev/null +++ b/scripts/Microsoft.DotNet.Cli.Build.Framework/TargetConditions/BuildArchitecturesAttribute.cs @@ -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 _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; + } + } +} \ No newline at end of file diff --git a/scripts/Microsoft.DotNet.Cli.Build.Framework/TargetConditions/BuildPlatformsAttribute.cs b/scripts/Microsoft.DotNet.Cli.Build.Framework/TargetConditions/BuildPlatformsAttribute.cs new file mode 100644 index 000000000..d05655a67 --- /dev/null +++ b/scripts/Microsoft.DotNet.Cli.Build.Framework/TargetConditions/BuildPlatformsAttribute.cs @@ -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 _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; + } + } +} \ No newline at end of file diff --git a/scripts/Microsoft.DotNet.Cli.Build.Framework/TargetConditions/TargetConditionAttribute.cs b/scripts/Microsoft.DotNet.Cli.Build.Framework/TargetConditions/TargetConditionAttribute.cs new file mode 100644 index 000000000..74243f06a --- /dev/null +++ b/scripts/Microsoft.DotNet.Cli.Build.Framework/TargetConditions/TargetConditionAttribute.cs @@ -0,0 +1,9 @@ +using System; + +namespace Microsoft.DotNet.Cli.Build.Framework +{ + public abstract class TargetConditionAttribute : Attribute + { + public abstract bool EvaluateCondition(); + } +} \ No newline at end of file diff --git a/scripts/Microsoft.DotNet.Cli.Build.Framework/UndefinedTargetException.cs b/scripts/Microsoft.DotNet.Cli.Build.Framework/UndefinedTargetException.cs new file mode 100644 index 000000000..69243ced9 --- /dev/null +++ b/scripts/Microsoft.DotNet.Cli.Build.Framework/UndefinedTargetException.cs @@ -0,0 +1,9 @@ +using System; + +namespace Microsoft.DotNet.Cli.Build.Framework +{ + public class UndefinedTargetException : Exception + { + public UndefinedTargetException(string message) : base(message) { } + } +} \ No newline at end of file diff --git a/scripts/docker/ubuntu/Dockerfile b/scripts/docker/ubuntu/Dockerfile index b5511b589..e9a2b38be 100644 --- a/scripts/docker/ubuntu/Dockerfile +++ b/scripts/docker/ubuntu/Dockerfile @@ -9,7 +9,7 @@ FROM ubuntu:14.04 # 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 + apt-get -qqy install unzip curl libicu-dev libunwind8 gettext libssl-dev libcurl4-openssl-dev zlib1g liblttng-ust-dev lldb-3.6-dev lldb-3.6 # Install Dotnet CLI dependencies. # clang is required for dotnet-compile-native diff --git a/scripts/dotnet-cli-build/PrepareTargets.cs b/scripts/dotnet-cli-build/PrepareTargets.cs index ce39e4ba4..087597a58 100644 --- a/scripts/dotnet-cli-build/PrepareTargets.cs +++ b/scripts/dotnet-cli-build/PrepareTargets.cs @@ -18,9 +18,18 @@ namespace Microsoft.DotNet.Cli.Build [Target(nameof(Init), nameof(RestorePackages))] public static BuildTargetResult Prepare(BuildTargetContext c) => c.Success(); - [Target(nameof(CheckPrereqCmakePresent), nameof(CheckPrereqDebianPackageBuildComponents), nameof(CheckPrereqCoreclrDependencyPackages))] + [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(CheckUbuntuCoreclrDependencies), nameof(CheckCentOSCoreclrDependencies))] + 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) @@ -173,13 +182,9 @@ namespace Microsoft.DotNet.Cli.Build } [Target] - public static BuildTargetResult CheckPrereqDebianPackageBuildComponents(BuildTargetContext c) + [BuildPlatforms(BuildPlatform.Ubuntu)] + public static BuildTargetResult CheckUbuntuDebianPackageBuildDependencies(BuildTargetContext c) { - if (!CurrentPlatform.IsUbuntu) - { - return c.Success(); - } - var debianPackageBuildDependencies = new string[] { "devscripts", @@ -211,58 +216,72 @@ namespace Microsoft.DotNet.Cli.Build } [Target] - public static BuildTargetResult CheckPrereqCoreclrDependencyPackages(BuildTargetContext c) + [BuildPlatforms(BuildPlatform.Ubuntu)] + public static BuildTargetResult CheckUbuntuCoreclrDependencies(BuildTargetContext c) { - if (!CurrentPlatform.IsUbuntu && !CurrentPlatform.IsCentOS) + var errorMessageBuilder = new StringBuilder(); + + var ubuntuCoreclrDependencies = new string[] + { + "unzip", + "curl", + "libicu-dev", + "libunwind8", + "gettext", + "libssl-dev", + "libcurl4-openssl-dev", + "zlib1g", + "liblttng-ust-dev", + "lldb-3.6-dev", + "lldb-3.6" + }; + + foreach (var package in ubuntuCoreclrDependencies) + { + if (!AptPackageIsInstalled(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 CheckCentOSCoreclrDependencies(BuildTargetContext c) + { var errorMessageBuilder = new StringBuilder(); - var platformPackageCheckAction = default(Func); - var platformCoreclrDependencies = default(string[]); - if (CurrentPlatform.IsUbuntu) + var centOSCoreclrDependencies = new string[] { - platformCoreclrDependencies = new string[] - { - "unzip", - "curl", - "libicu-dev", - "libunwind8", - "gettext", - "libssl-dev", - "libcurl3-gnutls", - "zlib1g", - "liblttng-ust-dev", - "lldb-3.6-dev", - "lldb-3.6" - }; + "unzip", + "libunwind", + "gettext", + "libcurl-devel", + "openssl-devel", + "zlib", + "libicu-devel" + }; - platformPackageCheckAction = AptPackageIsInstalled; - } - else if (CurrentPlatform.IsCentOS) + foreach (var package in centOSCoreclrDependencies) { - platformCoreclrDependencies = new string[] - { - "unzip", - "libunwind", - "gettext", - "libcurl-devel", - "openssl-devel", - "zlib", - "libicu-devel" - }; - - platformPackageCheckAction = YumPackageIsInstalled; - } - - foreach (var package in platformCoreclrDependencies) - { - if (!platformPackageCheckAction(package)) + if (!YumPackageIsInstalled(package)) { errorMessageBuilder.Append($"Error: Coreclr package dependency {package} missing."); errorMessageBuilder.Append(Environment.NewLine); + errorMessageBuilder.Append($"-> install with yum install {package}"); + errorMessageBuilder.Append(Environment.NewLine); } } @@ -313,6 +332,7 @@ cmake is required to build the native host 'corehost'"; var result = Command.Create("dpkg", "-s", packageName) .CaptureStdOut() .CaptureStdErr() + .QuietBuildReporter() .Execute(); return result.ExitCode == 0; @@ -323,6 +343,7 @@ cmake is required to build the native host 'corehost'"; var result = Command.Create("yum", "list", "installed", packageName) .CaptureStdOut() .CaptureStdErr() + .QuietBuildReporter() .Execute(); return result.ExitCode == 0; diff --git a/scripts/dotnet-cli-build/Program.cs b/scripts/dotnet-cli-build/Program.cs index bc2661b2c..fe76c3af0 100755 --- a/scripts/dotnet-cli-build/Program.cs +++ b/scripts/dotnet-cli-build/Program.cs @@ -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() - .Run(args); + public static int Main(string[] args) + { + DebugHelper.HandleDebugSwitch(ref args); + + return BuildSetup.Create(".NET Core CLI") + .UseStandardGoals() + .UseAllTargetsFromAssembly() + .Run(args); + } } } From ade5479196227702fa7e29294e9b7bb18369375d Mon Sep 17 00:00:00 2001 From: Bryan Date: Tue, 23 Feb 2016 15:27:03 -0800 Subject: [PATCH 3/3] Update CoreCLR & Corefx dependencies based on ldd method. Use a hardcoded list for ubuntu and slight refactoring for cleaner targets code. --- scripts/docker/ubuntu/Dockerfile | 67 ++++++++++--- .../dotnet-cli-build/PackageDependencies.cs | 96 +++++++++++++++++++ scripts/dotnet-cli-build/PrepareTargets.cs | 66 +++---------- .../Utils/AptDependencyUtility.cs | 24 +++++ .../Utils/YumDependencyUtility.cs | 22 +++++ 5 files changed, 209 insertions(+), 66 deletions(-) create mode 100644 scripts/dotnet-cli-build/PackageDependencies.cs create mode 100644 scripts/dotnet-cli-build/Utils/AptDependencyUtility.cs create mode 100644 scripts/dotnet-cli-build/Utils/YumDependencyUtility.cs diff --git a/scripts/docker/ubuntu/Dockerfile b/scripts/docker/ubuntu/Dockerfile index e9a2b38be..852a81720 100644 --- a/scripts/docker/ubuntu/Dockerfile +++ b/scripts/docker/ubuntu/Dockerfile @@ -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 libcurl4-openssl-dev 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 diff --git a/scripts/dotnet-cli-build/PackageDependencies.cs b/scripts/dotnet-cli-build/PackageDependencies.cs new file mode 100644 index 000000000..9b51237b8 --- /dev/null +++ b/scripts/dotnet-cli-build/PackageDependencies.cs @@ -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" + }; + } + } + + } +} diff --git a/scripts/dotnet-cli-build/PrepareTargets.cs b/scripts/dotnet-cli-build/PrepareTargets.cs index 087597a58..bc10066e9 100644 --- a/scripts/dotnet-cli-build/PrepareTargets.cs +++ b/scripts/dotnet-cli-build/PrepareTargets.cs @@ -24,7 +24,7 @@ namespace Microsoft.DotNet.Cli.Build [Target(nameof(CheckCoreclrPlatformDependencies), nameof(CheckInstallerBuildPlatformDependencies))] public static BuildTargetResult CheckPlatformDependencies(BuildTargetContext c) => c.Success(); - [Target(nameof(CheckUbuntuCoreclrDependencies), nameof(CheckCentOSCoreclrDependencies))] + [Target(nameof(CheckUbuntuCoreclrAndCoreFxDependencies), nameof(CheckCentOSCoreclrAndCoreFxDependencies))] public static BuildTargetResult CheckCoreclrPlatformDependencies(BuildTargetContext c) => c.Success(); [Target(nameof(CheckUbuntuDebianPackageBuildDependencies))] @@ -185,18 +185,14 @@ namespace Microsoft.DotNet.Cli.Build [BuildPlatforms(BuildPlatform.Ubuntu)] public static BuildTargetResult CheckUbuntuDebianPackageBuildDependencies(BuildTargetContext c) { - var debianPackageBuildDependencies = new string[] - { - "devscripts", - "debhelper", - "build-essential" - }; var messageBuilder = new StringBuilder(); + var aptDependencyUtility = new AptDependencyUtility(); - foreach (var package in debianPackageBuildDependencies) + + foreach (var package in PackageDependencies.DebianPackageBuildDependencies) { - if (!AptPackageIsInstalled(package)) + if (!AptDependencyUtility.PackageIsInstalled(package)) { messageBuilder.Append($"Error: Debian package build dependency {package} missing."); messageBuilder.Append(Environment.NewLine); @@ -217,28 +213,14 @@ namespace Microsoft.DotNet.Cli.Build [Target] [BuildPlatforms(BuildPlatform.Ubuntu)] - public static BuildTargetResult CheckUbuntuCoreclrDependencies(BuildTargetContext c) + public static BuildTargetResult CheckUbuntuCoreclrAndCoreFxDependencies(BuildTargetContext c) { var errorMessageBuilder = new StringBuilder(); + var stage0 = DotNetCli.Stage0.BinPath; - var ubuntuCoreclrDependencies = new string[] + foreach (var package in PackageDependencies.UbuntuCoreclrAndCoreFxDependencies) { - "unzip", - "curl", - "libicu-dev", - "libunwind8", - "gettext", - "libssl-dev", - "libcurl4-openssl-dev", - "zlib1g", - "liblttng-ust-dev", - "lldb-3.6-dev", - "lldb-3.6" - }; - - foreach (var package in ubuntuCoreclrDependencies) - { - if (!AptPackageIsInstalled(package)) + if (!AptDependencyUtility.PackageIsInstalled(package)) { errorMessageBuilder.Append($"Error: Coreclr package dependency {package} missing."); errorMessageBuilder.Append(Environment.NewLine); @@ -259,24 +241,13 @@ namespace Microsoft.DotNet.Cli.Build [Target] [BuildPlatforms(BuildPlatform.CentOS)] - public static BuildTargetResult CheckCentOSCoreclrDependencies(BuildTargetContext c) + public static BuildTargetResult CheckCentOSCoreclrAndCoreFxDependencies(BuildTargetContext c) { var errorMessageBuilder = new StringBuilder(); - - var centOSCoreclrDependencies = new string[] + + foreach (var package in PackageDependencies.CentosCoreclrAndCoreFxDependencies) { - "unzip", - "libunwind", - "gettext", - "libcurl-devel", - "openssl-devel", - "zlib", - "libicu-devel" - }; - - foreach (var package in centOSCoreclrDependencies) - { - if (!YumPackageIsInstalled(package)) + if (!YumDependencyUtility.PackageIsInstalled(package)) { errorMessageBuilder.Append($"Error: Coreclr package dependency {package} missing."); errorMessageBuilder.Append(Environment.NewLine); @@ -338,17 +309,6 @@ cmake is required to build the native host 'corehost'"; return result.ExitCode == 0; } - private static bool YumPackageIsInstalled(string packageName) - { - var result = Command.Create("yum", "list", "installed", packageName) - .CaptureStdOut() - .CaptureStdErr() - .QuietBuildReporter() - .Execute(); - - return result.ExitCode == 0; - } - private static IDictionary ReadBranchInfo(BuildTargetContext c, string path) { var lines = File.ReadAllLines(path); diff --git a/scripts/dotnet-cli-build/Utils/AptDependencyUtility.cs b/scripts/dotnet-cli-build/Utils/AptDependencyUtility.cs new file mode 100644 index 000000000..031aa6981 --- /dev/null +++ b/scripts/dotnet-cli-build/Utils/AptDependencyUtility.cs @@ -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; + } + } +} diff --git a/scripts/dotnet-cli-build/Utils/YumDependencyUtility.cs b/scripts/dotnet-cli-build/Utils/YumDependencyUtility.cs new file mode 100644 index 000000000..09e2f04ef --- /dev/null +++ b/scripts/dotnet-cli-build/Utils/YumDependencyUtility.cs @@ -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; + } + } +}