mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Also move some things in HAL for consistency. WAS: C++: - C APIs: #include "mockdata/AccelerometerData.h" - User side class: #include "simulation/AccelerometerSim.h" Java: - JNI APIs: hal.sim.mockdata.AccelerometerData (and a few classes in hal.sim) - User side classes: hal.sim.AccelerometerSim IS: C++: - C APIs: #include "hal/simulation/AccelerometerData.h" - C++ class: #include "frc/simulation/AccelerometerSim.h" Java: - JNI APIs: hal.simulation.AccelerometerData - User side class: wpilibj.simulation.AccelerometerSim
114 lines
3.4 KiB
Groovy
114 lines
3.4 KiB
Groovy
def athenaSimJniOutputDir = file("$buildDir/generated/cpp")
|
|
def athenaSimJniOutputFile = file("$athenaSimJniOutputDir/simjni.cpp")
|
|
|
|
task generateAthenaSimFiles() {
|
|
Set dirs = [];
|
|
|
|
def createdTask = it
|
|
outputs.file athenaSimJniOutputFile
|
|
|
|
model {
|
|
components {
|
|
it.all { component ->
|
|
if (component in getJniSpecClass()) {
|
|
component.binaries.all { binary ->
|
|
if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
|
|
binary.tasks.withType(CppCompile) {
|
|
it.dependsOn createdTask
|
|
}
|
|
component.jniHeaderLocations.each {
|
|
dependsOn it.key
|
|
createdTask.inputs.dir it.value
|
|
dirs << it.value
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
doLast {
|
|
def symbolList = []
|
|
dirs.each {
|
|
def tree = fileTree(dir: it)
|
|
tree.each { file ->
|
|
if (!file.name.contains('edu_wpi_first_hal_simulation_')) {
|
|
return
|
|
}
|
|
boolean reading = false
|
|
String currentLine = ''
|
|
file.eachLine { line ->
|
|
if (line.trim()) {
|
|
if (line.contains(';') && reading) {
|
|
currentLine += line.trim()
|
|
reading = false
|
|
symbolList << currentLine
|
|
currentLine = ''
|
|
}
|
|
if (line.startsWith("JNIEXPORT ") && line.contains('JNICALL')) {
|
|
if (line.contains(';')) {
|
|
symbolList << line
|
|
currentLine = ''
|
|
reading = false
|
|
} else {
|
|
reading = true
|
|
currentLine += line.trim()
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
athenaSimJniOutputDir.mkdirs()
|
|
athenaSimJniOutputFile.withWriter { out ->
|
|
out.println '#include <jni.h>'
|
|
out.println '''
|
|
static JavaVM* jvm = nullptr;
|
|
|
|
namespace hal {
|
|
namespace sim {
|
|
jint SimOnLoad(JavaVM* vm, void* reserved) {
|
|
jvm = vm;
|
|
|
|
JNIEnv *env;
|
|
if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) != JNI_OK)
|
|
return JNI_ERR;
|
|
|
|
return JNI_VERSION_1_6;
|
|
}
|
|
|
|
void SimOnUnload(JavaVM * vm, void* reserved) {
|
|
JNIEnv *env;
|
|
if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) != JNI_OK)
|
|
return;
|
|
jvm = nullptr;
|
|
}
|
|
}
|
|
}
|
|
|
|
static void ThrowSimException(JNIEnv* env) {
|
|
|
|
}
|
|
'''
|
|
out.println 'extern "C" {'
|
|
symbolList.each {
|
|
def symbol = it.replace('JNIEnv *', 'JNIEnv * env')
|
|
if (symbol.contains('JNIEXPORT void')) {
|
|
symbol = symbol.replace(';', ''' {
|
|
ThrowSimException(env);
|
|
}''')
|
|
} else {
|
|
symbol = symbol.replace(';', ''' {
|
|
ThrowSimException(env);
|
|
return 0;
|
|
}''')
|
|
}
|
|
out.println symbol
|
|
}
|
|
out.println '}'
|
|
}
|
|
}
|
|
}
|