Add Conditional Target capabilities to the build scripts

Make Attribute properties immutable

PR Feedback, bugfixes

PR Feedback
This commit is contained in:
Bryan Thornbury 2016-02-19 17:00:41 -08:00 committed by Bryan
parent adc6aa7eff
commit 6d8b622451
16 changed files with 415 additions and 116 deletions

View file

@ -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)