forked from microsoft/appcenter-sdk-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
161 lines (135 loc) · 5.33 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
#tool nuget:?package=XamarinComponent
#addin nuget:?package=Cake.Xamarin
#addin nuget:?package=Cake.FileHelpers
// MobileCenter module class definition.
class MobileCenterModule {
public String AndroidModule { get; set; }
public String IosModule { get; set; }
public String XamarinModule { get; set; }
public String NuGetVersion { get; set; }
public String NuGetSpecFilename { get; set; }
public MobileCenterModule(String android, String ios, String xamarin, String nuGetSpecFilename) {
AndroidModule = android;
IosModule = ios;
XamarinModule = xamarin;
NuGetSpecFilename = nuGetSpecFilename;
}
}
// SDK versions
var ANDROID_SDK_VERSION = "0.3.1";
var IOS_SDK_VERSION = "0.3.2";
// URLs for downloading binaries.
/*
* Read this: http://www.mono-project.com/docs/faq/security/.
* On Windows,
* you have to do additional steps for SSL connection to download files.
* http://stackoverflow.com/questions/4926676/mono-webrequest-fails-with-https
* By running mozroots and install part of Mozilla's root certificates can make it work.
*/
var SDK_STORAGE_URL = "https://mobilecentersdkdev.blob.core.windows.net/sdk/";
var ANDROID_URL = SDK_STORAGE_URL + "MobileCenter-SDK-Android-" + ANDROID_SDK_VERSION + ".zip";
var IOS_URL = SDK_STORAGE_URL + "MobileCenter-SDK-iOS-" + IOS_SDK_VERSION + ".zip";
// Available MobileCenter modules.
var MOBILECENTER_MODULES = new [] {
new MobileCenterModule("mobile-center-release.aar", "MobileCenter.framework.zip", "SDK/MobileCenter/Microsoft.Azure.Mobile", "MobileCenter.nuspec"),
new MobileCenterModule("mobile-center-analytics-release.aar", "MobileCenterAnalytics.framework.zip", "SDK/MobileCenterAnalytics/Microsoft.Azure.Mobile.Analytics", "MobileCenterAnalytics.nuspec"),
new MobileCenterModule("mobile-center-crashes-release.aar", "MobileCenterCrashes.framework.zip", "SDK/MobileCenterCrashes/Microsoft.Azure.Mobile.Crashes", "MobileCenterCrashes.nuspec")
};
// Task TARGET for build
var TARGET = Argument("target", Argument("t", "Default"));
// Versioning task.
Task("Version")
.Does(() =>
{
// Read AssemblyInfo.cs and extract versions for modules.
foreach (var module in MOBILECENTER_MODULES) {
var assemblyInfo = ParseAssemblyInfo("./" + module.XamarinModule + "/Properties/AssemblyInfo.cs");
module.NuGetVersion = assemblyInfo.AssemblyInformationalVersion;
}
});
// Building code task.
Task("Build")
.IsDependentOn("Externals")
.Does(() =>
{
// Build solution
NuGetRestore("./MobileCenter-SDK-Build.sln");
DotNetBuild("./MobileCenter-SDK-Build.sln", c => c.Configuration = "Release");
});
// Task dependencies for binding each platform.
Task("Bindings-Android").IsDependentOn("Externals-Android");
Task("Bindings-Ios").IsDependentOn("Externals-Ios");
// Downloading Android binaries.
Task("Externals-Android")
.Does(() =>
{
// Clean up download directory.
if(DirectoryExists("./externals/android"))
DeleteDirectory("./externals/android", true);
CreateDirectory("./externals/android");
// Download zip file.
DownloadFile(ANDROID_URL, "./externals/android/android.zip");
Unzip("./externals/android/android.zip", "./externals/android/");
// Copy files to $XamarinModule$.Android.Bindings/Jars
foreach (var module in MOBILECENTER_MODULES) {
var files = GetFiles("./externals/android/*/" + module.AndroidModule);
CopyFiles(files, module.XamarinModule + ".Android.Bindings/Jars/");
}
});
// Downloading iOS binaries.
Task("Externals-Ios")
.Does(() =>
{
// Clean up download directory.
if(DirectoryExists("./externals/ios"))
DeleteDirectory("./externals/ios", true);
CreateDirectory("./externals/ios");
// Download zip file containing MobileCenter frameworks
DownloadFile(IOS_URL, "./externals/ios/ios.zip");
Unzip("./externals/ios/ios.zip", "./externals/ios/");
// Copy the MobileCenter binaries directly from the frameworks and add the ".a" extension
var files = GetFiles("./externals/ios/*/*.framework/MobileCenter*");
foreach (var file in files) {
MoveFile(file, "./externals/ios/" + file.GetFilename() + ".a");
}
});
// Create a common externals task depending on platform specific ones
Task("Externals").IsDependentOn("Externals-Ios").IsDependentOn("Externals-Android");
// Packaging NuGets.
Task("NuGet")
.IsDependentOn("Build")
.IsDependentOn("Version")
.Does(() =>
{
// NuGet on mac trims out the first ./ so adding it twice works around
var basePath = IsRunningOnUnix() ? (System.IO.Directory.GetCurrentDirectory().ToString() + @"/.") : "./";
// Clean up output directory.
if(DirectoryExists("./output"))
DeleteDirectory("./output", true);
CreateDirectory("./output");
// Packaging NuGets.
foreach (var module in MOBILECENTER_MODULES) {
var spec = GetFiles("./NuGetSpec/" + module.NuGetSpecFilename);
Information("Building a NuGet package for " + module.XamarinModule + " version " + module.NuGetVersion);
NuGetPack(spec, new NuGetPackSettings {
BasePath = basePath,
Verbosity = NuGetVerbosity.Detailed,
Version = module.NuGetVersion
});
}
MoveFiles("./Microsoft.Azure.Mobile*.nupkg", "./output");
});
// Main Task.
Task("Default").IsDependentOn("NuGet");
// Cleaning up files/directories.
Task("clean").Does(() =>
{
if(DirectoryExists("./externals"))
DeleteDirectory("./externals", true);
if(DirectoryExists("./output"))
DeleteDirectory("./output", true);
DeleteFiles("./*.nupkg");
CleanDirectories("./**/bin");
CleanDirectories("./**/obj");
});
RunTarget(TARGET);