blob: a33ca826866fc8a653c77f8f5b2616c1363d609a [file] [log] [blame]
Brian Silverman8fce7482020-01-05 13:18:21 -08001import java.security.MessageDigest
2apply plugin: 'maven-publish'
3
4def outputsFolder = file("$buildDir/outputs")
5
6def baseArtifactId = nativeName
7def artifactGroupId = "edu.wpi.first.${nativeName}"
8def zipBaseName = "_GROUP_edu_wpi_first_${nativeName}_ID_${nativeName}-cpp_CLS"
James Kuszmaulb13e13f2023-11-22 20:44:04 -08009ext.zipBaseName = zipBaseName
Brian Silverman8fce7482020-01-05 13:18:21 -080010def jniBaseName = "_GROUP_edu_wpi_first_${nativeName}_ID_${nativeName}-jni_CLS"
Austin Schuh1e69f942020-11-14 15:06:14 -080011def jniCvStaticBaseName = "_GROUP_edu_wpi_first_${nativeName}_ID_${nativeName}-jnicvstatic_CLS"
Brian Silverman8fce7482020-01-05 13:18:21 -080012
Austin Schuh1e69f942020-11-14 15:06:14 -080013def licenseFile = file("$rootDir/license.md")
Brian Silverman8fce7482020-01-05 13:18:21 -080014
15task cppSourcesZip(type: Zip) {
16 destinationDirectory = outputsFolder
17 archiveBaseName = zipBaseName
James Kuszmaulb13e13f2023-11-22 20:44:04 -080018 archiveClassifier = "sources"
Brian Silverman8fce7482020-01-05 13:18:21 -080019 duplicatesStrategy = 'exclude'
20
21 from(licenseFile) {
22 into '/'
23 }
24
25 from('src/main/native/cpp') {
26 into '/'
27 }
28
29 model {
30 components {
31 it.all {
32 if (it in getJniSpecClass()) {
33 it.jniHeaderLocations.each {
34 dependsOn it.key
35 from(it.value) {
36 into '/jni'
37 }
38 }
39 }
40 }
41 }
42 }
43}
44
45task cppHeadersZip(type: Zip) {
46 destinationDirectory = outputsFolder
47 archiveBaseName = zipBaseName
James Kuszmaulb13e13f2023-11-22 20:44:04 -080048 archiveClassifier = "headers"
Brian Silverman8fce7482020-01-05 13:18:21 -080049
50 from(licenseFile) {
51 into '/'
52 }
53
Austin Schuh812d0d12021-11-04 20:16:48 -070054 ext.includeDirs = [
55 project.file('src/main/native/include')
56 ]
57
58 ext.includeDirs.each {
59 from(it) {
60 into '/'
61 }
Brian Silverman8fce7482020-01-05 13:18:21 -080062 }
63}
64
65artifacts {
66 archives cppHeadersZip
67 archives cppSourcesZip
68}
69
70addTaskToCopyAllOutputs(cppSourcesZip)
71addTaskToCopyAllOutputs(cppHeadersZip)
72
73model {
74 publishing {
Austin Schuh812d0d12021-11-04 20:16:48 -070075 def taskList = createComponentZipTasks($.components, [
76 nativeName,
77 "${nativeName}JNIShared"
78 ], zipBaseName, Zip, project, includeStandardZipFormat)
Brian Silverman8fce7482020-01-05 13:18:21 -080079
80 def jniTaskList = createComponentZipTasks($.components, ["${nativeName}JNI"], jniBaseName, Jar, project, { task, value ->
81 value.each { binary ->
82 if (binary.buildable) {
83 if (binary instanceof SharedLibraryBinarySpec) {
84 task.dependsOn binary.tasks.link
85 def hashFile = new File(binary.sharedLibraryFile.parentFile.absolutePath, "${binary.component.baseName}.hash")
86 task.outputs.file(hashFile)
87 task.inputs.file(binary.sharedLibraryFile)
88 task.from(hashFile) {
89 into nativeUtils.getPlatformPath(binary)
90 }
91 task.doFirst {
92 hashFile.text = MessageDigest.getInstance("MD5").digest(binary.sharedLibraryFile.bytes).encodeHex().toString()
93 }
94 task.from(binary.sharedLibraryFile) {
95 into nativeUtils.getPlatformPath(binary)
96 }
97 }
98 }
99 }
100 })
101
102 publications {
103 cpp(MavenPublication) {
104 taskList.each {
105 artifact it
106 }
107 artifact cppHeadersZip
108 artifact cppSourcesZip
109
110 artifactId = "${baseArtifactId}-cpp"
111 groupId artifactGroupId
112 version wpilibVersioning.version.get()
113 }
114 jni(MavenPublication) {
115 jniTaskList.each {
116 artifact it
117 }
118
119 artifactId = "${baseArtifactId}-jni"
120 groupId artifactGroupId
121 version wpilibVersioning.version.get()
122 }
123 }
Austin Schuh1e69f942020-11-14 15:06:14 -0800124
125 if (project.hasProperty('cvStaticBuild') && project.getProperty('cvStaticBuild') == true) {
126 def jniCvTaskList = createComponentZipTasks($.components, ["${nativeName}JNICvStatic"], jniCvStaticBaseName, Zip, project, { task, value ->
127 value.each { binary ->
128 if (binary.buildable) {
129 if (binary instanceof SharedLibraryBinarySpec) {
130 task.dependsOn binary.tasks.link
131 task.inputs.file(binary.sharedLibraryFile)
132 task.from(binary.sharedLibraryFile) {
133 into nativeUtils.getPlatformPath(binary) + '/shared'
134 }
135 def sharedPath = binary.sharedLibraryFile.absolutePath
136 sharedPath = sharedPath.substring(0, sharedPath.length() - 4)
137
138 task.from(new File(sharedPath + '.pdb')) {
139 into nativeUtils.getPlatformPath(binary) + '/shared'
140 }
141 }
142 }
143 }
144 })
145
146 publications {
147 jniCvStatic(MavenPublication) {
148 jniCvTaskList.each {
149 artifact it
150 }
151
152 artifactId = "${baseArtifactId}-jnicvstatic"
153 groupId artifactGroupId
154 version wpilibVersioning.version.get()
155 }
156 }
157 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800158 }
159}