forked from chromelyapps/Chromely
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
211 lines (175 loc) · 6.89 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
#addin nuget:?package=SharpZipLib
#addin nuget:?package=Cake.Compression
#addin nuget:?package=Cake.SemVer
#addin nuget:?package=semver&version=2.0.4
var target = string.IsNullOrEmpty(Argument("target", "Default")) ? "Default" : Argument("target", "Default");
var debugPack = Argument("debugpack", false);
var cefMap = new Dictionary<string, string>()
{
["64.0.0.0"] = "3.3282.1741.gcd94615",
["65.0.0.0"] = "3.3325.1751.ge5b78a5"
};
void RestoreCefBinary(string packageName ,string baseUrl = "http://opensource.spotify.com/cefbuilds/", string targetDirectory = "./dist/redist")
{
CreateDirectory(targetDirectory);
var downloadUri = $"{baseUrl}{packageName}";
var targetFileName = $"{targetDirectory}/{packageName}";
if(FileExists(targetFileName))
{
Information($"[Skip Downloading]: {downloadUri} to {targetFileName} cause it already exists");
}
else
{
Information($"[Downloading]: {downloadUri} to {targetFileName}");
DownloadFile(downloadUri, targetFileName);
}
var targetExtractDirectory = $"{targetDirectory}/{System.IO.Path.GetFileNameWithoutExtension(packageName)}";
if(DirectoryExists(targetExtractDirectory))
{
Information($"[Skip Extracting]: {targetFileName} to {targetExtractDirectory} cause it already exists");
}
else
{
Information($"[Extracting]: {targetFileName} to {targetExtractDirectory}");
BZip2Uncompress(targetFileName, targetExtractDirectory);
}
var platform = packageName.Split('_')[3];
var platformDirectory = $"{targetDirectory}/{platform}";
CreateDirectory(platformDirectory);
var targetExtractDirectory2 = $"{targetDirectory}/{System.IO.Path.GetFileNameWithoutExtension(packageName)}/{System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetFileNameWithoutExtension(packageName))}";
var resourceDirectory = $"{targetExtractDirectory2}/Resources";
var releaseDirectory = $"{targetExtractDirectory2}/Release";
if(GetFiles($"{platformDirectory}/*.*").Count > 0)
{
Information($"[Skip Copy platform]: {releaseDirectory} to {platformDirectory} cause there are already files");
Information($"[Skip Copy platform]: {resourceDirectory} to {platformDirectory} cause there are already files");
}
else
{
if(DirectoryExists(releaseDirectory))
{
Information($"[Copy release]: {releaseDirectory} to {platformDirectory}");
CopyDirectory(releaseDirectory, platformDirectory);
}
if(DirectoryExists(resourceDirectory))
{
Information($"[Copy resources]: {resourceDirectory} to {platformDirectory}");
CopyDirectory(resourceDirectory, platformDirectory);
}
}
}
void RestoreCef(bool force = false)
{
var cefWinVersion = XmlPeek("./src/Chromely.CefGlue.Winapi/Chromely.CefGlue.Winapi.csproj", "/Project/PropertyGroup/Version");
var cefVersion = cefMap[cefWinVersion];
var win32Uri = $"cef_binary_{cefVersion}_windows32_minimal.tar.bz2";
var win64Uri = $"cef_binary_{cefVersion}_windows64_minimal.tar.bz2";
var linux32Uri = $"cef_binary_{cefVersion}_linux32_minimal.tar.bz2";
var linux64Uri = $"cef_binary_{cefVersion}_linux64_minimal.tar.bz2";
var mac64Uri = $"cef_binary_{cefVersion}_macosx64_minimal.tar.bz2";
if(force || IsRunningOnWindows())
{
RestoreCefBinary(win32Uri);
RestoreCefBinary(win64Uri);
}
if(force || IsRunningOnUnix())
{
RestoreCefBinary(linux32Uri);
RestoreCefBinary(linux64Uri);
RestoreCefBinary(mac64Uri);
}
}
string GetPackVersion()
{
var cefWinVersion = System.Version.Parse(XmlPeek("./src/Chromely.CefGlue.Winapi/Chromely.CefGlue.Winapi.csproj", "/Project/PropertyGroup/Version"));
if(debugPack)
{
var debugPackFileName = "./debugpack.txt";
if(!FileExists(debugPackFileName))
{
System.IO.File.WriteAllText(debugPackFileName, "1");
}
var debugPackCounter = int.Parse(System.IO.File.ReadAllText(debugPackFileName));
var semver = CreateSemVer(cefWinVersion.Major, cefWinVersion.Minor, debugPackCounter);
System.IO.File.WriteAllText(debugPackFileName, (debugPackCounter + 1).ToString());
return semver.ToString();
}
return CreateSemVer(cefWinVersion.Major, cefWinVersion.Minor, cefWinVersion.Build).ToString();
}
void Pack(bool force = false, string targetDirectory = "./dist/nuget")
{
var semver = GetPackVersion();
Information(semver);
var settings = new NuGetPackSettings()
{
Version = semver,
OutputDirectory = targetDirectory,
};
NuGetPack("./src/Chromely.Cef.Redist/Chromely.Cef.Redist.nuspec", settings);
if(force || IsRunningOnWindows())
{
NuGetPack("./src/Chromely.Cef.Redist/Windows/Chromely.Cef.Redist.Windows.nuspec", settings);
NuGetPack("./src/Chromely.Cef.Redist/win-64/Chromely.Cef.Redist.win-64.nuspec", settings);
NuGetPack("./src/Chromely.Cef.Redist/win-86/Chromely.Cef.Redist.win-86.nuspec", settings);
}
if(force || IsRunningOnUnix())
{
NuGetPack("./src/Chromely.Cef.Redist/Linux/Chromely.Cef.Redist.Linux.nuspec", settings);
NuGetPack("./src/Chromely.Cef.Redist/linux-86/Chromely.Cef.Redist.linux-86.nuspec", settings);
NuGetPack("./src/Chromely.Cef.Redist/linux-64/Chromely.Cef.Redist.linux-64.nuspec", settings);
}
}
Task("Clean.Force")
.IsDependentOn("Clean")
.Does(() => CleanDirectory("./dist"));
Task("Clean")
.Does(() =>
{
CleanDirectory( "./dist/test");
DotNetCoreClean("./src/ChromelySolution.sln");
});
Task("Restore.Cef.Force")
.Does(() => RestoreCef(force: true));
Task("Restore.Cef")
.Does(() => RestoreCef());
Task("Restore")
.IsDependentOn("Restore.Cef")
.Does(() => DotNetCoreRestore("./src/ChromelySolution.sln"));
Task("Build")
.IsDependentOn("Restore")
.Does(() => DotNetCoreBuild("./src/ChromelySolution.sln", new DotNetCoreBuildSettings
{
NoRestore = true
}));
Task("Pack.Redist")
.IsDependentOn("Restore.Cef")
.Does(() => Pack());
Task("Pack.Redist.Force")
.IsDependentOn("Restore.Cef.Force")
.Does(() => Pack(true));
Task("Build.Rebuild")
.IsDependentOn("Clean")
.IsDependentOn("Build");
Task("Build.Force")
.IsDependentOn("Clean.Force")
.IsDependentOn("Build");
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
var settings = new DotNetCoreTestSettings
{
ResultsDirectory = "./dist/test",
NoBuild = true,
NoRestore = true,
};
var projectFiles = GetFiles("./src/tests/**/*.csproj");
foreach(var file in projectFiles)
{
DotNetCoreTest(file.FullPath, settings);
}
});
Task("ReBuild").IsDependentOn("Build.Rebuild"); // Alias for rebuild
Task("Default")
.IsDependentOn("Build");
RunTarget(target);