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