Merge pull request #485 from mtausig/master
[mono.git] / mcs / class / Microsoft.Build.Engine / Microsoft.Build.BuildEngine / BuildItemGroup.cs
index c3ce1237b23af047692670daea7d2a5c841eabba..444731a8cee60b70538b3055085f8b73478c782c 100644 (file)
@@ -25,8 +25,6 @@
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-#if NET_2_0
-
 using System;
 using System.Reflection;
 using System.Collections;
@@ -44,6 +42,7 @@ namespace Microsoft.Build.BuildEngine {
                GroupingCollection      parentCollection;
                Project                 parentProject;
                bool                    read_only;
+               bool evaluated;
 
                public BuildItemGroup ()
                        : this (null, null, null, false)
@@ -75,6 +74,9 @@ namespace Microsoft.Build.BuildEngine {
                                buildItems.Add (bi);
                                project.LastItemGroupContaining [bi.Name] = this;
                        }
+
+                       DefinedInFileName = importedProject != null ? importedProject.FullFileName :
+                                               project != null ? project.FullFileName : null;
                }
 
                public BuildItem AddNewItem (string itemName,
@@ -185,29 +187,45 @@ namespace Microsoft.Build.BuildEngine {
                        buildItems.Add (buildItem);
                }
 
+               // In eval phase, any ref'ed item would've already been expanded
+               // or it doesnt exist, so dont expand again
+               // In non-eval, items have _already_ been expanded, so dont expand again
+               // So, ignore @options
                internal string ConvertToString (Expression transform,
-                                                Expression separator)
+                                                Expression separator, ExpressionOptions options)
                {
                        string separatorString;
                        
+                       // Item refs are not expanded for separator or transform
                        if (separator == null)
                                separatorString = ";";
                        else
-                               separatorString = (string) separator.ConvertTo (parentProject, typeof (string));
+                               separatorString = (string) separator.ConvertTo (parentProject, typeof (string),
+                                                               ExpressionOptions.DoNotExpandItemRefs);
                
                        string[] items = new string [buildItems.Count];
                        int i = 0;
                        foreach (BuildItem bi in  buildItems)
-                               items [i++] = bi.ConvertToString (transform);
+                               items [i++] = bi.ConvertToString (transform, ExpressionOptions.DoNotExpandItemRefs);
                        return String.Join (separatorString, items);
                }
 
-               internal ITaskItem[] ConvertToITaskItemArray (Expression transform)
+               // In eval phase, any ref'ed item would've already been expanded
+               // or it doesnt exist, so dont expand again
+               // In non-eval, items have _already_ been expanded, so dont expand again
+               // So, ignore @options
+               internal ITaskItem[] ConvertToITaskItemArray (Expression transform, Expression separator, ExpressionOptions options)
                {
+                       if (separator != null)
+                               // separator present, so return as a single "join'ed" string
+                               return new ITaskItem [] {
+                                       new TaskItem (ConvertToString (transform, separator, options))
+                               };
+
                        ITaskItem[] array = new ITaskItem [buildItems.Count];
                        int i = 0;
                        foreach (BuildItem item in buildItems)
-                               array [i++] = item.ConvertToITaskItem (transform);
+                               array [i++] = item.ConvertToITaskItem (transform, ExpressionOptions.DoNotExpandItemRefs);
                        return array;
                }
 
@@ -221,6 +239,8 @@ namespace Microsoft.Build.BuildEngine {
 
                internal void Evaluate ()
                {
+                       if (evaluated)
+                               return;
                        foreach (BuildItem bi in buildItems) {
                                if (bi.Condition == String.Empty)
                                        bi.Evaluate (parentProject, true);
@@ -229,6 +249,7 @@ namespace Microsoft.Build.BuildEngine {
                                        bi.Evaluate (parentProject, ce.BoolEvaluate (parentProject));
                                }
                        }
+                       evaluated = true;
                }               
 
                internal void ReplaceWith (BuildItem item, List <BuildItem> list)
@@ -283,6 +304,8 @@ namespace Microsoft.Build.BuildEngine {
                        }
                }
 
+               internal string DefinedInFileName { get; private set; }
+
                internal bool FromXml {
                        get {
                                return itemGroupElement != null;
@@ -296,5 +319,3 @@ namespace Microsoft.Build.BuildEngine {
                }
        }
 }
-
-#endif