-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathProgram.cs
More file actions
327 lines (289 loc) · 13.1 KB
/
Program.cs
File metadata and controls
327 lines (289 loc) · 13.1 KB
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Newtonsoft.Json;
using static Bullseye.Targets;
using static Build.Buildary.Directory;
using static Build.Buildary.Path;
using static Build.Buildary.Shell;
using static Build.Buildary.Runner;
using static Build.Buildary.Runtime;
using static Build.Buildary.Log;
using static Build.Buildary.File;
using static Build.Buildary.GitVersion;
namespace Build
{
static class Program
{
static Task Main(string[] args)
{
var options = ParseOptions<Options>(args);
var nugetApiKey = Environment.GetEnvironmentVariable("PRIVATE_NUGET_KEY");
var nugetSource = "https://feeds.pknopf.com/nuget/qmlnet";
var gitversion = GetGitVersion(ExpandPath("./"));
var commandBuildArgs = $"--configuration {options.Configuration} /p:Platform=\"Any CPU\"";
var commandBuildArgsWithVersion = commandBuildArgs;
if (!string.IsNullOrEmpty(gitversion.PreReleaseTag))
{
commandBuildArgsWithVersion += $" --version-suffix \"{gitversion.PreReleaseTag}\"";
}
Info($"Version: {JsonConvert.SerializeObject(gitversion)}");
Target("clean", () =>
{
CleanDirectory(ExpandPath("./output"));
});
Target("test", () =>
{
if (IsOSX())
{
// OSX prevent's DYLD_LIBRARY_PATH from being sent to
// child shells. We must manually send it.
var ldLibraryPath = Environment.GetEnvironmentVariable("DYLD_LIBRARY_PATH");
RunShell($"DYLD_LIBRARY_PATH={ldLibraryPath} dotnet test src/net/Qml.Net.Tests/");
}
else
{
RunShell($"dotnet test src/net/Qml.Net.Tests/ {commandBuildArgs}");
}
});
Target("build-native", () =>
{
if (IsWindows())
{
RunShell($"{ExpandPath("./src/native/build.bat")}");
// The windows build currently brings in all the .dll's for packaging.
// However, it also brings in the *d.dll/*.pdb files. Let's remove them.
foreach(var file in GetFiles(ExpandPath("./src/native/output/"), recursive: true))
{
if (file.EndsWith("d.dll"))
{
if(FileExists(file.Substring(0, file.Length - 5) + ".dll"))
{
// This is a debug dll.
DeleteFile(file);
}
}
else if (file.EndsWith(".pdb"))
{
DeleteFile(file);
}
else if (file.EndsWith("*.qmlc"))
{
DeleteFile(file);
}
}
}
else
{
RunShell("src/native/build.sh");
if (IsOSX())
{
// We deploy the entire Qt framework. Let's trim it down.
foreach(var directory in GetDirecories(ExpandPath("./src/native/output"), recursive:true))
{
if (!DirectoryExists(directory))
{
continue;
}
var directoryName = Path.GetFileName(directory);
if (directoryName == "Headers")
{
DeleteDirectory(directory);
continue;
}
if (directoryName.EndsWith(".dSYM"))
{
DeleteDirectory(directory);
continue;
}
if (directory == "cmake")
{
DeleteDirectory(directory);
continue;
}
if (directory == "pkgconfig")
{
DeleteDirectory(directory);
}
}
foreach (var file in GetFiles(ExpandPath("./src/native/output"), recursive:true))
{
var extension = Path.GetExtension(file);
var fileName = Path.GetFileNameWithoutExtension(file);
if (fileName.EndsWith("_debug"))
{
DeleteFile(file);
continue;
}
if (extension == ".prl")
{
DeleteFile(file);
continue;
}
if (extension == ".plist")
{
DeleteFile(file);
continue;
}
if (extension == ".qmlc")
{
DeleteFile(file);
continue;
}
if (extension == ".cmake")
{
DeleteFile(file);
continue;
}
if (extension == ".a")
{
DeleteFile(file);
continue;
}
if (extension == ".la")
{
DeleteFile(file);
}
}
}
if (IsLinux())
{
// First get a list of all dependencies from every .so files.
var linkedFiles = new List<string>();
foreach(var file in GetFiles(ExpandPath("./src/native/output"), pattern:"*.so*", recursive:true))
{
var lddOutput = ReadShell($"ldd {file}");
foreach (var _line in lddOutput.Split(Environment.NewLine))
{
var line = _line.TrimStart('\t').TrimStart('\n');
var match = Regex.Match(line, @"(.*) =>.*");
if (match.Success)
{
var linkedFile = match.Groups[1].Value;
if(!linkedFiles.Contains(linkedFile))
{
linkedFiles.Add(linkedFile);
}
}
}
}
// Let's remove any file from lib/ that isn't linked against anything.
foreach(var file in GetFiles(ExpandPath("./src/native/output/lib"), recursive:true))
{
var fileName = Path.GetFileName(file);
if (!linkedFiles.Contains(fileName))
{
DeleteFile(file);
}
}
foreach (var directory in GetDirecories(ExpandPath("./src/native/output"), recursive: true))
{
if (!DirectoryExists(directory))
{
continue;
}
var directoryName = Path.GetFileName(directory);
if (directoryName == "cmake")
{
DeleteDirectory(directory);
continue;
}
if (directoryName == "pkgconfig")
{
DeleteDirectory(directory);
continue;
}
Info(directory);
}
foreach (var file in GetFiles(ExpandPath("./src/native/output"), recursive: true))
{
var fileName = Path.GetFileName(file);
var fileExtension = Path.GetExtension(fileName);
if (fileExtension == ".qmlc")
{
DeleteFile(file);
}
}
}
}
});
Target("build-net", () =>
{
RunShell($"dotnet build {ExpandPath("src/net/Qml.Net.sln")} {commandBuildArgsWithVersion}");
});
Target("build", DependsOn("build-native", "build-net"));
Target("deploy", DependsOn("clean"), () =>
{
// Deploy our nuget packages.
RunShell($"dotnet pack {ExpandPath("src/net/Qml.Net.sln")} --output {ExpandPath("./output")} {commandBuildArgsWithVersion}");
if (IsWindows())
{
// Deploy our Windows binaries NuGet package.
RunShell($"dotnet pack {ExpandPath("src/native/Qml.Net.WindowsBinaries.csproj")} --output {ExpandPath("./output")} {commandBuildArgsWithVersion}");
}
if (IsOSX())
{
// Deploy our OSX binaries NuGet package.
RunShell($"dotnet pack {ExpandPath("src/native/Qml.Net.OSXBinaries.csproj")} --output {ExpandPath("./output")} {commandBuildArgsWithVersion}");
}
if (IsLinux())
{
// Deploy our Linux binaries NuGet package.
RunShell($"dotnet pack {ExpandPath("src/native/Qml.Net.LinuxBinaries.csproj")} --output {ExpandPath("./output")} {commandBuildArgsWithVersion}");
}
});
Target("update-version", () =>
{
if (FileExists("./build/version.props"))
{
DeleteFile("./build/version.props");
}
WriteFile("./build/version.props",
$@"<Project>
<PropertyGroup>
<VersionPrefix>{gitversion.Version}</VersionPrefix>
</PropertyGroup>
</Project>");
});
Target("publish", () =>
{
return; // temp, until we move to Azure Dev Ops
#pragma warning disable CS0162
if (string.IsNullOrEmpty(nugetApiKey))
{
Info("Skipping publish, due to missing NuGet key...");
return;
}
void Deploy(string package)
{
RunShell($"dotnet nuget push -k {nugetApiKey} -s {nugetSource} {package}");
}
if (IsWindows())
{
Deploy($"./output/Qml.Net.WindowsBinaries.{gitversion.FullVersion}.nupkg");
}
if (IsOSX())
{
Deploy($"./output/Qml.Net.OSXBinaries.{gitversion.FullVersion}.nupkg");
}
if (IsLinux())
{
Deploy($"./output/Qml.Net.{gitversion.FullVersion}.nupkg");
Deploy($"./output/Qml.Net.LinuxBinaries.{gitversion.FullVersion}.nupkg");
}
});
Target("default", DependsOn("clean", "build"));
Target("ci", DependsOn("update-version", "build", "test", "deploy", "publish"));
return Run(options);
}
// ReSharper disable ClassNeverInstantiated.Local
class Options : RunnerOptions
// ReSharper restore ClassNeverInstantiated.Local
{
[PowerArgs.ArgShortcut("config"), PowerArgs.ArgDefaultValue("Release")]
public string Configuration { get; set; }
}
}
}