-
Notifications
You must be signed in to change notification settings - Fork 240
/
build.cake
281 lines (238 loc) · 10.6 KB
/
build.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
/////////////////////////////////////////////////////////////////////
// ADDINS
/////////////////////////////////////////////////////////////////////
#addin "Cake.FileHelpers"
//////////////////////////////////////////////////////////////////////
// TOOLS
//////////////////////////////////////////////////////////////////////
#tool "nuget:?package=NuGet.CommandLine&version=4.3.0"
///////////////////////////////////////////////////////////////////////////////
// USINGS
///////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var platform = Argument("platform", "AnyCPU");
var configuration = Argument("configuration", "Release");
///////////////////////////////////////////////////////////////////////////////
// CONFIGURATION
///////////////////////////////////////////////////////////////////////////////
var MainRepo = "VitalElement/AvalonStudio";
var MasterBranch = "master";
var ReleasePlatform = "Any CPU";
var ReleaseConfiguration = "Release";
///////////////////////////////////////////////////////////////////////////////
// PARAMETERS
///////////////////////////////////////////////////////////////////////////////
var isPlatformAnyCPU = StringComparer.OrdinalIgnoreCase.Equals(platform, "Any CPU");
var isPlatformX86 = StringComparer.OrdinalIgnoreCase.Equals(platform, "x86");
var isPlatformX64 = StringComparer.OrdinalIgnoreCase.Equals(platform, "x64");
var isLocalBuild = BuildSystem.IsLocalBuild;
var isRunningOnUnix = IsRunningOnUnix();
var isRunningOnWindows = IsRunningOnWindows();
var isRunningOnAppVeyor = BuildSystem.AppVeyor.IsRunningOnAppVeyor;
var isPullRequest = BuildSystem.AppVeyor.Environment.PullRequest.IsPullRequest;
var isMainRepo = StringComparer.OrdinalIgnoreCase.Equals(MainRepo, BuildSystem.AppVeyor.Environment.Repository.Name);
var isMasterBranch = StringComparer.OrdinalIgnoreCase.Equals(MasterBranch, BuildSystem.AppVeyor.Environment.Repository.Branch);
var isTagged = BuildSystem.AppVeyor.Environment.Repository.Tag.IsTag
&& !string.IsNullOrWhiteSpace(BuildSystem.AppVeyor.Environment.Repository.Tag.Name);
var isReleasable = StringComparer.OrdinalIgnoreCase.Equals(ReleasePlatform, platform)
&& StringComparer.OrdinalIgnoreCase.Equals(ReleaseConfiguration, configuration);
var isMyGetRelease = !isTagged && isReleasable;
var isNuGetRelease = isTagged && isReleasable;
///////////////////////////////////////////////////////////////////////////////
// DIRECTORIES
///////////////////////////////////////////////////////////////////////////////
var msvcp140_x86 = @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Redist\MSVC\14.14.26405\x86\Microsoft.VC141.CRT\msvcp140.dll";
var msvcp140_x64 = @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Redist\MSVC\14.14.26405\x64\Microsoft.VC141.CRT\msvcp140.dll";
var vcruntime140_x86 = @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Redist\MSVC\14.14.26405\x86\Microsoft.VC141.CRT\vcruntime140.dll";
var vcruntime140_x64 = @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Redist\MSVC\14.14.26405\x64\Microsoft.VC141.CRT\vcruntime140.dll";
var editbin = @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\bin\HostX86\x86\editbin.exe";
var artifactsDir = (DirectoryPath)Directory("./artifacts");
var zipRootDir = artifactsDir.Combine("zip");
var nugetRoot = artifactsDir.Combine("nuget");
var fileZipSuffix = ".zip";
var buildDirs = GetDirectories("./AvalonStudio/AvalonStudio/**/bin/**") +
GetDirectories("./AvalonStudio/AvalonStudio/**/obj/**") +
GetDirectories("./AvalonStudio/AvalonStudioBuild/**/bin/**") +
GetDirectories("./AvalonStudio/AvalonStudioBuild/**/obj/**") +
GetDirectories("./artifacts/**/zip/**");
var netCoreAppsRoot= "./AvalonStudio";
var netCoreApps = new string[] { "AvalonStudio", "AvalonStudioBuild" };
var netCoreProjects = netCoreApps.Select(name =>
new {
Path = string.Format("{0}/{1}", netCoreAppsRoot, name),
Name = name,
Framework = XmlPeek(string.Format("{0}/{1}/{1}.csproj", netCoreAppsRoot, name), "//*[local-name()='TargetFrameworks']/text()").Split(';').First(),
Runtimes = XmlPeek(string.Format("{0}/{1}/{1}.csproj", netCoreAppsRoot, name), "//*[local-name()='RuntimeIdentifiers']/text()").Split(';')
}).ToList();
///////////////////////////////////////////////////////////////////////////////
// INFORMATION
///////////////////////////////////////////////////////////////////////////////
Information("Building version {0} of AvalonStudio ({1}, {2}) using version {3} of Cake.",
platform,
configuration,
target,
typeof(ICakeContext).Assembly.GetName().Version.ToString());
if (isRunningOnAppVeyor)
{
Information("Repository Name: " + BuildSystem.AppVeyor.Environment.Repository.Name);
Information("Repository Branch: " + BuildSystem.AppVeyor.Environment.Repository.Branch);
}
Information("Target: " + target);
Information("Platform: " + platform);
Information("Configuration: " + configuration);
Information("IsLocalBuild: " + isLocalBuild);
Information("IsRunningOnUnix: " + isRunningOnUnix);
Information("IsRunningOnWindows: " + isRunningOnWindows);
Information("IsRunningOnAppVeyor: " + isRunningOnAppVeyor);
Information("IsPullRequest: " + isPullRequest);
Information("IsMainRepo: " + isMainRepo);
Information("IsMasterBranch: " + isMasterBranch);
Information("IsTagged: " + isTagged);
Information("IsReleasable: " + isReleasable);
Information("IsMyGetRelease: " + isMyGetRelease);
Information("IsNuGetRelease: " + isNuGetRelease);
var avalonBuildRIDs = new List<string>
{
"win7-x64"
};
///////////////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(()=>{
CleanDirectory(zipRootDir);
CleanDirectory(nugetRoot);
CleanDirectories(buildDirs);
});
Task("Restore-NetCore")
.IsDependentOn("Clean")
.Does(() =>
{
foreach (var project in netCoreProjects)
{
DotNetCoreRestore(project.Path);
}
});
Task("Build-NetCore")
.IsDependentOn("Restore-NetCore")
.Does(() =>
{
foreach (var project in netCoreProjects)
{
Information("Building: {0}", project.Name);
var settings = new DotNetCoreBuildSettings {
Configuration = configuration,
MSBuildSettings = new DotNetCoreMSBuildSettings {
MaxCpuCount = 0
}
};
DotNetCoreBuild(project.Path, settings);
}
});
void RunCoreTest(string dir, bool net461Only)
{
Information("Running tests from " + dir);
DotNetCoreRestore(dir);
var frameworks = new List<string>(){"net5.0"};
foreach(var fw in frameworks)
{
if(fw != "net461" && net461Only)
continue;
Information("Running for " + fw);
DotNetCoreTest(System.IO.Path.Combine(dir, System.IO.Path.GetFileName(dir)+".csproj"),
new DotNetCoreTestSettings{Framework = fw});
}
}
Task("Run-Net-Core-Unit-Tests")
.IsDependentOn("Clean")
.Does(() => {
RunCoreTest("./AvalonStudio/AvalonStudio.Extensibility.Tests", false);
RunCoreTest("./AvalonStudio/AvalonStudio.Controls.Standard.Tests", false);
});
Task("Publish-NetCore")
.Does(() =>
{
foreach (var project in netCoreProjects)
{
foreach(var runtime in project.Runtimes)
{
var outputDir = zipRootDir.Combine(project.Name + "-" + runtime);
Information("Publishing: {0}, runtime: {1}", project.Name, runtime);
DotNetCorePublish(project.Path, new DotNetCorePublishSettings {
Framework = project.Framework,
Configuration = configuration,
Runtime = runtime,
OutputDirectory = outputDir.FullPath
});
/*if (IsRunningOnWindows() && (runtime == "win7-x86" || runtime == "win7-x64"))
{
Information("Patching executable subsystem for: {0}, runtime: {1}", project.Name, runtime);
var targetExe = outputDir.CombineWithFilePath(project.Name + ".exe");
var exitCodeWithArgument = StartProcess(editbin, new ProcessSettings {
Arguments = "/subsystem:windows " + targetExe.FullPath
});
Information("The editbin command exit code: {0}", exitCodeWithArgument);
}*/
}
}
});
Task("Copy-Redist-Files-NetCore")
.IsDependentOn("Publish-NetCore")
.WithCriteria(()=>((isMainRepo && isMasterBranch && isRunningOnAppVeyor && !isPullRequest) || isLocalBuild))
.Does(() =>
{
foreach (var project in netCoreProjects)
{
foreach(var runtime in project.Runtimes)
{
var outputDir = zipRootDir.Combine(project.Name + "-" + runtime);
/*if (IsRunningOnWindows() && runtime == "win7-x86")
{
Information("Copying redist files for: {0}, runtime: {1}", project.Name, runtime);
CopyFileToDirectory(msvcp140_x86, outputDir);
CopyFileToDirectory(vcruntime140_x86, outputDir);
}
if (IsRunningOnWindows() && runtime == "win7-x64")
{
Information("Copying redist files for: {0}, runtime: {1}", project.Name, runtime);
CopyFileToDirectory(msvcp140_x64, outputDir);
CopyFileToDirectory(vcruntime140_x64, outputDir);
}*/
}
}
});
Task("Zip-NetCore")
.IsDependentOn("Publish-NetCore")
.Does(() =>
{
foreach (var project in netCoreProjects)
{
foreach(var runtime in project.Runtimes)
{
var outputDir = zipRootDir.Combine(project.Name + "-" + runtime);
Zip(outputDir.FullPath, zipRootDir.CombineWithFilePath(project.Name + "-" + runtime + fileZipSuffix));
if(DirectoryExists(outputDir))
{
DeleteDirectory(outputDir, new DeleteDirectorySettings {
Recursive = true,
Force = true
});
}
}
}
});
Task("Default")
.IsDependentOn("Clean")
.IsDependentOn("Run-Net-Core-Unit-Tests")
.IsDependentOn("Build-NetCore")
.IsDependentOn("Publish-NetCore")
.IsDependentOn("Copy-Redist-Files-NetCore")
.IsDependentOn("Zip-NetCore");
Task("OSX")
.IsDependentOn("Run-Net-Core-Unit-Tests");
Task("Linux")
.IsDependentOn("Run-Net-Core-Unit-Tests");
RunTarget(target);