Rename our allwpilib (which is now 2020) to not have 2019 in the name
Change-Id: I3c07f85ed32ab8b97db765a9b43f2a6ce7da964a
diff --git a/shared/jni/publish.gradle b/shared/jni/publish.gradle
new file mode 100644
index 0000000..765302a
--- /dev/null
+++ b/shared/jni/publish.gradle
@@ -0,0 +1,114 @@
+import java.security.MessageDigest
+apply plugin: 'maven-publish'
+
+def outputsFolder = file("$buildDir/outputs")
+
+def baseArtifactId = nativeName
+def artifactGroupId = "edu.wpi.first.${nativeName}"
+def zipBaseName = "_GROUP_edu_wpi_first_${nativeName}_ID_${nativeName}-cpp_CLS"
+def jniBaseName = "_GROUP_edu_wpi_first_${nativeName}_ID_${nativeName}-jni_CLS"
+
+def licenseFile = file("$rootDir/license.txt")
+
+task cppSourcesZip(type: Zip) {
+ destinationDirectory = outputsFolder
+ archiveBaseName = zipBaseName
+ classifier = "sources"
+ duplicatesStrategy = 'exclude'
+
+ from(licenseFile) {
+ into '/'
+ }
+
+ from('src/main/native/cpp') {
+ into '/'
+ }
+
+ model {
+ components {
+ it.all {
+ if (it in getJniSpecClass()) {
+ it.jniHeaderLocations.each {
+ dependsOn it.key
+ from(it.value) {
+ into '/jni'
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+task cppHeadersZip(type: Zip) {
+ destinationDirectory = outputsFolder
+ archiveBaseName = zipBaseName
+ classifier = "headers"
+
+ from(licenseFile) {
+ into '/'
+ }
+
+ from('src/main/native/include') {
+ into '/'
+ }
+}
+
+artifacts {
+ archives cppHeadersZip
+ archives cppSourcesZip
+}
+
+addTaskToCopyAllOutputs(cppSourcesZip)
+addTaskToCopyAllOutputs(cppHeadersZip)
+
+model {
+ publishing {
+ def taskList = createComponentZipTasks($.components, [nativeName, "${nativeName}JNIShared"], 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) {
+ taskList.each {
+ artifact it
+ }
+ artifact cppHeadersZip
+ artifact cppSourcesZip
+
+ artifactId = "${baseArtifactId}-cpp"
+ groupId artifactGroupId
+ version wpilibVersioning.version.get()
+ }
+ jni(MavenPublication) {
+ jniTaskList.each {
+ artifact it
+ }
+
+ artifactId = "${baseArtifactId}-jni"
+ groupId artifactGroupId
+ version wpilibVersioning.version.get()
+ }
+ }
+ }
+}
diff --git a/shared/jni/setupBuild.gradle b/shared/jni/setupBuild.gradle
new file mode 100644
index 0000000..6c6148c
--- /dev/null
+++ b/shared/jni/setupBuild.gradle
@@ -0,0 +1,290 @@
+apply plugin: 'cpp'
+apply plugin: 'google-test-test-suite'
+apply plugin: 'visual-studio'
+apply plugin: 'edu.wpi.first.NativeUtils'
+apply plugin: 'edu.wpi.first.GradleJni'
+apply plugin: SingleNativeBuild
+apply plugin: ExtraTasks
+
+apply from: "${rootDir}/shared/config.gradle"
+
+ext {
+ baseId = nativeName
+ groupId = "edu.wpi.first.${nativeName}"
+}
+
+apply from: "${rootDir}/shared/java/javacommon.gradle"
+
+dependencies {
+ if (!project.hasProperty('noWpiutil')) {
+ implementation project(':wpiutil')
+ devImplementation project(':wpiutil')
+ }
+}
+
+project(':').libraryBuild.dependsOn build
+
+ext {
+ staticGtestConfigs = [:]
+}
+
+staticGtestConfigs["${nativeName}Test"] = []
+
+apply from: "${rootDir}/shared/googletest.gradle"
+
+model {
+ components {
+ "${nativeName}Base"(NativeLibrarySpec) {
+ if (project.hasProperty('setBaseName')) {
+ baseName = setBaseName
+ }
+ sources {
+ cpp {
+ source {
+ srcDirs 'src/main/native/cpp'
+ include '**/*.cpp'
+ exclude '**/jni/*.cpp'
+ }
+ exportedHeaders {
+ srcDir 'src/main/native/include'
+ if (project.hasProperty('generatedHeaders')) {
+ srcDir generatedHeaders
+ }
+ include '**/*.h'
+ }
+ }
+ }
+ binaries.all {
+ if (it instanceof SharedLibraryBinarySpec) {
+ it.buildable = false
+ return
+ }
+ if (!project.hasProperty('noWpiutil')) {
+ lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
+ }
+ if (project.hasProperty('splitSetup')) {
+ splitSetup(it)
+ }
+ }
+ }
+ "${nativeName}"(NativeLibrarySpec) {
+ if (project.hasProperty('setBaseName')) {
+ baseName = setBaseName
+ }
+ sources {
+ cpp {
+ source {
+ srcDirs "${rootDir}/shared/singlelib"
+ include '**/*.cpp'
+ }
+ exportedHeaders {
+ srcDir 'src/main/native/include'
+ if (project.hasProperty('generatedHeaders')) {
+ srcDir generatedHeaders
+ }
+ }
+ }
+ }
+ if (!project.hasProperty('noWpiutil')) {
+ binaries.all {
+ lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
+ }
+ }
+ appendDebugPathToBinaries(binaries)
+ }
+ "${nativeName}JNIShared"(JniNativeLibrarySpec) {
+ if (project.hasProperty('setBaseName')) {
+ baseName = setBaseName + 'jni'
+ } else {
+ baseName = nativeName + 'jni'
+ }
+
+ enableCheckTask true
+ javaCompileTasks << compileJava
+ jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.roborio)
+ jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.raspbian)
+ jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.aarch64bionic)
+ sources {
+ cpp {
+ source {
+ srcDirs 'src/main/native/cpp'
+ include '**/jni/*.cpp'
+ }
+ exportedHeaders {
+ srcDir 'src/main/native/include'
+ if (project.hasProperty('generatedHeaders')) {
+ srcDir generatedHeaders
+ }
+ include '**/*.h'
+ }
+
+ }
+ }
+ binaries.all {
+ if (it instanceof StaticLibraryBinarySpec) {
+ it.buildable = false
+ return
+ }
+ lib library: "${nativeName}", linkage: 'shared'
+ if (!project.hasProperty('noWpiutil')) {
+ lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
+ }
+ if (project.hasProperty('jniSplitSetup')) {
+ jniSplitSetup(it)
+ }
+ }
+ }
+ "${nativeName}JNI"(JniNativeLibrarySpec) {
+ if (project.hasProperty('setBaseName')) {
+ baseName = setBaseName + 'jni'
+ } else {
+ baseName = nativeName + 'jni'
+ }
+
+ enableCheckTask true
+ javaCompileTasks << compileJava
+ jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.roborio)
+ jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.raspbian)
+ jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.aarch64bionic)
+ sources {
+ cpp {
+ source {
+ srcDirs 'src/main/native/cpp'
+ include '**/jni/*.cpp'
+ }
+ exportedHeaders {
+ srcDir 'src/main/native/include'
+ if (project.hasProperty('generatedHeaders')) {
+ srcDir generatedHeaders
+ }
+ include '**/*.h'
+ }
+ }
+ }
+ binaries.all {
+ if (it instanceof StaticLibraryBinarySpec) {
+ it.buildable = false
+ return
+ }
+ if (!project.hasProperty('noWpiutil')) {
+ lib project: ':wpiutil', library: 'wpiutil', linkage: 'static'
+ }
+ if (project.hasProperty('jniSplitSetup')) {
+ jniSplitSetup(it)
+ }
+ }
+ }
+ // By default, a development executable will be generated. This is to help the case of
+ // testing specific functionality of the library.
+ "${nativeName}Dev"(NativeExecutableSpec) {
+ targetBuildTypes 'debug'
+ sources {
+ cpp {
+
+ source {
+ srcDirs 'src/dev/native/cpp'
+ include '**/*.cpp'
+ }
+ exportedHeaders {
+ srcDir 'src/main/native/include'
+ if (project.hasProperty('generatedHeaders')) {
+ srcDir generatedHeaders
+ }
+ }
+ }
+ }
+ binaries.all {
+ lib library: nativeName, linkage: 'shared'
+ lib library: "${nativeName}JNIShared", linkage: 'shared'
+ if (!project.hasProperty('noWpiutil')) {
+ lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
+ }
+ if (nativeName == 'hal' && it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
+ nativeUtils.useRequiredLibrary(it, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
+ }
+ }
+ }
+ }
+ testSuites {
+ "${nativeName}Test"(GoogleTestTestSuiteSpec) {
+ for(NativeComponentSpec c : $.components) {
+ if (c.name == nativeName) {
+ testing c
+ break
+ }
+ }
+ sources {
+ cpp {
+ source {
+ srcDirs 'src/test/native/cpp'
+ include '**/*.cpp'
+ }
+ exportedHeaders {
+ srcDirs 'src/test/native/include', 'src/main/native/cpp'
+ if (project.hasProperty('generatedHeaders')) {
+ srcDir generatedHeaders
+ }
+ }
+ }
+ }
+ }
+ }
+ binaries {
+ withType(GoogleTestTestSuiteBinarySpec) {
+ lib library: nativeName, linkage: 'shared'
+ if (!project.hasProperty('noWpiutil')) {
+ lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
+ if (nativeName == 'hal' && it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
+ nativeUtils.useRequiredLibrary(it, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
+ }
+ }
+ }
+ }
+ tasks {
+ def c = $.components
+ project.tasks.create('runCpp', Exec) {
+ group = 'WPILib'
+ description = "Run the ${nativeName}Dev executable"
+ def found = false
+ def systemArch = getCurrentArch()
+ c.each {
+ if (it in NativeExecutableSpec && it.name == "${nativeName}Dev") {
+ it.binaries.each {
+ if (!found) {
+ def arch = it.targetPlatform.name
+ if (arch == systemArch) {
+ dependsOn it.tasks.install
+ commandLine it.tasks.install.runScriptFile.get().asFile.toString()
+ def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib'
+ test.dependsOn it.tasks.install
+ test.systemProperty 'java.library.path', filePath
+ test.environment 'LD_LIBRARY_PATH', filePath
+ test.workingDir filePath
+ run.dependsOn it.tasks.install
+ run.systemProperty 'java.library.path', filePath
+ run.environment 'LD_LIBRARY_PATH', filePath
+ run.workingDir filePath
+
+ found = true
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+apply from: "${rootDir}/shared/cppDesktopTestTask.gradle"
+apply from: "${rootDir}/shared/javaDesktopTestTask.gradle"
+
+ext.getJniSpecClass = {
+ return JniNativeLibrarySpec
+}
+
+tasks.withType(RunTestExecutable) {
+ args "--gtest_output=xml:test_detail.xml"
+ outputs.dir outputDir
+}
+
+apply from: "${rootDir}/shared/jni/publish.gradle"