forked from elastic/ml-cpp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
203 lines (174 loc) · 6.03 KB
/
build.gradle
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
description = 'Builds the Machine Learning native binaries'
import org.gradle.internal.os.OperatingSystem
import org.gradle.plugins.ide.eclipse.model.SourceFolder
import org.gradle.util.GradleVersion
import org.gradle.util.DistributionLocator
import static org.gradle.api.tasks.wrapper.Wrapper.DistributionType
boolean snapshot = "true".equals(System.getProperty("build.snapshot", "true"));
boolean isWindows = OperatingSystem.current().isWindows()
boolean isLinux = OperatingSystem.current().isLinux()
boolean isMacOsX = OperatingSystem.current().isMacOsX()
allprojects {
group = 'org.elasticsearch.ml'
version = elasticsearchVersion
if (snapshot) {
version += '-SNAPSHOT'
}
}
String cppCrossCompile = System.env.CPP_CROSS_COMPILE
if (cppCrossCompile == null) {
if (project.hasProperty("CPP_CROSS_COMPILE")) {
cppCrossCompile = CPP_CROSS_COMPILE
} else {
cppCrossCompile = ''
}
}
if (cppCrossCompile != '' && cppCrossCompile != 'macosx') {
throw new GradleException("CPP_CROSS_COMPILE property must be empty or 'macosx'")
}
String artifactClassifier = (isWindows ? "windows-x86_64" : ((isMacOsX || cppCrossCompile == 'macosx') ? "darwin-x86_64" : "linux-x86_64"))
// Always do the C++ build using bash (Git bash on Windows)
project.ext.bash = isWindows ? "C:\\Program Files\\Git\\bin\\bash" : "/bin/bash"
project.ext.make = (isMacOsX || isWindows) ? "gnumake" : (isLinux ? "make" : "gmake")
project.ext.numCpus = Runtime.runtime.availableProcessors()
configurations.all {
// check for updates every build
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
task clean(type: Exec) {
environment 'CPP_CROSS_COMPILE', cppCrossCompile
environment 'SNAPSHOT', snapshot ? 'yes' : 'no'
commandLine bash
args '-c', 'source ./set_env.sh && rm -rf build && ' + make + ' clean'
workingDir "${projectDir}"
}
task compile(type: Exec) {
// Only do this fully parallelised compile without linking step on a quad core
// machine or better - with fewer cores it's not worth it
enabled numCpus >= 4
environment 'CPP_CROSS_COMPILE', cppCrossCompile
environment 'SNAPSHOT', snapshot ? 'yes' : 'no'
commandLine bash
args '-c', 'source ./set_env.sh && ' + make + ' -j' + numCpus + ' objcompile'
workingDir "${projectDir}"
}
task make(type: Exec) {
environment 'CPP_CROSS_COMPILE', cppCrossCompile
environment 'SNAPSHOT', snapshot ? 'yes' : 'no'
commandLine bash
args '-c', 'source ./set_env.sh && ' + make + ' -j' + numCpus
workingDir "${projectDir}"
dependsOn 'compile'
}
task strip(type: Exec) {
environment 'CPP_CROSS_COMPILE', cppCrossCompile
environment 'SNAPSHOT', snapshot ? 'yes' : 'no'
commandLine bash
args '-c', 'source ./set_env.sh && dev-tools/strip_binaries.sh'
workingDir "${projectDir}"
dependsOn 'make'
}
task format(type: Exec) {
commandLine bash
args '-c', 'source ./set_env.sh && dev-tools/clang-format.sh'
workingDir "${projectDir}"
}
def zipSpec = copySpec {
from("${projectDir}/build/distribution") {
// Don't copy Windows import libraries
exclude "**/*.lib"
// Don't copy the test support library
exclude "**/libMlTest.*"
// Don't copy debug files
exclude "**/*-debug"
exclude "**/*.pdb"
exclude "**/*.dSYM/**"
// Don't copy core dumps
exclude "**/core*"
includeEmptyDirs = false
}
}
task buildZip(type: Zip) {
dependsOn strip
baseName = artifactName
with zipSpec
destinationDir = file("${buildDir}/distributions")
version = project.version
classifier = artifactClassifier
}
def zipSpecSymbols = copySpec {
from("${projectDir}/build/distribution") {
// only take debug files
include "**/*-debug"
include "**/*.pdb"
include "**/*.dSYM/**"
includeEmptyDirs = false
}
}
task buildZipSymbols(type: Zip) {
dependsOn strip
baseName = "$artifactName-debug"
with zipSpecSymbols
destinationDir = file("${buildDir}/distributions")
version = project.version
classifier = artifactClassifier
}
// The uber zip contains C++ binaries for as many platforms as possible
def uberZipSpec = copySpec {
// We know we'll have binaries from the current build
from(zipTree(buildZip.outputs.files.singleFile))
// We might also have binaries for other platforms (e.g. if they've been built in Docker)
def localZips = fileTree("${projectDir}/build/distributions").matching {
include "${artifactName}-${project.version}-darwin-*.zip"
include "${artifactName}-${project.version}-linux-*.zip"
include "${artifactName}-${project.version}-windows-*.zip"
}
for (zipFile in localZips) {
from(zipTree(zipFile)) {
duplicatesStrategy 'exclude'
}
}
}
task buildUberZip(type: Zip) {
dependsOn buildZip
baseName = "$artifactName"
with uberZipSpec
destinationDir = file("${buildDir}/distributions")
version = project.version
}
configurations.create('default')
artifacts {
'default' buildUberZip
}
task test(type: Exec) {
environment 'CPP_CROSS_COMPILE', cppCrossCompile
environment 'SNAPSHOT', snapshot ? 'yes' : 'no'
commandLine bash
args '-c', 'source ./set_env.sh && ' + make + ' -j' + numCpus + ' test'
workingDir "${projectDir}"
dependsOn 'strip'
description = 'Run C++ tests'
}
task check {
dependsOn 'test'
description = 'Run all verification tasks'
}
task assemble {
dependsOn 'buildUberZip', 'buildZipSymbols'
description = 'Assemble the C++ part of Machine Learning'
}
task build(dependsOn: [check, assemble]) {
group = 'Build'
description = 'Assemble and test the C++ part of Machine Learning'
}
task wrapper(type: Wrapper) {
distributionType = DistributionType.ALL
doLast {
final DistributionLocator locator = new DistributionLocator()
final GradleVersion version = GradleVersion.version(wrapper.gradleVersion)
final URI distributionUri = locator.getDistributionFor(version, wrapper.distributionType.name().toLowerCase(Locale.ENGLISH))
final URI sha256Uri = new URI(distributionUri.toString() + ".sha256")
final String sha256Sum = new String(sha256Uri.toURL().bytes)
wrapper.getPropertiesFile() << "distributionSha256Sum=${sha256Sum}\n"
}
}