-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbuild.cake
283 lines (240 loc) · 8.27 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
282
283
#addin nuget:?package=Cake.Git&version=1.0.1
#addin nuget:?package=Newtonsoft.Json&version=13.0.1
using System.Net.Http;
using System.Linq;
using Newtonsoft.Json.Linq;
var IOSVERSION = Argument("iosversion", "13.3.3");
var IOS_SERVICERELEASE_VERSION = "0"; // This is combined with the IOSVERSION variable for the NuGet Package version
var target = Argument ("target", "Default");
var NUGET_API_KEY = EnvironmentVariable("NUGET_API_KEY");
Task ("DownloadDeps")
.Description ("Downloads frameworks")
.Does (async () => {
Information ("Downloading all the dependencies please wait...");
if (!IsRunningOnUnix ()) {
Error ("*** This can only be run in macOS. ***");
return;
}
var iosUrl = $"https://customers.pspdfkit.com/pspdfkit-ios/{IOSVERSION}-framework.podspec.json";
var instantUrl = $"https://customers.pspdfkit.com/instant/{IOSVERSION}-framework.podspec.json";
var iosDlUrl = await ResolveDownloadUrl (iosUrl);
var instantDlUrl = await ResolveDownloadUrl (instantUrl);
CreateDirectory("./cache");
DownloadFile (iosDlUrl, $"./cache/ios.zip");
DownloadFile (instantDlUrl, $"./cache/instant.zip");
UnzipFile ($"./cache/ios.zip", $"./cache/ios");
UnzipFile ($"./cache/instant.zip", $"./cache/ios");
CopyDir ("./cache/ios/PSPDFKit.framework", "./PSPDFKit.iOS.Model/PSPDFKit.framework");
CopyDir ("./cache/ios/PSPDFKitUI.framework", "./PSPDFKit.iOS.UI/PSPDFKitUI.framework");
CopyDir ("./cache/ios/Instant.framework", "./PSPDFKit.iOS.Instant/Instant.framework");
}
);
Task ("iOSModel")
.Description ("Builds 'PSPDFKit.iOS.Model.dll', expects 'PSPDFKit.framework' inside './PSPDFKit.iOS.Model/' Directory\n")
.Does (() => {
Information ("=== PSPDFKit.iOS.Model.dll ===");
if (!DirectoryExists ("./PSPDFKit.iOS.Model/PSPDFKit.framework/"))
throw new Exception ("Unable to locate 'PSPDFKit.framework' inside './PSPDFKit.iOS.Model' Directory");
MSBuild ("./PSPDFKit.iOS.Model/PSPDFKit.iOS.Model.csproj", new MSBuildSettings ()
.SetConfiguration ("Release")
);
if (FileExists ("./PSPDFKit.iOS.Model/bin/Release/PSPDFKit.iOS.Model.dll"))
CopyFile ("./PSPDFKit.iOS.Model/bin/Release/PSPDFKit.iOS.Model.dll", "./PSPDFKit.iOS.Model.dll");
}
);
Task ("iOSUI")
.Description ("Builds 'PSPDFKit.iOS.UI.dll', expects 'PSPDFKitUI.framework' inside './PSPDFKit.iOS.UI/' Directory\n")
.Does (() => {
Information ("=== PSPDFKit.iOS.UI.dll ===");
if (!DirectoryExists ("./PSPDFKit.iOS.UI/PSPDFKitUI.framework/")) {
Warning ("Unable to locate 'PSPDFKitUI.framework' inside './PSPDFKit.iOS.UI' Directory");
Warning ("Skipping PSPDFKit.iOS.UI.dll");
} else {
MSBuild ("./PSPDFKit.iOS.UI/PSPDFKit.iOS.UI.csproj", new MSBuildSettings ()
.SetConfiguration ("Release")
);
if (FileExists ("./PSPDFKit.iOS.UI/bin/Release/PSPDFKit.iOS.UI.dll"))
CopyFile ("./PSPDFKit.iOS.UI/bin/Release/PSPDFKit.iOS.UI.dll", "./PSPDFKit.iOS.UI.dll");
}
}
);
Task ("iOSInstant")
.Description ("Builds 'PSPDFKit.iOS.Instant.dll', expects 'Instant.framework' inside './PSPDFKit.iOS.Instant/' Directory\n")
.Does (() => {
Information ("=== PSPDFKit.iOS.Instant.dll ===");
if (!DirectoryExists ("./PSPDFKit.iOS.Instant/Instant.framework/")) {
Warning ("Unable to locate 'Instant.framework' inside './PSPDFKit.iOS.Instant' Directory");
Warning ("Skipping PSPDFKit.iOS.Instant.dll");
} else {
MSBuild ("./PSPDFKit.iOS.Instant/PSPDFKit.iOS.Instant.csproj", new MSBuildSettings ()
.SetConfiguration ("Release")
);
if (FileExists ("./PSPDFKit.iOS.Instant/bin/Release/PSPDFKit.iOS.Instant.dll"))
CopyFile ("./PSPDFKit.iOS.Instant/bin/Release/PSPDFKit.iOS.Instant.dll", "./PSPDFKit.iOS.Instant.dll");
}
}
);
Task ("RestoreNugets")
.Does (() => {
Information ("=== Restoring NuGets ===");
NuGetRestore ("./PSPDFKit.sln");
});
Task ("ios")
.Description ("Builds iOS PSPDFKit dlls.\n")
.IsDependentOn ("Clean")
.IsDependentOn ("DownloadDeps")
.IsDependentOn ("RestoreNugets")
.IsDependentOn ("iOSModel")
.IsDependentOn ("iOSUI")
.IsDependentOn ("iOSInstant")
.Does (() => {
Information ("DONE! You will find the PSPDFKit.*.dll's in the root folder.");
}
);
Task ("Default")
.Description ("Builds all PSPDFKit dlls.\n")
.IsDependentOn ("Clean")
.IsDependentOn ("DownloadDeps")
.IsDependentOn ("RestoreNugets")
.IsDependentOn ("iOSModel")
.IsDependentOn ("iOSUI")
.IsDependentOn ("iOSInstant")
.Does (() => {
Information ("DONE! You will find the PSPDFKit.*.dll's in the root folder.");
}
);
Task ("NuGet")
.IsDependentOn ("Default")
.Does (() =>
{
if(!DirectoryExists ("./nuget/pkgs/"))
CreateDirectory ("./nuget/pkgs");
var head = GitLogTip ("./");
var commit = head.Sha.Substring (0,7);
NuGetPack ("./nuget/pspdfkit-ios-model.nuspec", new NuGetPackSettings {
Version = $"{IOSVERSION}.{IOS_SERVICERELEASE_VERSION}+sha.{commit}",
OutputDirectory = "./nuget/pkgs/",
BasePath = "./",
Properties = new Dictionary<string, string> {
{"NoWarn", "NU5105"},
}
});
NuGetPack ("./nuget/pspdfkit-ios-ui.nuspec", new NuGetPackSettings {
Version = $"{IOSVERSION}.{IOS_SERVICERELEASE_VERSION}+sha.{commit}",
OutputDirectory = "./nuget/pkgs/",
BasePath = "./",
Properties = new Dictionary<string, string> {
{"NoWarn", "NU5105"},
}
});
NuGetPack ("./nuget/pspdfkit-ios-instant.nuspec", new NuGetPackSettings {
Version = $"{IOSVERSION}.{IOS_SERVICERELEASE_VERSION}+sha.{commit}",
OutputDirectory = "./nuget/pkgs/",
BasePath = "./",
Properties = new Dictionary<string, string> {
{"NoWarn", "NU5105"},
}
});
});
Task ("NuGet-Push")
.Does (() =>
{
var iOSFullVersion = IOSVERSION;
if (IOS_SERVICERELEASE_VERSION != "0") {
iOSFullVersion = $"{IOSVERSION}.{IOS_SERVICERELEASE_VERSION}";
}
// Get the path to the packages
var modelPackage = $"./nuget/pkgs/PSPDFKit.iOS.Model.{iOSFullVersion}.nupkg";
var uiPackage = $"./nuget/pkgs/PSPDFKit.iOS.UI.{iOSFullVersion}.nupkg";
var instantPackage = $"./nuget/pkgs/PSPDFKit.iOS.Instant.{iOSFullVersion}.nupkg";
// Push the packages
NuGetPush(modelPackage, new NuGetPushSettings {
Source = "https://api.nuget.org/v3/index.json",
ApiKey = NUGET_API_KEY
});
NuGetPush(uiPackage, new NuGetPushSettings {
Source = "https://api.nuget.org/v3/index.json",
ApiKey = NUGET_API_KEY
});
NuGetPush(instantPackage, new NuGetPushSettings {
Source = "https://api.nuget.org/v3/index.json",
ApiKey = NUGET_API_KEY
});
});
Task ("Clean")
.Description ("Cleans the build.\n")
.Does (() => {
var nukeFiles = new [] {
"./PSPDFKit.iOS.Model.dll",
"./PSPDFKit.iOS.UI.dll",
"./PSPDFKit.iOS.Instant.dll",
};
foreach (var file in nukeFiles) {
Console.WriteLine (file);
if (FileExists ($"{file}"))
Nuke ($"{file}");
}
var projdirs = new [] {
"./PSPDFKit.iOS.Model",
"./PSPDFKit.iOS.UI",
"./PSPDFKit.iOS.Instant",
"./PSPDFCatalog/PSPDFCatalog",
"./XamarinForms/iOS",
"./XamarinForms/XFSample",
};
foreach (var proj in projdirs) {
Console.WriteLine (proj);
if (DirectoryExists ($"{proj}/bin/"))
Nuke ($"{proj}/bin");
if (DirectoryExists ($"{proj}/obj/"))
Nuke ($"{proj}/obj");
}
var nukedirs = new [] {
"./packages",
"./nuget/pkgs",
"./cache/ios",
"./cache",
"./PSPDFKit.iOS.Model/PSPDFKit.framework",
"./PSPDFKit.iOS.UI/PSPDFKitUI.framework",
"./PSPDFKit.iOS.Instant/Instant.framework",
};
foreach (var dir in nukedirs) {
Console.WriteLine (dir);
if (DirectoryExists ($"{dir}/"))
Nuke ($"{dir}");
}
}
);
static HttpClient client = new HttpClient ();
static async Task<string> ResolveDownloadUrl (string url)
{
var json = await client.GetStringAsync (url);
var jobj = JObject.Parse (json);
return (string) jobj["source"]["http"];
}
void LipoCreate (FilePath binaryPath, params FilePath [] thinBinaries)
{
var args = string.Join (" ", thinBinaries.Select (i => $"\"{i}\""));
StartProcess ("lipo", new ProcessSettings {
Arguments = $"-create -output \"{binaryPath}\" {args}"
});
}
void CopyDir (FilePath origin, FilePath destination)
{
StartProcess ("cp", new ProcessSettings {
Arguments = $"-RP \"{origin}\" \"{destination}\""
});
}
void UnzipFile (FilePath zipFile, DirectoryPath destination)
{
StartProcess ("unzip", new ProcessSettings {
Arguments = $"\"{zipFile}\" -d \"{destination}\""
});
}
void Nuke (string path)
{
StartProcess ("rm", new ProcessSettings {
Arguments = $"-rf \"{path}\""
});
}
RunTarget (target);