some BuildSubmission and BuildResult implementation, as well as tiny bit of build...
authorAtsushi Eno <atsushieno@veritas-vos-liberabit.com>
Thu, 31 Oct 2013 17:55:08 +0000 (02:55 +0900)
committerAtsushi Eno <atsushieno@veritas-vos-liberabit.com>
Tue, 3 Dec 2013 07:50:44 +0000 (16:50 +0900)
mcs/class/Microsoft.Build/Microsoft.Build.Execution/BuildResult.cs
mcs/class/Microsoft.Build/Microsoft.Build.Execution/BuildSubmission.cs
mcs/class/Microsoft.Build/Test/Microsoft.Build.Execution/ProjectInstanceTest.cs

index 021eb624a5559196465182061beaeeaa9274541a..479b137a4f6c7cf6c921a1a16d17d5311d76e0f1 100644 (file)
 
 using System;
 using System.Collections.Generic;
+using System.Linq;
 
 namespace Microsoft.Build.Execution
 {
        public class BuildResult
        {
+               public BuildResult ()
+               {
+                       ResultsByTarget = new Dictionary<string, TargetResult> ();
+               }
+               
                public void AddResultsForTarget (string target, TargetResult result)
                {
-                       throw new NotImplementedException ();
+                       ResultsByTarget.Add (target, result);
                }
 
                public bool HasResultsForTarget (string target)
                {
-                       throw new NotImplementedException ();
+                       return ResultsByTarget.ContainsKey (target);
                }
 
                public void MergeResults (BuildResult results)
                {
-                       throw new NotImplementedException ();
+                       if (ConfigurationId != results.ConfigurationId)
+                               throw new InvalidOperationException ("Argument BuildResults have inconsistent ConfigurationId.");
+                       if (GlobalRequestId != results.GlobalRequestId)
+                               throw new InvalidOperationException ("Argument BuildResults have inconsistent GlobalRequestId.");
+                       if (NodeRequestId != results.NodeRequestId)
+                               throw new InvalidOperationException ("Argument BuildResults have inconsistent NodeRequestId.");
+                       if (ParentGlobalRequestId != results.ParentGlobalRequestId)
+                               throw new InvalidOperationException ("Argument BuildResults have inconsistent ParentGlobalRequestId.");
+                       if (SubmissionId != results.SubmissionId)
+                               throw new InvalidOperationException ("Argument BuildResults have inconsistent SubmissionId.");
+                       
+                       CircularDependency |= results.CircularDependency;
+                       Exception = Exception ?? results.Exception;
+                       foreach (var p in results.ResultsByTarget)
+                               ResultsByTarget.Add (p.Key, p.Value);
                }
 
-               public bool CircularDependency {
-                       get { throw new NotImplementedException (); }
-               }
+               public bool CircularDependency { get; internal set; }
 
-               public int ConfigurationId {
-                       get { throw new NotImplementedException (); }
-               }
+               public int ConfigurationId { get; internal set; }
 
-               public Exception Exception {
-                       get { throw new NotImplementedException (); }
-                       set { throw new NotImplementedException (); }
-               }
+               public Exception Exception { get; set; }
 
-               public int GlobalRequestId {
-                       get { throw new NotImplementedException (); }
-               }
+               public int GlobalRequestId { get; internal set; }
 
                public ITargetResult this [string target] {
-                       get { throw new NotImplementedException (); }
+                       get { return ResultsByTarget [target]; }
                }
 
-               public int NodeRequestId {
-                       get { throw new NotImplementedException (); }
-               }
+               public int NodeRequestId { get; internal set; }
 
+               BuildResultCode? overall_result;
                public BuildResultCode OverallResult {
-                       get { throw new NotImplementedException (); }
+                       get {
+                               if (overall_result == null)
+                                       throw new InvalidOperationException ("Build has not finished");
+                               return overall_result.Value;
+                       }
+                       internal set { overall_result = value; }
                }
 
-               public int ParentGlobalRequestId {
-                       get { throw new NotImplementedException (); }
-               }
+               public int ParentGlobalRequestId { get; internal set; }
 
-               public IDictionary<string, TargetResult> ResultsByTarget {
-                       get { throw new NotImplementedException (); }
-               }
+               public IDictionary<string, TargetResult> ResultsByTarget { get; private set; }
 
-               public int SubmissionId {
-                       get { throw new NotImplementedException (); }
-               }
+               public int SubmissionId { get; internal set; }
        }
 }
 
