-
Notifications
You must be signed in to change notification settings - Fork 14
/
publish.gradle
418 lines (363 loc) · 13.6 KB
/
publish.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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
import java.security.MessageDigest
apply plugin: 'maven-publish'
publishing {
repositories {
maven {
url "${System.getProperty('user.home')}/releases/maven/development"
}
maven {
url "${System.getProperty('user.home')}/releases/maven/release"
}
}
}
def pubVersion = "${project.ext.version}-3"
def outputsFolder = file("$project.buildDir/outputs")
def baseArtifactId = 'opencv'
def artifactGroupId = 'edu.wpi.first.thirdparty.frc2025.opencv'
def zipBaseName = '_GROUP_edu_wpi_first_thirdparty_frc2025_opencv_ID_opencv-cpp_CLS'
def jniBaseName = "_GROUP_edu_wpi_first_thirdparty_frc2025_opencv_ID_opencv-jni_CLS"
def javaBaseName = "_GROUP_edu_wpi_first_thirdparty_frc2025_opencv_ID_opencv-java_CLS"
def versionFile = file("$outputsFolder/version.txt")
task outputVersions() {
description = 'Prints the versions of this to a file for use by the downstream packaging project'
group = 'Build'
outputs.files(versionFile)
doFirst {
buildDir.mkdir()
outputsFolder.mkdir()
}
doLast {
versionFile.write pubVersion
}
}
build.dependsOn outputVersions
copyAllOutputs.dependsOn outputVersions
copyAllOutputs.inputs.file versionFile
copyAllOutputs.from versionFile
task cppSourcesZip(type: Zip, dependsOn: make) {
destinationDirectory = outputsFolder
archiveBaseName = zipBaseName
archiveClassifier = "sources"
from(licenseFile) {
into '/'
}
from('opencv/3rdparty') {
into '/3rdparty'
include '**/*.cpp', '**/*.h*'
}
from('opencv/modules') {
into '/modules'
include '**/*.cpp', '**/*.h*'
}
from(project.cmakeBuildDirectory.resolve('modules')) {
into '/modules'
include '**/*.cpp', '**/*.h*'
}
includeEmptyDirs = false
}
task cppHeadersZip(type: Zip, dependsOn: make) {
destinationDirectory = outputsFolder
archiveBaseName = zipBaseName
archiveClassifier = "headers"
from(licenseFile) {
into '/'
}
from ('opencv/include') {
into '/'
exclude '**/CMakeLists.txt'
}
from (project.cmakeBuildDirectory.resolve('opencv2').toFile()) {
into '/opencv2/'
}
from(rootPath.resolve('modules').toFile()) {
include '*/include/**/*.hpp'
include '*/include/**/*.h'
exclude 'java/**'
exclude 'python/**'
eachFile { FileCopyDetails fcp ->
fcp.relativePath = new RelativePath(!fcp.file.isDirectory(), fcp.relativePath.segments[2..-1] as String[])
}
}
includeEmptyDirs = false
}
['', 'Debug' ].each{ buildType ->
def staticBuildDir = buildType.contains('Debug') ? project.cmakeBuildDebugDirectory : project.cmakeBuildDirectory
def sharedBuildDir = buildType.contains('Debug') ? project.cmakeBuildSharedDebugDirectory : project.cmakeBuildSharedDirectory
def outputClassifier = project.ext.platformClassifier
def outputClassifierStatic = project.ext.platformClassifier + 'static'
if (buildType.contains('Debug')) {
outputClassifier = outputClassifier + 'debug'
outputClassifierStatic = outputClassifierStatic + 'debug'
}
def buildTypeFolder = buildType.contains('Debug') ? 'Debug' : 'Release'
project.tasks.create('cppLibsZip' + buildType, Zip) {
dependsOn tasks.named('makeShared' + buildType)
destinationDirectory = outputsFolder
archiveClassifier = outputClassifier
archiveBaseName = zipBaseName
duplicatesStrategy = 'exclude'
from(licenseFile) {
into '/'
}
if (!project.platform.startsWith("windows")) {
if (buildType.contains('Debug') && project.platform.startsWith('linux')) {
dependsOn 'stripLibsSharedDebug'
from("$buildDir/stripSharedDebug") {
into project.platformPath + '/shared'
}
} else {
def resolvedDir = sharedBuildDir.resolve("lib")
if (project.platform.startsWith("osx")) {
resolvedDir = resolvedDir.resolve(buildTypeFolder)
}
from(resolvedDir.toFile()) {
into project.platformPath + '/shared'
include '*.so.*.*.*'
exclude 'cv2.so'
exclude '**/*dephelp*'
eachFile { f->
f.name = f.name.replace("${project.ext.version}", "${project.ext.soVersion}")
}
}
from(resolvedDir.toFile()) {
into project.platformPath + '/shared'
include "*.${project.ext.version}.dylib".toString()
eachFile { f->
f.name = f.name.replace("${project.ext.version}", "${project.ext.soVersion}")
}
exclude 'cv2.so'
exclude '**/*dephelp*'
}
from(resolvedDir.toFile()) {
into project.platformPath + '/shared'
include 'libopencv_java*.so'
include 'libopencv_java*.dylib'
exclude 'cv2.so'
exclude '**/*dephelp*'
}
from(sharedBuildDir.resolve("3rdparty").resolve("lib").toFile()) {
into project.platformPath + '/shared'
include '*.so'
}
}
} else {
from(sharedBuildDir.resolve("lib").resolve(buildTypeFolder).toFile()) {
into project.platformPath + '/shared'
include '*.lib' // import library
include '*.dll'
include '*.pdb'
exclude 'opencv_ts*'
}
from(sharedBuildDir.resolve("bin").resolve(buildTypeFolder).toFile()) {
into project.platformPath + '/shared'
include '*.lib' // import library
include '*.dll'
include '*.pdb'
exclude 'opencv_ts*'
}
from(sharedBuildDir.resolve("3rdparty").resolve("lib").toFile()) {
into project.platformPath + '/shared'
include '*.dll'
include '*.pdb'
}
}
}
project.tasks.create('cppLibsZipStatic' + buildType, Zip) {
dependsOn tasks.named('nativeLibLinks' + buildType)
destinationDirectory = outputsFolder
archiveClassifier = outputClassifierStatic
archiveBaseName = zipBaseName
duplicatesStrategy = 'exclude'
from(licenseFile) {
into '/'
}
if (!project.platform.startsWith("windows")) {
def resolvedDir = staticBuildDir.resolve("lib")
if (project.platform.startsWith("osx")) {
resolvedDir = resolvedDir.resolve(buildTypeFolder)
}
from(resolvedDir.toFile()) {
into project.platformPath + '/static'
include 'libopencv*.a'
exclude 'libopencv_*.a'
}
} else {
from(staticBuildDir.resolve("lib").resolve(buildTypeFolder).toFile()) {
into project.platformPath + '/static'
include 'opencv*.lib'
include '*.pdb'
exclude 'opencv_*.lib'
}
from(sharedBuildDir.resolve("3rdparty").resolve("lib").toFile()) {
into project.platformPath + '/static'
include '*.pdb'
}
}
}
project.tasks.create('jniJar' + buildType, Jar) {
dependsOn tasks.named('make' + buildType)
dependsOn tasks.named('nativeLibLinks' + buildType)
destinationDirectory = outputsFolder
archiveClassifier = outputClassifier
archiveBaseName = jniBaseName
duplicatesStrategy = 'exclude'
manifest {
attributes(
"Created-By": "WPILib Gradle Build Script",
"Implementation-Title": "OpenCV JNI Library, ${project.ext.platformClassifier}",
"Implementation-Version": pubVersion,
"Implementation-Vendor": "Itseez",
"Bundle-Name": "${archiveBaseName.get()}",
"Bundle-Version": pubVersion,
"Bundle-License": "https://opensource.org/licenses/BSD-3-Clause",
"Bundle-Vendor": "WPILib")
}
from(licenseFile) {
into '/'
}
def directory
def jniFileName
def jniFile
if (project.platform.startsWith("linux")) {
directory = staticBuildDir.resolve("lib").toFile()
jniFileName = "libopencv_java${libVersion}.so"
jniFile = new File(directory.absolutePath, "${jniFileName}")
} else if (project.platform.startsWith("osx")) {
directory = staticBuildDir.resolve("lib").resolve(buildTypeFolder).toFile()
System.out.println(directory.absolutePath)
jniFileName = "libopencv_java${libVersion}.dylib"
jniFile = new File(directory.absolutePath, "${jniFileName}")
} else {
directory = staticBuildDir.resolve("lib").resolve(buildTypeFolder).toFile()
jniFileName = "opencv_java${libVersion}.dll"
jniFile = new File(directory.absolutePath, "${jniFileName}")
}
def hashFile = new File(directory.absolutePath, "opencv_java${libVersion}.hash")
it.outputs.file(hashFile)
it.from(hashFile) {
into project.platformPath
}
it.doFirst {
hashFile.text = MessageDigest.getInstance("MD5").digest(jniFile.bytes).encodeHex().toString()
}
it.from(jniFile) {
into project.platformPath
}
}
}
task outputJar(type: Jar, dependsOn: make) {
archiveBaseName = javaBaseName
destinationDirectory = outputsFolder
manifest {
attributes(
"Created-By": "WPILib Gradle Build Script",
"Implementation-Title": "OpenCV",
"Implementation-Version": pubVersion,
"Implementation-Vendor": "Itseez",
"Bundle-Name": project.name,
"Bundle-Version": pubVersion,
"Bundle-License": "https://opensource.org/licenses/BSD-3-Clause",
"Bundle-Vendor": "WPILib")
}
from { zipTree(project.pathToOpenCVJar.toFile()) } {
exclude 'META-INF/*'
exclude 'META-INF'
exclude '**/*.java'
}
}
task sourcesJar(type: Jar, dependsOn: make) {
archiveBaseName = javaBaseName
destinationDirectory = outputsFolder
archiveClassifier = 'sources'
manifest {
attributes(
"Created-By": "WPILib Gradle Build Script",
"Implementation-Title": "OpenCV Java Sources",
"Implementation-Version": pubVersion,
"Implementation-Vendor": "Itseez",
"Bundle-Name": "${project.name}-sources",
"Bundle-Version": pubVersion,
"Bundle-License": "https://opensource.org/licenses/BSD-3-Clause",
"Bundle-Vendor": "WPILib")
}
from(project.cmakeBuildDirectory.resolve("modules").resolve("java").resolve("jar").resolve("opencv").resolve("java").toFile()) {
include '**/*.java'
}
}
if (!project.hasProperty('skipRelease')) {
build.dependsOn jniJar
build.dependsOn cppLibsZip
build.dependsOn cppLibsZipStatic
addTaskToCopyAllOutputs(cppLibsZip)
addTaskToCopyAllOutputs(jniJar)
addTaskToCopyAllOutputs(cppLibsZipStatic)
}
if (!project.hasProperty('skipDebug')) {
build.dependsOn cppLibsZipDebug
build.dependsOn cppLibsZipStaticDebug
build.dependsOn jniJarDebug
addTaskToCopyAllOutputs(cppLibsZipDebug)
addTaskToCopyAllOutputs(jniJarDebug)
addTaskToCopyAllOutputs(cppLibsZipStaticDebug)
}
if (!project.hasProperty('skipSources')) {
build.dependsOn cppHeadersZip
build.dependsOn cppSourcesZip
build.dependsOn outputJar
build.dependsOn sourcesJar
addTaskToCopyAllOutputs(cppSourcesZip)
addTaskToCopyAllOutputs(cppHeadersZip)
addTaskToCopyAllOutputs(outputJar)
addTaskToCopyAllOutputs(sourcesJar)
}
if (!project.hasProperty('jenkinsBuild')) {
artifacts {
archives cppHeadersZip
archives cppSourcesZip
archives cppLibsZip
archives jniJar
archives cppLibsZipDebug
archives cppLibsZipStatic
archives cppLibsZipStaticDebug
archives jniJarDebug
archives outputJar
archives sourcesJar
}
}
model {
publishing {
publications {
java(MavenPublication) {
artifact outputJar
artifact sourcesJar {
}
artifactId = "${baseArtifactId}-java"
groupId artifactGroupId
version pubVersion
}
jni(MavenPublication) {
artifact jniJar
artifact jniJarDebug
artifactId = "${baseArtifactId}-jni"
groupId artifactGroupId
version pubVersion
}
cpp(MavenPublication) {
artifact cppHeadersZip
artifact cppSourcesZip
artifact cppLibsZip
artifact cppLibsZipDebug
artifact cppLibsZipStatic
artifact cppLibsZipStaticDebug
artifactId = "${baseArtifactId}-cpp"
groupId artifactGroupId
version pubVersion
}
}
repositories {
maven {
url "${System.getProperty('user.home')}/releases/maven/${project.repo}"
}
}
}
}