forked from stride3d/stride
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SolutionPlatform.cs
302 lines (268 loc) · 11 KB
/
SolutionPlatform.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using Stride.Core;
using Stride.Core.Settings;
namespace Stride.Core.Assets
{
/// <summary>
/// Defines a solution platform.
/// </summary>
[DataContract("SolutionPlatform")]
public class SolutionPlatform : SolutionPlatformPart
{
/// <summary>
/// Initializes a new instance of the <see cref="SolutionPlatform"/> class.
/// </summary>
public SolutionPlatform()
{
PlatformsPart = new SolutionPlatformPartCollection();
DefineConstants = new List<string>();
}
/// <summary>
/// Gets the alternative names that will appear in the .sln file equivalent to this platform.
/// </summary>
/// <value>The alternative names.</value>
[DataMember(20)]
public SolutionPlatformPartCollection PlatformsPart { get; private set; }
/// <summary>
/// Gets or sets the type of the platform.
/// </summary>
/// <value>The type.</value>
[DataMember(30)]
public PlatformType Type { get; set; }
/// <summary>
/// Gets or sets the type of the platform.
/// </summary>
/// <value>The type.</value>
[DataMember(35)]
public string TargetFramework { get; set; }
/// <summary>
/// Gets or sets the runtime identifier.
/// </summary>
/// <value>The runtime identifier.</value>
[DataMember(35)]
public string RuntimeIdentifier { get; set; }
/// <summary>
/// Gets the define constants that will be used by the csproj of the platform.
/// </summary>
/// <value>The define constants.</value>
[DataMember(40)]
public List<string> DefineConstants { get; private set; }
/// <summary>
/// Gets or sets a value indicating whether this <see cref="SolutionPlatform"/> is available on this machine.
/// </summary>
/// <value><c>true</c> if available; otherwise, <c>false</c>.</value>
[DataMember(50)]
public bool IsAvailable { get; set; }
/// <summary>
/// The list of templates. If empty, no choice will be given to user and default one will be created by concatening ProjectExecutable and <see cref="SolutionPlatformPart.Name"/>.
/// </summary>
[DataMember(60)]
public List<SolutionPlatformTemplate> Templates { get; } = new List<SolutionPlatformTemplate>();
/// <summary>
/// Gets the all <see cref="SolutionPlatformPart"/>.
/// </summary>
/// <returns>IEnumerable<SolutionPlatformPart>.</returns>
public IEnumerable<SolutionPlatformPart> GetParts()
{
// Returns solution platform in alphabetical order
var parts = new List<SolutionPlatformPart>(1 + PlatformsPart.Count) { this };
parts.AddRange(PlatformsPart);
return parts.OrderBy(part => part.SolutionName ?? part.Name, StringComparer.InvariantCultureIgnoreCase);
}
public IEnumerable<string> GetConfigurationProperties(SolutionPlatformPart part, string configuration)
{
if (part == null) throw new ArgumentNullException("part");
if (part.Configurations.Contains(configuration))
{
foreach (var property in part.Configurations[configuration].Properties)
{
yield return property;
}
}
if (part.InheritConfigurations && !ReferenceEquals(part, this))
{
foreach (var property in Configurations[configuration].Properties)
{
yield return property;
}
}
}
public override string ToString()
{
return $"SolutionPlatform {Type}";
}
}
/// <summary>
/// Class SolutionAlternativePlatform.
/// </summary>
[DebuggerDisplay("Solution {Name} Configs [{Configurations.Count}]")]
public class SolutionPlatformPart
{
/// <summary>
/// Initializes a new instance of the <see cref="SolutionPlatformPart"/> class.
/// </summary>
public SolutionPlatformPart()
{
UseWithExecutables = true;
UseWithLibraries = true;
IncludeInSolution = true;
Configurations = new SolutionConfigurationCollection { new SolutionConfiguration("Debug") { IsDebug = true }, new SolutionConfiguration("Release") };
}
/// <summary>
/// Initializes a new instance of the <see cref="SolutionPlatformPart"/> class.
/// </summary>
/// <param name="name">The name.</param>
/// <exception cref="System.ArgumentNullException">name</exception>
public SolutionPlatformPart(string name) : this()
{
if (name == null) throw new ArgumentNullException("name");
Name = name;
}
/// <summary>
/// Gets or sets the name of the alternative platform.
/// </summary>
/// <value>The name.</value>
public string Name { get; set; }
/// <summary>
/// Gets or sets the solution name. If null, use the <see cref="Name"/>
/// </summary>
/// <value>The name.</value>
public string SolutionName { get; set; }
/// <summary>
/// Gets or sets the display name. If null, use the <see cref="Name"/>.
/// </summary>
/// <value>
/// The display name.
/// </value>
public string DisplayName { get; set; }
/// <summary>
/// Gets the name of the solution from <see cref="SolutionName"/>, using <see cref="Name"/> as a fallback.
/// </summary>
/// <value>The name of the safe solution.</value>
public string SafeSolutionName
{
get
{
return SolutionName ?? Name;
}
}
/// <summary>
/// Gets or sets the CPU name, if this platform is CPU specific.
/// </summary>
/// <value>
/// The CPU name.
/// </value>
public string Cpu { get; set; }
/// <summary>
/// Gets or sets the name of the alias. If != null, then this platform is only available in the solution and remapped
/// to the platform with this <see cref="Alias"/>
/// </summary>
/// <value>The name of the alias.</value>
public string Alias { get; set; }
/// <summary>
/// Gets or sets a value indicating whether inherit configurations from parent <see cref="SolutionPlatform"/>
/// </summary>
/// <value><c>true</c> if [inherit configurations]; otherwise, <c>false</c>.</value>
public bool InheritConfigurations { get; set; }
/// <summary>
/// Gets the configurations supported by this platform (by default contains 'Debug' and 'Release')
/// </summary>
public SolutionConfigurationCollection Configurations { get; private set; }
public bool UseWithExecutables { get; set; }
public bool UseWithLibraries { get; set; }
public bool IncludeInSolution { get; set; }
public string LibraryProjectName { get; set; }
public string ExecutableProjectName { get; set; }
/// <summary>
/// Determines whether the project is handled by this platform.
/// </summary>
/// <param name="projectType">Type of the project.</param>
/// <returns><c>true</c> if the project is handled by this platform; otherwise, <c>false</c>.</returns>
public bool IsProjectHandled(ProjectType projectType)
{
return (projectType != ProjectType.Executable || UseWithExecutables) && (projectType != ProjectType.Library || UseWithLibraries);
}
/// <summary>
/// Gets the name of the project configuration from <see cref="Alias"/>, with <see cref="SafeSolutionName"/> as a fallback.
/// </summary>
/// <value>The name of the safe solution.</value>
public string GetProjectName(ProjectType projectType)
{
switch (projectType)
{
case ProjectType.Executable:
return ExecutableProjectName ?? Alias ?? SafeSolutionName;
case ProjectType.Library:
return LibraryProjectName ?? Alias ?? SafeSolutionName;
default:
throw new ArgumentOutOfRangeException("projectType");
}
}
public override string ToString()
{
return $"SolutionPlatformPart {Name} ({Configurations.Count} configs)";
}
}
/// <summary>
/// A collection of <see cref="SolutionPlatformPart"/>
/// </summary>
[DataContract("SolutionPlatformPartCollection")]
public class SolutionPlatformPartCollection : KeyedCollection<string, SolutionPlatformPart>
{
protected override string GetKeyForItem(SolutionPlatformPart item)
{
return item.Name;
}
}
/// <summary>
/// A collection of <see cref="SolutionConfiguration"/>
/// </summary>
[DataContract("SolutionConfigurationCollection")]
public class SolutionConfigurationCollection : KeyedCollection<string, SolutionConfiguration>
{
protected override string GetKeyForItem(SolutionConfiguration item)
{
return item.Name;
}
}
/// <summary>
/// A solution configuration used by <see cref="SolutionPlatform"/>
/// </summary>
[DataContract("SolutionConfiguration")]
[DebuggerDisplay("Config [{Name}]")]
public class SolutionConfiguration
{
/// <summary>
/// Initializes a new instance of the <see cref="SolutionConfiguration"/> class.
/// </summary>
public SolutionConfiguration(string name)
{
if (name == null) throw new ArgumentNullException("name");
Name = name;
Properties = new List<string>();
}
/// <summary>
/// Gets or sets the configuration name (e.g. Debug, Release)
/// </summary>
/// <value>The name.</value>
[DataMember]
public string Name { get; private set; }
/// <summary>
/// Gets or sets a value indicating whether this instance is a debug configuration.
/// </summary>
/// <value><c>true</c> if this instance is debug; otherwise, <c>false</c>.</value>
public bool IsDebug { get; set; }
/// <summary>
/// Gets the additional msbuild properties for a specific configuration (Debug or Release)
/// </summary>
/// <value>The msbuild configuration properties.</value>
[DataMember]
public List<string> Properties { get; private set; }
}
}