index 7d92276ce8569b5f5ce7caf1776754c709b7b9b2..7443781ab0e1abc5808ff54daf4631bb422476a0 100644 (file)
@@ -2,8 +2,9 @@
 //
 // Author:
 //   Rolf Bjarne Kvinge (rolf@xamarin.com)
+//   Atsushi Enomoto (atsushi@xamarin.com)
 //
-// Copyright (C) 2011 Xamarin Inc.
+// Copyright (C) 2011,2013 Xamarin Inc.
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -28,6 +29,8 @@
 using System;
 using System.Threading;
 using System.Threading.Tasks;
+using System.Linq;
+using Microsoft.Build.Framework;
 
 namespace Microsoft.Build.Execution
 {
@@ -45,6 +48,7 @@ namespace Microsoft.Build.Execution
                BuildRequestData request;
                BuildSubmissionCompleteCallback callback;
                bool is_started, is_completed, is_canceled;
+               ManualResetEvent wait_handle = new ManualResetEvent (false);
 
                public object AsyncContext { get; private set; }
                public BuildManager BuildManager { get; private set; }
@@ -54,7 +58,11 @@ namespace Microsoft.Build.Execution
                }
                public int SubmissionId { get; private set; }
                public WaitHandle WaitHandle {
-                       get { throw new NotImplementedException (); }
+                       get {
+                               if (!is_started)
+                                       throw new InvalidOperationException ("Build has not started yet");
+                               return wait_handle;
+                       }
                }
 
                internal void Cancel ()
@@ -66,7 +74,30 @@ namespace Microsoft.Build.Execution
 
                public BuildResult Execute ()
                {
-                       throw new NotImplementedException ();
+                       var result = new BuildResult ();
+                       result.SubmissionId = this.SubmissionId;
+                       
+                       // null targets -> success. empty targets -> success(!)
+                       if (request.TargetNames == null)
+                               result.OverallResult = BuildResultCode.Success;
+                       else {
+                               foreach (var targetName in request.TargetNames.Where (t => t != null)) {
+                                       ProjectTargetInstance target;
+                                       // null key is allowed and regarded as blind success(!)
+                                       if (!request.ProjectInstance.Targets.TryGetValue (targetName, out target))
+                                               result.AddResultsForTarget (targetName, new TargetResult (new ITaskItem [0], TargetResultCode.Failure));
+                                       else
+                                               throw new NotImplementedException ();
+                               }
+                       
+                               result.OverallResult = result.ResultsByTarget.Select (p => p.Value).Any (r => r.ResultCode == TargetResultCode.Failure) ? BuildResultCode.Failure : BuildResultCode.Success;
+                       }
+                       
+                       BuildResult = result;
+                       wait_handle.Set ();
+                       if (callback != null)
+                               callback (this);
+                       return BuildResult;
                }
 
                public void ExecuteAsync (BuildSubmissionCompleteCallback callback, object context)
index 943e52fc1cff15eb05e7432dd95b8042e5b7e5e5..ce9aaa4f2b0296c29de4c71e3dcd1233fca6c410 100644 (file)
@@ -38,7 +38,6 @@ namespace MonoTests.Microsoft.Build.Execution
                }
                
                [Test]
-               [Category ("NotWorking")]
                public void BuildEmptyProject ()
                {
                        string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />";