forked from OmniSharp/omnisharp-roslyn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.cake
297 lines (245 loc) · 9.89 KB
/
common.cake
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
#addin "Newtonsoft.Json"
#tool "nuget:?package=GitVersion.CommandLine&prerelease"
#load "platform.cake"
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net;
public static class Log
{
public static ICakeContext Context { get; set; }
public static void Write(Verbosity verbosity, LogLevel logLevel, string message, params object[] args) =>
Context.Log.Write(verbosity, logLevel, message, args);
public static void Debug(Verbosity verbosity, string message, params object[] args) =>
Write(verbosity, LogLevel.Debug, message, args);
}
public static class FileHelper
{
public static void Copy(string source, string destination, bool overwrite = false)
{
Log.Debug(Verbosity.Diagnostic, "Copy file: {0} to {1}.", source, destination);
System.IO.File.Copy(source, destination, overwrite);
}
public static void Delete(string path)
{
Log.Debug(Verbosity.Diagnostic, "Delete file: {0}.", path);
System.IO.File.Delete(path);
}
public static bool Exists(string path) =>
System.IO.File.Exists(path);
public static void WriteAllLines(string path, string[] contents) =>
System.IO.File.WriteAllLines(path, contents);
}
public static class DirectoryHelper
{
public static void Copy(string source, string destination, bool copySubDirectories = true)
{
var files = System.IO.Directory.GetFiles(source);
var subDirectories = System.IO.Directory.GetDirectories(source);
if (!Exists(destination))
{
Create(destination);
}
foreach (var file in files)
{
var newFile = PathHelper.Combine(destination, PathHelper.GetFileName(file));
FileHelper.Copy(file, newFile, overwrite: true);
}
if (copySubDirectories)
{
foreach (var subDirectory in subDirectories)
{
var newSubDirectory = PathHelper.Combine(destination, PathHelper.GetFileName(subDirectory));
Copy(subDirectory, newSubDirectory);
}
}
}
public static void Create(string path)
{
Log.Debug(Verbosity.Diagnostic, "Create directory: {0}.", path);
System.IO.Directory.CreateDirectory(path);
}
public static void Delete(string path, bool recursive)
{
Log.Debug(Verbosity.Diagnostic, "Delete directory: {0}.", path);
System.IO.Directory.Delete(path, recursive);
}
public static bool Exists(string path) =>
System.IO.Directory.Exists(path);
public static void ForceCreate(string path)
{
if (Exists(path))
{
Delete(path, recursive: true);
}
Create(path);
}
}
public static class PathHelper
{
public static string Combine(params string[] paths) =>
System.IO.Path.Combine(paths);
public static string GetDirectoryName(string path) =>
System.IO.Path.GetDirectoryName(path);
public static string GetFileName(string path) =>
System.IO.Path.GetFileName(path);
public static string GetFullPath(string path) =>
System.IO.Path.GetFullPath(path);
}
string CombinePaths(params string[] paths)
{
return PathHelper.Combine(paths);
}
void DownloadFileAndUnzip(string url, string folder)
{
DirectoryHelper.ForceCreate(folder);
var zipFileName = CombinePaths(folder, "temp.zip");
Information("Downloading {0}", url);
using (var client = new WebClient())
{
client.DownloadFile(url, zipFileName);
}
Unzip(zipFileName, folder);
FileHelper.Delete(zipFileName);
}
public class Folders
{
public string DotNetSdk { get; }
public string LegacyDotNetSdk { get; }
public string Mono { get; }
public string MSBuild { get; }
public string Tools { get; }
public string Bin { get; }
public string Source { get; }
public string Tests { get; }
public string TestAssets { get; }
public string Artifacts { get; }
public string ArtifactsPublish { get; }
public string ArtifactsLogs { get; }
public string ArtifactsPackage { get; }
public string DeploymentPackage { get; }
public string ArtifactsScripts { get; }
public string MonoRuntimeMacOS { get; }
public string MonoRuntimeLinux32 { get; }
public string MonoRuntimeLinux64 { get; }
public string MonoFramework { get; }
public string MonoMSBuildRuntime { get; }
public string MonoMSBuildLib { get; }
public Folders(string workingDirectory)
{
this.DotNetSdk = PathHelper.Combine(workingDirectory, ".dotnet");
this.LegacyDotNetSdk = PathHelper.Combine(workingDirectory, ".dotnet-legacy");
this.Mono = PathHelper.Combine(workingDirectory, ".mono");
this.MSBuild = PathHelper.Combine(workingDirectory, ".msbuild");
this.Tools = PathHelper.Combine(workingDirectory, "tools");
this.Bin = PathHelper.Combine(workingDirectory, "bin");
this.Source = PathHelper.Combine(workingDirectory, "src");
this.Tests = PathHelper.Combine(workingDirectory, "tests");
this.TestAssets = PathHelper.Combine(workingDirectory, "test-assets");
this.Artifacts = PathHelper.Combine(workingDirectory, "artifacts");
this.ArtifactsPublish = PathHelper.Combine(this.Artifacts, "publish");
this.ArtifactsLogs = PathHelper.Combine(this.Artifacts, "logs");
this.ArtifactsPackage = PathHelper.Combine(this.Artifacts, "package");
this.DeploymentPackage = PathHelper.Combine(this.Artifacts, "deployment");
this.ArtifactsScripts = PathHelper.Combine(this.Artifacts, "scripts");
this.MonoRuntimeMacOS = PathHelper.Combine(this.Tools, "Mono.Runtime.MacOS");
this.MonoRuntimeLinux32 = PathHelper.Combine(this.Tools, "Mono.Runtime.Linux-x86");
this.MonoRuntimeLinux64 = PathHelper.Combine(this.Tools, "Mono.Runtime.Linux-x64");
this.MonoFramework = PathHelper.Combine(this.Tools, "Mono.Framework");
this.MonoMSBuildRuntime = PathHelper.Combine(this.Tools, "Microsoft.Build.Runtime.Mono");
this.MonoMSBuildLib = PathHelper.Combine(this.Tools, "Microsoft.Build.Lib.Mono");
}
}
public class MonoRuntime
{
public string PlatformName { get; }
public string InstallFolder { get; }
public string RuntimeFile { get; }
public MonoRuntime(string platformName, string installFolder, string runtimeFile)
{
this.PlatformName = platformName;
this.InstallFolder = installFolder;
this.RuntimeFile = runtimeFile;
}
}
public class BuildEnvironment
{
public string WorkingDirectory { get; }
public Folders Folders { get; }
public string DotNetCommand { get; }
public string LegacyDotNetCommand { get; }
public string ShellCommand { get; }
public string ShellArgument { get; }
public string ShellScriptFileExtension { get; }
public MonoRuntime[] MonoRuntimes { get; }
public MonoRuntime CurrentMonoRuntime { get; }
public GitVersion VersionInfo { get; }
public BuildEnvironment(bool useGlobalDotNetSdk, ICakeContext context)
{
this.WorkingDirectory = context.Environment.WorkingDirectory.FullPath;
this.Folders = new Folders(this.WorkingDirectory);
this.DotNetCommand = useGlobalDotNetSdk
? "dotnet"
: PathHelper.Combine(this.Folders.DotNetSdk, "dotnet");
if (Platform.Current.IsWindows) this.DotNetCommand += ".exe";
this.LegacyDotNetCommand = PathHelper.Combine(this.Folders.LegacyDotNetSdk, "dotnet");
if (Platform.Current.IsWindows) this.LegacyDotNetCommand += ".exe";
this.ShellCommand = Platform.Current.IsWindows ? "powershell" : "bash";
this.ShellArgument = Platform.Current.IsWindows ? "-NoProfile /Command" : "-C";
this.ShellScriptFileExtension = Platform.Current.IsWindows ? "ps1" : "sh";
this.MonoRuntimes = new []
{
new MonoRuntime("osx", this.Folders.MonoRuntimeMacOS, "mono.osx"),
new MonoRuntime("linux-x86", this.Folders.MonoRuntimeLinux32, "mono.linux-x86"),
new MonoRuntime("linux-x64", this.Folders.MonoRuntimeLinux64, "mono.linux-x86_64")
};
if (Platform.Current.IsMacOS)
{
this.CurrentMonoRuntime = this.MonoRuntimes[0];
}
else if (Platform.Current.IsLinux && Platform.Current.Is32Bit)
{
this.CurrentMonoRuntime = this.MonoRuntimes[1];
}
else if (Platform.Current.IsLinux && Platform.Current.Is64Bit)
{
this.CurrentMonoRuntime = this.MonoRuntimes[2];
}
VersionInfo = context.GitVersion();
}
}
/// <summary>
/// Class representing build.json
/// </summary>
public class BuildPlan
{
public string DotNetInstallScriptURL { get; set; }
public string DotNetChannel { get; set; }
public string DotNetVersion { get; set; }
public string[] DotNetSharedRuntimeVersions { get; set; }
public string LegacyDotNetVersion { get; set; }
public string RequiredMonoVersion { get; set; }
public string DownloadURL { get; set; }
public string MonoRuntimeMacOS { get; set; }
public string MonoRuntimeLinux32 { get; set; }
public string MonoRuntimeLinux64 { get; set; }
public string MonoFramework { get; set; }
public string MonoMSBuildRuntime { get; set; }
public string MonoMSBuildLib { get; set; }
public string[] HostProjects { get; set; }
public string[] TestProjects { get; set; }
public string[] TestAssets { get; set; }
public string[] LegacyTestAssets { get; set; }
public string[] CakeTestAssets { get; set; }
public string[] WindowsOnlyTestAssets { get; set; }
public string[] RestoreOnlyTestAssets { get; set; }
public static BuildPlan Load(BuildEnvironment env)
{
var buildJsonPath = PathHelper.Combine(env.WorkingDirectory, "build.json");
return JsonConvert.DeserializeObject<BuildPlan>(
System.IO.File.ReadAllText(buildJsonPath));
}
}
void PrintBlankLine()
{
Information("");
}