1 // Copyright (c) Microsoft. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3 //-----------------------------------------------------------------------
4 // </copyright>
5 // <summary>An interface for objects which can have project xml evaluated into them.</summary>
6 //-----------------------------------------------------------------------
7 
8 using System;
9 using System.Collections.Generic;
10 using System.Text;
11 using Microsoft.Build.Construction;
12 using Microsoft.Build.Evaluation;
13 using Microsoft.Build.Execution;
14 using Microsoft.Build.Collections;
15 using Microsoft.Build.BackEnd;
16 
17 namespace Microsoft.Build.Evaluation
18 {
19     /// <summary>
20     /// An interface for objects which the Evaluator can use as a destination for evaluation of ProjectRootElement.
21     /// </summary>
22     /// <typeparam name="P">The type of properties to be produced.</typeparam>
23     /// <typeparam name="I">The type of items to be produced.</typeparam>
24     /// <typeparam name="M">The type of metadata on those items.</typeparam>
25     /// <typeparam name="D">The type of item definitions to be produced.</typeparam>
26     internal interface IEvaluatorData<P, I, M, D> : IPropertyProvider<P>, IItemProvider<I>
27         where P : class, IProperty, IEquatable<P>, IValued
28         where I : class, IItem
29         where M : class, IMetadatum
30         where D : class, IItemDefinition<M>
31     {
32 
33         /// <summary>
34         /// The ID of this evaluation
35         /// </summary>
36         int EvaluationId
37         {
38             get;
39             set;
40         }
41 
42         /// <summary>
43         /// The (project) directory that should be used during evaluation
44         /// </summary>
45         string Directory
46         {
47             get;
48         }
49 
50         /// <summary>
51         /// Task classes and locations known to this project.
52         /// This is the project-specific task registry, which is consulted before
53         /// the toolset's task registry.
54         /// </summary>
55         TaskRegistry TaskRegistry
56         {
57             get;
58             set;
59         }
60 
61         /// <summary>
62         /// The toolset data used during evaluation, and which should be used for build.
63         /// </summary>
64         Toolset Toolset
65         {
66             get;
67         }
68 
69         /// <summary>
70         /// The sub-toolset version that should be used with this toolset to determine
71         /// the full set of properties to be used by the build.
72         /// </summary>
73         string SubToolsetVersion
74         {
75             get;
76         }
77 
78         /// <summary>
79         /// The externally specified tools version to evaluate with, if any.
80         /// For example, the tools version from a /tv switch.
81         /// This is not the tools version specified on the Project tag, if any.
82         /// May be null.
83         /// </summary>
84         string ExplicitToolsVersion
85         {
86             get;
87         }
88 
89         /// <summary>
90         /// Gets the global properties
91         /// </summary>
92         PropertyDictionary<ProjectPropertyInstance> GlobalPropertiesDictionary
93         {
94             get;
95         }
96 
97         /// <summary>
98         /// List of names of the properties that, while global, are still treated as overridable
99         /// </summary>
100         ISet<string> GlobalPropertiesToTreatAsLocal
101         {
102             get;
103         }
104 
105         /// <summary>
106         /// Sets the initial targets
107         /// </summary>
108         List<string> InitialTargets
109         {
110             get;
111             set;
112         }
113 
114         /// <summary>
115         /// Sets the default targets
116         /// </summary>
117         List<string> DefaultTargets
118         {
119             get;
120             set;
121         }
122 
123         /// <summary>
124         /// Sets or retrieves the list of targets which run before the keyed target.
125         /// </summary>
126         IDictionary<string, List<TargetSpecification>> BeforeTargets
127         {
128             get;
129             set;
130         }
131 
132         /// <summary>
133         /// Sets or retrieves the list of targets which run after the keyed target.
134         /// </summary>
135         IDictionary<string, List<TargetSpecification>> AfterTargets
136         {
137             get;
138             set;
139         }
140 
141         /// <summary>
142         /// List of possible values for properties inferred from certain conditions,
143         /// keyed by the property name.
144         /// </summary>
145         Dictionary<string, List<string>> ConditionedProperties
146         {
147             get;
148         }
149 
150         /// <summary>
151         /// Whether evaluation should collect items ignoring condition,
152         /// as well as items respecting condition; and collect
153         /// conditioned properties, as well as regular properties
154         /// </summary>
155         bool ShouldEvaluateForDesignTime
156         {
157             get;
158         }
159 
160         /// <summary>
161         /// Tells the evaluator whether it should evaluate elements with false conditions
162         /// </summary>
163         bool CanEvaluateElementsWithFalseConditions
164         {
165             get;
166         }
167 
168         /// <summary>
169         /// Enumerator over properties in this project.
170         /// Exposed for debugging display.
171         /// </summary>
172         PropertyDictionary<P> Properties
173         {
174             get;
175         }
176 
177         /// <summary>
178         /// Enumerator over all item definitions.
179         /// Exposed for debugging display.
180         /// Ideally the dictionary would be exposed, but there are
181         /// covariance problems. (A dictionary of Key, Value cannot be upcast
182         /// to a Dictionary of Key, IValue).
183         /// </summary>
184         IEnumerable<D> ItemDefinitionsEnumerable
185         {
186             get;
187         }
188 
189         /// <summary>
190         /// Enumerator over all items.
191         /// Exposed for debugging display.
192         /// Ideally the dictionary would be exposed, but there are
193         /// covariance problems. (A dictionary of Key, Value cannot be upcast
194         /// to a Dictionary of Key, IValue).
195         /// </summary>
196         ItemDictionary<I> Items
197         {
198             get;
199         }
200 
201         /// <summary>
202         /// Evaluation ordered list of project item elements that were evaluated by the Evaluator
203         /// It means that both the item element's condition and the item group element's conditions evaluated to true
204         /// </summary>
205         List<ProjectItemElement> EvaluatedItemElements
206         {
207             get;
208         }
209 
210         /// <summary>
211         /// Prepares the data block for a new evaluation pass
212         /// </summary>
InitializeForEvaluation(IToolsetProvider toolsetProvider)213         void InitializeForEvaluation(IToolsetProvider toolsetProvider);
214 
215         /// <summary>
216         /// Indicates to the data block that evaluation has completed,
217         /// so for example it can mark datastructures read-only.
218         /// </summary>
FinishEvaluation()219         void FinishEvaluation();
220 
221         /// <summary>
222         /// Adds a new item
223         /// </summary>
AddItem(I item)224         void AddItem(I item);
225 
226         /// <summary>
227         /// Adds a new item to the collection of all items ignoring condition
228         /// </summary>
AddItemIgnoringCondition(I item)229         void AddItemIgnoringCondition(I item);
230 
231         /// <summary>
232         /// Adds a new item definition
233         /// </summary>
AddItemDefinition(string itemType)234         IItemDefinition<M> AddItemDefinition(string itemType);
235 
236         /// <summary>
237         /// Properties encountered during evaluation. These are read during the first evaluation pass.
238         /// Unlike those returned by the Properties property, these are ordered, and include any properties that
239         /// were subsequently overridden by others with the same name. It does not include any
240         /// properties whose conditions did not evaluate to true.
241         /// </summary>
AddToAllEvaluatedPropertiesList(P property)242         void AddToAllEvaluatedPropertiesList(P property);
243 
244         /// <summary>
245         /// Item definition metadata encountered during evaluation. These are read during the second evaluation pass.
246         /// Unlike those returned by the ItemDefinitions property, these are ordered, and include any metadata that
247         /// were subsequently overridden by others with the same name and item type. It does not include any
248         /// elements whose conditions did not evaluate to true.
249         /// </summary>
AddToAllEvaluatedItemDefinitionMetadataList(M itemDefinitionMetadatum)250         void AddToAllEvaluatedItemDefinitionMetadataList(M itemDefinitionMetadatum);
251 
252         /// <summary>
253         /// Items encountered during evaluation. These are read during the third evaluation pass.
254         /// Unlike those returned by the Items property, these are ordered.
255         /// It does not include any elements whose conditions did not evaluate to true.
256         /// It does not include any items added since the last evaluation.
257         /// </summary>
AddToAllEvaluatedItemsList(I item)258         void AddToAllEvaluatedItemsList(I item);
259 
260         /// <summary>
261         /// Retrieves an existing item definition, if any.
262         /// </summary>
GetItemDefinition(string itemType)263         IItemDefinition<M> GetItemDefinition(string itemType);
264 
265         /// <summary>
266         /// Sets a property which does not come from the Xml.
267         /// </summary>
SetProperty(string name, string evaluatedValueEscaped, bool isGlobalProperty, bool mayBeReserved)268         P SetProperty(string name, string evaluatedValueEscaped, bool isGlobalProperty, bool mayBeReserved);
269 
270         /// <summary>
271         /// Sets a property which comes from the Xml.
272         /// Predecessor is any immediately previous property that was overridden by this one during evaluation.
273         /// This would include all properties with the same name that lie above in the logical
274         /// project file, and whose conditions evaluated to true.
275         /// If there are none above this is null.
276         /// </summary>
SetProperty(ProjectPropertyElement propertyElement, string evaluatedValueEscaped, P predecessor)277         P SetProperty(ProjectPropertyElement propertyElement, string evaluatedValueEscaped, P predecessor);
278 
279         /// <summary>
280         /// Retrieves an existing target, if any.
281         /// </summary>
GetTarget(string targetName)282         ProjectTargetInstance GetTarget(string targetName);
283 
284         /// <summary>
285         /// Adds a new target, overwriting any existing target with the same name.
286         /// </summary>
AddTarget(ProjectTargetInstance target)287         void AddTarget(ProjectTargetInstance target);
288 
289         /// <summary>
290         /// Record an import opened during evaluation, if appropriate.
291         /// </summary>
RecordImport(ProjectImportElement importElement, ProjectRootElement import, int versionEvaluated)292         void RecordImport(ProjectImportElement importElement, ProjectRootElement import, int versionEvaluated);
293 
294         /// <summary>
295         /// Record an import opened during evaluation, if appropriate.
296         /// </summary>
RecordImportWithDuplicates(ProjectImportElement importElement, ProjectRootElement import, int versionEvaluated)297         void RecordImportWithDuplicates(ProjectImportElement importElement, ProjectRootElement import, int versionEvaluated);
298 
299         /// <summary>
300         /// Evaluates the provided string by expanding items and properties,
301         /// using the current items and properties available.
302         /// This is useful for the immediate window.
303         /// Does not expand bare metadata expressions.
304         /// </summary>
305         /// <comment>
306         /// Not for internal use.
307         /// </comment>
ExpandString(string unexpandedValue)308         string ExpandString(string unexpandedValue);
309 
310         /// <summary>
311         /// Evaluates the provided string as a condition by expanding items and properties,
312         /// using the current items and properties available, then doing a logical evaluation.
313         /// This is useful for the immediate window.
314         /// Does not expand bare metadata expressions.
315         /// </summary>
316         /// <comment>
317         /// Not for internal use.
318         /// </comment>
EvaluateCondition(string condition)319         bool EvaluateCondition(string condition);
320     }
321 }
322