This repository was archived by the owner on Mar 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.cake
More file actions
152 lines (127 loc) · 4.92 KB
/
build.cake
File metadata and controls
152 lines (127 loc) · 4.92 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
#load "./scripts/version.cake"
#load "./scripts/azure.cake"
#load "./scripts/git.cake"
#load "./scripts/utils.cake"
#load "./scripts/rust.cake"
using System.Text.RegularExpressions;
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var musl = !HasArgument("skip-musl");
///////////////////////////////////////////////////////////////////////////////
// VARIABLES
///////////////////////////////////////////////////////////////////////////////
var version = "0.0.0";
var deploy = false;
///////////////////////////////////////////////////////////////////////////////
// SETUP/TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(context =>
{
// Get the version.
version = CakeVersion.Calculate(context);
if(BuildSystem.AppVeyor.IsRunningOnAppVeyor) {
// Update the AppVeyor version number.
BuildSystem.AppVeyor.UpdateBuildVersion(version);
}
// Determine if we should deploy or not.
var branch = GitUtils.GetBranch(context);
if(branch.Equals("master", StringComparison.OrdinalIgnoreCase)) {
deploy = !BuildSystem.IsLocalBuild;
}
Information("Version: {0}", version);
});
///////////////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////////////
Task("Patch-Version")
.WithCriteria(() => deploy, "Not patching version since this is a local build.")
.Does(() =>
{
var path = File("./Cargo.toml").Path;
var input = System.IO.File.ReadAllText(path.FullPath);
var result = new Regex("version = \"[0-9]\\.[0-9]\\.[0-9]\"").Replace(input, $"version = \"{version}\"");
System.IO.File.WriteAllText(path.FullPath, result);
});
Task("Build-OpenSSL")
.WithCriteria(() => Context.Environment.Platform.Family == PlatformFamily.Linux, "Not on Linux.")
.WithCriteria(() => musl, "Argument --skip-musl was set.")
.Does(context =>
{
EnsureEnvironmentVariable(context, "OPENSSL_DIR");
var location = new DirectoryPath(context.EnvironmentVariable("OPENSSL_DIR"));
if(DirectoryExists(location))
{
Information("Found OpenSSL, so no need to build it.");
return;
}
Information("Building OpenSSL ({0}). This will take a while...", location);
var process = System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
{
FileName = "/bin/bash",
UseShellExecute = true,
Arguments = string.Format("-c \"sudo -E {0} {1}\"",
MakeAbsolute(Directory("./scripts/shell/build_openssl_musl.sh")).FullPath,
location)
});
process.WaitForExit();
});
Task("Build")
.IsDependentOn("Patch-Version")
.IsDependentOn("Build-OpenSSL")
.Does(context =>
{
Rust.Build(context);
if(context.Environment.Platform.Family == PlatformFamily.Linux && musl)
{
// Build for MUSL.
EnsureEnvironmentVariable(context, "OPENSSL_STATIC", "1");
EnsureEnvironmentVariable(context, "OPENSSL_DIR");
Rust.Build(context, "x86_64-unknown-linux-musl");
}
});
Task("Smoke-Tests")
.IsDependentOn("Build")
.Does(context =>
{
var root = GetTargetDirectory(context);
var filename = GetTargetFilename(context);
var path = MakeAbsolute(root.CombineWithFilePath(filename));
var exitCode = context.StartProcess(path, new ProcessSettings {
WorkingDirectory = root,
Arguments = new ProcessArgumentBuilder()
.Append("--trace")
.Append("run")
.Append("--cake=0.28.1")
.Append("--nuget=latest")
.Append("--sdk=2.1.4")
.Append("--coreclr")
});
if(exitCode != 0)
{
throw new CakeException("Smoke tests failed. See log for more information.");
}
});
Task("Deploy")
.WithCriteria(() => deploy, "Not deploying since this is a local build.")
.IsDependentOn("Smoke-Tests")
.Does(async context =>
{
await AzureFileClient.UploadArtifacts(context, version);
// Building on Linux?
if(context.Environment.Platform.Family == PlatformFamily.Linux && musl)
{
// Upload MUSL artifacts as well.
await AzureFileClient.UploadArtifacts(context, version, "x86_64-unknown-linux-musl");
}
});
///////////////////////////////////////////////////////////////////////////////
// TARGETS
///////////////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Deploy");
///////////////////////////////////////////////////////////////////////////////
// EXECUTION
///////////////////////////////////////////////////////////////////////////////
RunTarget(target);