Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 1 | import java.security.MessageDigest |
| 2 | apply plugin: 'maven-publish' |
| 3 | |
| 4 | def outputsFolder = file("$buildDir/outputs") |
| 5 | |
| 6 | def baseArtifactId = nativeName |
| 7 | def artifactGroupId = "edu.wpi.first.${nativeName}" |
| 8 | def zipBaseName = "_GROUP_edu_wpi_first_${nativeName}_ID_${nativeName}-cpp_CLS" |
| 9 | def jniBaseName = "_GROUP_edu_wpi_first_${nativeName}_ID_${nativeName}-jni_CLS" |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 10 | def jniCvStaticBaseName = "_GROUP_edu_wpi_first_${nativeName}_ID_${nativeName}-jnicvstatic_CLS" |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 11 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 12 | def licenseFile = file("$rootDir/license.md") |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 13 | |
| 14 | task 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 | |
| 44 | task cppHeadersZip(type: Zip) { |
| 45 | destinationDirectory = outputsFolder |
| 46 | archiveBaseName = zipBaseName |
| 47 | classifier = "headers" |
| 48 | |
| 49 | from(licenseFile) { |
| 50 | into '/' |
| 51 | } |
| 52 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 53 | ext.includeDirs = [ |
| 54 | project.file('src/main/native/include') |
| 55 | ] |
| 56 | |
| 57 | ext.includeDirs.each { |
| 58 | from(it) { |
| 59 | into '/' |
| 60 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
| 64 | artifacts { |
| 65 | archives cppHeadersZip |
| 66 | archives cppSourcesZip |
| 67 | } |
| 68 | |
| 69 | addTaskToCopyAllOutputs(cppSourcesZip) |
| 70 | addTaskToCopyAllOutputs(cppHeadersZip) |
| 71 | |
| 72 | model { |
| 73 | publishing { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 74 | def taskList = createComponentZipTasks($.components, [ |
| 75 | nativeName, |
| 76 | "${nativeName}JNIShared" |
| 77 | ], zipBaseName, Zip, project, includeStandardZipFormat) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 78 | |
| 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 Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 123 | |
| 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 Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 157 | } |
| 158 | } |