Fix ContinueOnError evaluation (was almost always true). Add more logging.
authorAtsushi Eno <atsushieno@veritas-vos-liberabit.com>
Fri, 22 Nov 2013 07:25:07 +0000 (16:25 +0900)
committerAtsushi Eno <atsushieno@veritas-vos-liberabit.com>
Tue, 3 Dec 2013 07:52:35 +0000 (16:52 +0900)
mcs/class/Microsoft.Build/Microsoft.Build.Internal/BuildEngine4.cs
mcs/class/Microsoft.Build/Test/Microsoft.Build.Execution/ProjectTargetInstanceTest.cs

index e321f8ceec90b67276998c38d793997ee8fcc29f..071122a84e2c383daa063df72f589bd94d525bb9 100644 (file)
@@ -132,7 +132,6 @@ namespace Microsoft.Build.Internal
                                // process DependsOnTargets first.
                                foreach (var dep in project.ExpandString (target.DependsOnTargets).Split (';').Where (s => !string.IsNullOrEmpty (s))) {
                                        var result = BuildTarget (dep, args);
-                                       if (result != null)
                                        args.Result.AddResultsForTarget (dep, result);
                                        if (result.ResultCode == TargetResultCode.Failure) {
                                                targetResult.Failure (null);
@@ -192,31 +191,37 @@ namespace Microsoft.Build.Internal
                                                        throw new InvalidOperationException (string.Format ("Task {0} has property {1} but it is read-only.", ti.Name, p.Key));
                                                prop.SetValue (task, ConvertTo (p.Value, prop.PropertyType), null);
                                        }
+                                       event_source.FireTaskStarted (this, new TaskStartedEventArgs ("Task Started", null, project.FullPath, ti.FullPath, ti.Name));
                                        if (!task.Execute ()) {
+                                               event_source.FireTaskFinished (this, new TaskFinishedEventArgs ("Task Finished", null, project.FullPath, ti.FullPath, ti.Name, false));
                                                targetResult.Failure (null);
-                                               if (!ContinueOnError)
-                                                       break;
-                                       }
-                                       foreach (var to in ti.Outputs) {
-                                               var toItem = to as ProjectTaskOutputItemInstance;
-                                               var toProp = to as ProjectTaskOutputPropertyInstance;
-                                               string taskParameter = toItem != null ? toItem.TaskParameter : toProp.TaskParameter;
-                                               var pi = task.GetType ().GetProperty (taskParameter);
-                                               if (pi == null)
-                                                       throw new InvalidOperationException (string.Format ("Task {0} does not have property {1} specified as TaskParameter", ti.Name, toItem.TaskParameter));
-                                               if (!pi.CanRead)
-                                                       throw new InvalidOperationException (string.Format ("Task {0} has property {1} specified as TaskParameter, but it is write-only", ti.Name, toItem.TaskParameter));
-                                               if (toItem != null)
-                                                       args.Project.AddItem (toItem.ItemType, ConvertFrom (pi.GetValue (task, null)));
-                                               else
-                                                       args.Project.SetProperty (toProp.PropertyName, ConvertFrom (pi.GetValue (task, null)));
+                                               if (!ContinueOnError) {
+                                                       event_source.FireTargetFinished (this, new TargetFinishedEventArgs ("Target Failed", null, targetName, project.FullPath, target.FullPath, false));
+                                                       return targetResult;
+                                               }
+                                       } else {
+                                               event_source.FireTaskFinished (this, new TaskFinishedEventArgs ("Task Finished", null, project.FullPath, ti.FullPath, ti.Name, true));
+                                               foreach (var to in ti.Outputs) {
+                                                       var toItem = to as ProjectTaskOutputItemInstance;
+                                                       var toProp = to as ProjectTaskOutputPropertyInstance;
+                                                       string taskParameter = toItem != null ? toItem.TaskParameter : toProp.TaskParameter;
+                                                       var pi = task.GetType ().GetProperty (taskParameter);
+                                                       if (pi == null)
+                                                               throw new InvalidOperationException (string.Format ("Task {0} does not have property {1} specified as TaskParameter", ti.Name, toItem.TaskParameter));
+                                                       if (!pi.CanRead)
+                                                               throw new InvalidOperationException (string.Format ("Task {0} has property {1} specified as TaskParameter, but it is write-only", ti.Name, toItem.TaskParameter));
+                                                       if (toItem != null)
+                                                               args.Project.AddItem (toItem.ItemType, ConvertFrom (pi.GetValue (task, null)));
+                                                       else
+                                                               args.Project.SetProperty (toProp.PropertyName, ConvertFrom (pi.GetValue (task, null)));
+                                               }
                                        }
                                }
                                Func<string,ITaskItem> creator = s => new TargetOutputTaskItem () { ItemSpec = s };
                                var items = args.Project.GetAllItems (target.Outputs, string.Empty, creator, creator, s => true, (t, s) => {
                                });
                                targetResult.Success (items);
-                               event_source.FireTargetFinished (this, new TargetFinishedEventArgs ("Target Started", null, targetName, project.FullPath, target.FullPath, true));
+                               event_source.FireTargetFinished (this, new TargetFinishedEventArgs ("Target Finished", null, targetName, project.FullPath, target.FullPath, true));
                        }
                        return targetResult;
                }
@@ -440,7 +445,7 @@ namespace Microsoft.Build.Internal
                                case "ErrorAndStop":
                                        return false;
                                }
-                               return project.EvaluateCondition (current_task.ContinueOnError);
+                               return !string.IsNullOrEmpty (current_task.ContinueOnError) && project.EvaluateCondition (current_task.ContinueOnError);
                        }
                }
 
index daccc6c55d0ea76fdfd9b1d43099f99058855050..490feda5bd0a333fd8a6518eed183af6d23bd7e3 100644 (file)
@@ -133,15 +133,16 @@ namespace MonoTests.Microsoft.Build.Execution
                public void DependsOnTargets ()
                {
             string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
+       <Target Name='Bar' DependsOnTargets='Foo' />
        <Target Name='Foo'>
            <Error Text='expected error' />
        </Target>
-       <Target Name='Bar' DependsOnTargets='Foo' />
 </Project>";
             var xml = XmlReader.Create (new StringReader (project_xml));
             var root = ProjectRootElement.Create (xml);
             var proj = new ProjectInstance (root);
-                       Assert.IsFalse (proj.Build ("Bar", new ILogger [] {new ConsoleLogger (LoggerVerbosity.Diagnostic, Console.Error.WriteLine, null, null)}), "#1");
+                       Assert.AreEqual (2, proj.Targets.Count, "#1");
+                       Assert.IsFalse (proj.Build ("Bar", new ILogger [0]), "#2");
                }
        }
 }