blob: f3696312d0de19502ce8b4d0073f198e5b287287 [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
53 from('src/main/native/include') {
54 into '/'
55 }
56}
57
58artifacts {
59 archives cppHeadersZip
60 archives cppSourcesZip
61}
62
63addTaskToCopyAllOutputs(cppSourcesZip)
64addTaskToCopyAllOutputs(cppHeadersZip)
65
66model {
67 publishing {
68 def taskList = createComponentZipTasks($.components, [nativeName, "${nativeName}JNIShared"], zipBaseName, Zip, project, includeStandardZipFormat)
69
70 def jniTaskList = createComponentZipTasks($.components, ["${nativeName}JNI"], jniBaseName, Jar, project, { task, value ->
71 value.each { binary ->
72 if (binary.buildable) {
73 if (binary instanceof SharedLibraryBinarySpec) {
74 task.dependsOn binary.tasks.link
75 def hashFile = new File(binary.sharedLibraryFile.parentFile.absolutePath, "${binary.component.baseName}.hash")
76 task.outputs.file(hashFile)
77 task.inputs.file(binary.sharedLibraryFile)
78 task.from(hashFile) {
79 into nativeUtils.getPlatformPath(binary)
80 }
81 task.doFirst {
82 hashFile.text = MessageDigest.getInstance("MD5").digest(binary.sharedLibraryFile.bytes).encodeHex().toString()
83 }
84 task.from(binary.sharedLibraryFile) {
85 into nativeUtils.getPlatformPath(binary)
86 }
87 }
88 }
89 }
90 })
91
92 publications {
93 cpp(MavenPublication) {
94 taskList.each {
95 artifact it
96 }
97 artifact cppHeadersZip
98 artifact cppSourcesZip
99
100 artifactId = "${baseArtifactId}-cpp"
101 groupId artifactGroupId
102 version wpilibVersioning.version.get()
103 }
104 jni(MavenPublication) {
105 jniTaskList.each {
106 artifact it
107 }
108
109 artifactId = "${baseArtifactId}-jni"
110 groupId artifactGroupId
111 version wpilibVersioning.version.get()
112 }
113 }
Austin Schuh1e69f942020-11-14 15:06:14 -0800114
115 if (project.hasProperty('cvStaticBuild') && project.getProperty('cvStaticBuild') == true) {
116 def jniCvTaskList = createComponentZipTasks($.components, ["${nativeName}JNICvStatic"], jniCvStaticBaseName, Zip, project, { task, value ->
117 value.each { binary ->
118 if (binary.buildable) {
119 if (binary instanceof SharedLibraryBinarySpec) {
120 task.dependsOn binary.tasks.link
121 task.inputs.file(binary.sharedLibraryFile)
122 task.from(binary.sharedLibraryFile) {
123 into nativeUtils.getPlatformPath(binary) + '/shared'
124 }
125 def sharedPath = binary.sharedLibraryFile.absolutePath
126 sharedPath = sharedPath.substring(0, sharedPath.length() - 4)
127
128 task.from(new File(sharedPath + '.pdb')) {
129 into nativeUtils.getPlatformPath(binary) + '/shared'
130 }
131 }
132 }
133 }
134 })
135
136 publications {
137 jniCvStatic(MavenPublication) {
138 jniCvTaskList.each {
139 artifact it
140 }
141
142 artifactId = "${baseArtifactId}-jnicvstatic"
143 groupId artifactGroupId
144 version wpilibVersioning.version.get()
145 }
146 }
147 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800148 }
149}