-
Notifications
You must be signed in to change notification settings - Fork 623
/
build.gradle
291 lines (264 loc) · 10.4 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
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
284
285
286
287
288
289
290
291
plugins {
id 'maven-publish'
id 'signing'
}
group "ai.djl.paddlepaddle"
apply from: file("${rootProject.projectDir}/tools/gradle/cpp-formatter.gradle")
boolean isRelease = project.hasProperty("release") || project.hasProperty("staging")
version = "${paddlepaddle_version}" + (isRelease ? "" : "-SNAPSHOT")
def downloadBuild(String os, String flavor) {
exec {
if (os == "win") {
commandLine "${project.projectDir}/build.cmd", "${flavor}"
} else {
commandLine 'bash', 'build.sh', "${flavor}"
}
}
def engineDir = "${project.parent.projectDir}/paddlepaddle-engine"
def classifier = "${os}-x86_64"
def publishDir = "${engineDir}/build/jnilib/${classifier}/${flavor}"
copy {
def tree = fileTree(project.buildDir)
tree.include("**/libdjl_paddle.*", "**/djl_paddle.dll")
from tree.files
into publishDir
}
// for nightly ci
// the reason why we duplicate the folder here is to insert djl_version into the path
// so different versions of JNI wouldn't override each other. We don't also want publishDir
// to have djl_version as engine would require to know that during the System.load()
def ciDir = "${project.projectDir}/jnilib/${djl_version}/${classifier}/${flavor}"
copy {
from publishDir
into ciDir
}
}
task compileJNI {
doFirst {
if (System.properties['os.name'].toLowerCase(Locale.ROOT).contains("windows")) {
downloadBuild("win", "cpu")
} else if (System.properties['os.name'].toLowerCase(Locale.ROOT).contains("mac")) {
downloadBuild("osx", "cpu")
} else if (System.properties['os.name'].toLowerCase(Locale.ROOT).contains("linux")) {
downloadBuild("linux", "cpu")
} else {
throw new IllegalStateException("Unknown Architecture " + System.properties['os.name'])
}
}
}
task prepareNativeLibs() {
doLast {
delete "${buildDir}/native"
def files = [
"cpu/linux": "https://alpha-djl-demos.s3.amazonaws.com/temp/paddle202/paddle_inference_install_dir-2.0.2-openblas-gcc54-ubuntu.tgz",
"cpu/osx" : "https://paddle-inference-lib.bj.bcebos.com/mac/2.0.2/cpu_avx_openblas/paddle_inference.tgz",
"cpu/win" : "https://alpha-djl-demos.s3.amazonaws.com/temp/paddle_inference_install_dir-windows-openblas-2.0.2.zip"
]
def downloadDir = file("${buildDir}/download")
downloadDir.mkdirs()
files.each { entry ->
String url = entry.value
String fileName = url.substring(url.lastIndexOf('/') + 1)
def dir = file("${downloadDir}/" + entry.key)
dir.mkdirs()
File file = new File(dir, fileName)
if (!file.exists()) {
project.logger.lifecycle("Downloading ${entry.key} -> ${url}")
new URL(url).withInputStream { i -> file.withOutputStream { it << i } }
}
project.logger.lifecycle("Extracting native files from: ${fileName}")
if (fileName.endsWith(".zip")) {
copy {
from {
zipTree(file).matching { include "**/*.dll" }
}
eachFile {
path = name
}
into "${buildDir}/native/${entry.key}/native/lib"
}
} else if (fileName.endsWith(".tgz")) {
File tmpDir = new File("${buildDir}/native/tmp")
tmpDir.mkdirs()
exec {
workingDir tmpDir
commandLine "sh", "-c", "tar xvfz ${file.absolutePath}"
}
copy {
from(tmpDir) {
include '**/*.dylib'
include '**/*.so*'
}
eachFile {
path = name
}
into "${buildDir}/native/${entry.key}/native/lib"
}
delete "${buildDir}/native/tmp"
}
}
exec {
commandLine "sh", "-c", "find ${buildDir}/native -type d -empty -delete"
}
new File("${buildDir}/native/auto").mkdirs()
}
}
task uploadS3 {
doLast {
exec {
commandLine "sh", "-c", "find ${buildDir}/native -type f | xargs gzip"
}
def f = new File("${buildDir}/native/files.txt")
def uploadDirs = [
"${buildDir}/native/cpu/linux/native/lib/",
"${buildDir}/native/cpu/osx/native/lib/",
"${buildDir}/native/cpu/win/native/lib/"
]
uploadDirs.each { item ->
fileTree(item).files.name.each {
def out = item - "${buildDir}/native/"
f << out + it
f << "\n"
}
}
exec {
commandLine "aws", "s3", "sync", "${buildDir}/native/", "s3://djl-ai/publish/paddlepaddle-${paddlepaddle_version}/"
}
}
}
jar {
// this line is to enforce gradle to build the jar
// otherwise it don't generate the placeholder jar at times
// when there is no java code inside src/main
outputs.dir file("build/libs")
doFirst {
def dir = file("${project.buildDir}/classes/java/main/native/lib")
dir.mkdirs()
def propFile = new File(dir, "paddlepaddle.properties")
def versionName = project.version
if (!isRelease) {
versionName += String.format("-%s", new Date().format('yyyyMMdd'))
}
propFile.text = "placeholder=true\nversion=${versionName}\n"
}
}
java {
withJavadocJar()
withSourcesJar()
}
project.tasks.withType(GenerateModuleMetadata) {
enabled = false
}
signing {
required(project.hasProperty("staging") || project.hasProperty("snapshot"))
def signingKey = findProperty("signingKey")
def signingPassword = findProperty("signingPassword")
useInMemoryPgpKeys(signingKey, signingPassword)
sign publishing.publications
}
def BINARY_ROOT = "${project.buildDir}/native"
def flavorNames = file(BINARY_ROOT).list(new FilenameFilter() {
@Override
boolean accept(File dir, String name) {
return new File(dir, name).isDirectory()
}
}) ?: []
flavorNames.each { flavor ->
def platformNames = file("${BINARY_ROOT}/${flavor}").list() ?: []
def artifactsNames = []
platformNames.each { osName ->
tasks.create(name: "${flavor}-${osName}Jar", type: Jar) {
doFirst {
def propFile = file("${BINARY_ROOT}/${flavor}/${osName}/native/lib/paddlepaddle.properties")
propFile.delete()
def dsStore = file("${BINARY_ROOT}/${flavor}/${osName}/native/lib/.DS_Store")
dsStore.delete()
def versionName = String.format("${version}-%s", new Date().format('yyyyMMdd'))
def dir = file("${BINARY_ROOT}/${flavor}/${osName}/native/lib")
def sb = new StringBuilder()
sb.append("version=${versionName}\nclassifier=${flavor}-${osName}-x86_64\nlibraries=")
def first = true
for (String name : dir.list().sort()) {
if (first) {
first = false
} else {
sb.append(',')
}
sb.append(name)
}
propFile.text = sb.toString()
from file("src/main/resources")
}
from file("${BINARY_ROOT}/${flavor}/${osName}")
archiveClassifier = "${osName}-x86_64"
manifest {
attributes("Automatic-Module-Name": "ai.djl.paddlepaddle_native_${flavor}_${osName}")
}
}
artifactsNames.add(tasks["${flavor}-${osName}Jar"])
}
// Only publish if the project directory equals the current directory
// This means that publishing from the main project does not publish the native jars
// and the native jars have to be published separately
if (project.getProjectDir().toString() == System.getProperty("user.dir")) {
publishing.publications.create("${flavor}", MavenPublication) {
artifactId "paddlepaddle-native-${flavor}"
from components.java
artifacts = artifactsNames
artifact jar
artifact javadocJar
artifact sourcesJar
pom {
name = "DJL release for PaddlePaddle native binaries"
description = "Deep Java Library (DJL) provided PaddlePaddle native library binary distribution"
url = "http://www.djl.ai/paddlepaddle/${project.name}"
packaging = "jar"
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'https://www.apache.org/licenses/LICENSE-2.0'
}
}
scm {
connection = "scm:git:git@github.com:deepjavalibrary/djl.git"
developerConnection = "scm:git:git@github.com:deepjavalibrary/djl.git"
url = "https://github.com/deepjavalibrary/djl"
tag = "HEAD"
}
developers {
developer {
name = "DJL.AI Team"
email = "djl-dev@amazon.com"
organization = "Amazon AI"
organizationUrl = "https://amazon.com"
}
}
}
}
}
}
publishing.repositories {
maven {
if (project.hasProperty("snapshot")) {
name = "snapshot"
url = "https://oss.sonatype.org/content/repositories/snapshots/"
credentials {
username = findProperty("ossrhUsername")
password = findProperty("ossrhPassword")
}
} else if (project.hasProperty("staging")) {
name = "staging"
url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
credentials {
username = findProperty("ossrhUsername")
password = findProperty("ossrhPassword")
}
} else {
name = "local"
url = "build/repo"
}
}
}
if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
tasks.getByName("spotbugsMain").enabled = false
}