Skip to content

Commit

Permalink
Create test-jni
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm001 committed Dec 24, 2023
1 parent dd8b650 commit 5ac9f68
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
plugins {
id "java"
id "cpp"
id "com.diffplug.spotless" version "6.22.0"
id "edu.wpi.first.NativeUtils" version "2024.6.1" apply false
id "edu.wpi.first.wpilib.repositories.WPILibRepositoriesPlugin" version "2020.2"
Expand Down
17 changes: 5 additions & 12 deletions photon-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ apply from: "${rootDir}/shared/common.gradle"
ext {
nativeName = "photoncore"

main_native_libs = [
"opencv_shared"
]
main_native_libs = ["opencv_shared"]

test_native_libs = [
"opencv_static"
]
test_native_libs = ["opencv_shared"]

dev_native_libs = [
"opencv_static",
"opencv_shared",
]
}

Expand Down Expand Up @@ -64,11 +60,11 @@ model {
sources {
cpp {
source {
srcDirs 'src/main/native/cpp'
srcDirs 'src/main/native/jni'
if (project.hasProperty('generatedSources')) {
srcDir generatedSources
}
include '**/jni/**/*.cpp'
include '**/*.cpp'
}
exportedHeaders {
srcDir 'src/main/native/include'
Expand All @@ -86,9 +82,6 @@ model {
return
}
lib library: "${nativeName}", linkage: 'shared'
if (!project.hasProperty('noWpiutil')) {
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
}
if (project.hasProperty('jniSplitSetup')) {
jniSplitSetup(it)
}
Expand Down
File renamed without changes.
39 changes: 38 additions & 1 deletion shared/javacpp/publish.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import java.security.MessageDigest

apply plugin: 'maven-publish'

def outputsFolder = file("$buildDir/outputs")

def baseArtifactId = nativeName
def artifactGroupId = 'org.photonvision'
def zipBaseName = "_GROUP_org_photonvision_${baseArtifactId}_ID_${baseArtifactId}-cpp_CLS"
def jniBaseName = "_GROUP_org_photonvision_${nativeName}_ID_${nativeName}-jni_CLS"

def licenseFile = file("$rootDir/LICENCE")

Expand Down Expand Up @@ -52,7 +55,32 @@ addTaskToCopyAllOutputs(cppHeadersZip)

model {
publishing {
def taskList = createComponentZipTasks($.components, [nativeName], zipBaseName, Zip, project, includeStandardZipFormat)
def taskList = createComponentZipTasks($.components, [
nativeName,
"${nativeName}JNI"
], zipBaseName, Zip, project, includeStandardZipFormat)

def jniTaskList = createComponentZipTasks($.components, ["${nativeName}JNI"], jniBaseName, Jar, project, { task, value ->
value.each { binary ->
if (binary.buildable) {
if (binary instanceof SharedLibraryBinarySpec) {
task.dependsOn binary.tasks.link
def hashFile = new File(binary.sharedLibraryFile.parentFile.absolutePath, "${binary.component.baseName}.hash")
task.outputs.file(hashFile)
task.inputs.file(binary.sharedLibraryFile)
task.from(hashFile) {
into nativeUtils.getPlatformPath(binary)
}
task.doFirst {
hashFile.text = MessageDigest.getInstance("MD5").digest(binary.sharedLibraryFile.bytes).encodeHex().toString()
}
task.from(binary.sharedLibraryFile) {
into nativeUtils.getPlatformPath(binary)
}
}
}
}
})

publications {
cpp(MavenPublication) {
Expand All @@ -66,6 +94,15 @@ model {
groupId artifactGroupId
version pubVersion
}
jni(MavenPublication) {
jniTaskList.each {
artifact it
}

artifactId = "${baseArtifactId}-jni"
groupId artifactGroupId
version pubVersion
}
}

repositories {
Expand Down

0 comments on commit 5ac9f68

Please sign in to comment.