forked from ubisoft/Sharpmake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sharpmake.Main.sharpmake.cs
175 lines (144 loc) · 7.11 KB
/
Sharpmake.Main.sharpmake.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Sharpmake;
[module: Sharpmake.Include("Sharpmake/Sharpmake.sharpmake.cs")]
[module: Sharpmake.Include("Sharpmake.Application/Sharpmake.Application.sharpmake.cs")]
[module: Sharpmake.Include("Sharpmake.Extensions/Sharpmake.Extensions.sharpmake.cs")]
[module: Sharpmake.Include("Sharpmake.Generators/Sharpmake.Generators.sharpmake.cs")]
[module: Sharpmake.Include("Sharpmake.Platforms/Sharpmake.Platforms.sharpmake.cs")]
[module: Sharpmake.Include("Sharpmake.UnitTests/Sharpmake.UnitTests.sharpmake.cs")]
[module: Sharpmake.Include("samples/Sharpmake.Samples.sharpmake.cs")]
[module: Sharpmake.Include("Sharpmake.FunctionalTests/Sharpmake.FunctionalTests.sharpmake.cs")]
namespace SharpmakeGen
{
public static class Globals
{
public static string AbsoluteRootPath = string.Empty;
// this holds the path where sharpmake binaries are expected to output
// note that it will contain an subdirectory per optimization
public const string OutputRootPath = @"[project.RootPath]\tmp\bin";
}
public static class Common
{
public static ITarget[] GetDefaultTargets()
{
var result = new List<ITarget>();
result.Add(
new Target(
Platform.anycpu,
DevEnv.vs2019,
Optimization.Debug | Optimization.Release,
framework: DotNetFramework.v4_7_2 | DotNetFramework.net5_0
)
);
return result.ToArray();
}
public abstract class SharpmakeBaseProject : CSharpProject
{
public string DefaultProjectPath = @"[project.RootPath]\tmp\projects\[project.Name]";
protected SharpmakeBaseProject(
bool excludeSharpmakeFiles = true,
bool generateXmlDoc = true
)
{
AddTargets(GetDefaultTargets());
GenerateDocumentationFile = generateXmlDoc;
RootPath = Globals.AbsoluteRootPath;
// Use the new csproj style
ProjectSchema = CSharpProjectSchema.NetCore;
CustomProperties.Add("Deterministic", "true");
// Enable Globalization Invariant Mode
// https://github.com/dotnet/runtime/blob/master/docs/design/features/globalization-invariant-mode.md
CustomProperties.Add("InvariantGlobalization", "true");
if (excludeSharpmakeFiles)
NoneExtensions.Add(".sharpmake.cs");
}
public override void PostResolve()
{
base.PostResolve();
// retrieve the path of the csproj, could have changed from the default
// note that we ensure that it is identical between confs
string projectPath = Configurations.Select(conf => conf.ProjectPath).Distinct().Single();
// we set this property to fix the nuget restore behavior which was different
// between visual studio and command line, since this var was not initialized
// at the same time, leading to the restore being done in different locations
CustomProperties.Add("MSBuildProjectExtensionsPath", Util.PathGetRelative(projectPath, DefaultProjectPath));
}
[Configure]
public virtual void ConfigureAll(Configuration conf, Target target)
{
conf.ProjectFileName = "[project.Name]";
conf.ProjectPath = DefaultProjectPath;
conf.Output = Configuration.OutputType.DotNetClassLibrary;
conf.TargetPath = Path.Combine(Globals.OutputRootPath, "[lower:target.Optimization]");
conf.IntermediatePath = @"[project.RootPath]\tmp\obj\[target.Optimization]\[project.Name]";
conf.BaseIntermediateOutputPath = conf.IntermediatePath;
conf.ReferencesByName.Add("System");
conf.Options.Add(Assembler.SharpmakeScriptsCSharpVersion);
conf.Options.Add(Options.CSharp.TreatWarningsAsErrors.Enabled);
conf.Options.Add(
new Options.CSharp.WarningsNotAsErrors(
618 // W1: CS0618: A class member was marked with the Obsolete attribute, such that a warning will be issued when the class member is referenced
)
);
if (GenerateDocumentationFile)
{
conf.Options.Add(
new Options.CSharp.SuppressWarning(
1570, // W1: CS1570: XML comment on 'construct' has badly formed XML - 'reason
1591 // W4: CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member'
)
);
}
}
}
}
[Generate]
public class SharpmakeSolution : CSharpSolution
{
public SharpmakeSolution()
{
Name = "Sharpmake";
AddTargets(Common.GetDefaultTargets());
var githubFiles = Util.DirectoryGetFiles(Path.Combine(Globals.AbsoluteRootPath, ".github"));
ExtraItems[".github"] = new Strings { githubFiles };
var bashFiles = Util.DirectoryGetFiles(Globals.AbsoluteRootPath, "*.sh", SearchOption.TopDirectoryOnly);
ExtraItems["BashFiles"] = new Strings { bashFiles };
var batchFiles = Util.DirectoryGetFiles(Globals.AbsoluteRootPath, "*.bat", SearchOption.TopDirectoryOnly);
ExtraItems["BatchFiles"] = new Strings { batchFiles };
var pythonFiles = Util.DirectoryGetFiles(Globals.AbsoluteRootPath, "*.py", SearchOption.TopDirectoryOnly);
ExtraItems["PythonFiles"] = new Strings { pythonFiles };
}
[Configure]
public void ConfigureAll(Configuration conf, Target target)
{
conf.SolutionFileName = "[solution.Name]";
conf.SolutionPath = @"[solution.SharpmakeCsPath]\";
conf.AddProject<SharpmakeApplicationProject>(target);
conf.AddProject<SharpmakeUnitTestsProject>(target);
// Platforms, Extensions and Samples
foreach (Type projectType in Assembly.GetExecutingAssembly().GetTypes().Where(t =>
t.IsSubclassOf(typeof(Platforms.PlatformProject)) ||
t.IsSubclassOf(typeof(Extensions.ExtensionProject)) ||
t.IsSubclassOf(typeof(Samples.SampleProject)) ||
t.IsSubclassOf(typeof(FunctionalTests.FunctionalTestProject)))
)
{
conf.AddProject(projectType, target);
}
}
}
public static class Main
{
[Sharpmake.Main]
public static void SharpmakeMain(Arguments arguments)
{
FileInfo sharpmakeFileInfo = Util.GetCurrentSharpmakeFileInfo();
Globals.AbsoluteRootPath = Util.PathMakeStandard(sharpmakeFileInfo.DirectoryName);
arguments.Generate<SharpmakeSolution>();
}
}
}