mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
To reduce the need for users to manually perform unit conversions, this allows Measure objects from wpiunits to be passed into most places in wpimath that currently expect doubles in terms of SI units like meters. For example, users would need to know that unit conversion is required - and what the correct units are. Using units would be more difficult to write code for than just hardcoding a value or using Units.inchesToMeters. Now, using units has no more developer overhead than using raw numbers.
138 lines
3.5 KiB
Groovy
138 lines
3.5 KiB
Groovy
import com.hubspot.jinjava.Jinjava;
|
|
import com.hubspot.jinjava.JinjavaConfig;
|
|
|
|
ext {
|
|
useJava = true
|
|
useCpp = true
|
|
baseId = 'wpimath'
|
|
groupId = 'edu.wpi.first.wpimath'
|
|
|
|
nativeName = 'wpimath'
|
|
devMain = 'edu.wpi.first.math.DevMain'
|
|
}
|
|
|
|
apply from: "${rootDir}/shared/jni/setupBuild.gradle"
|
|
|
|
cppHeadersZip {
|
|
from('src/main/native/thirdparty/eigen/include') {
|
|
into '/'
|
|
}
|
|
from('src/main/native/thirdparty/gcem/include') {
|
|
into '/'
|
|
}
|
|
from("$buildDir/generated/source/proto/main/cpp") {
|
|
into '/wpimath/protobuf'
|
|
include '*.h'
|
|
}
|
|
}
|
|
|
|
cppHeadersZip.dependsOn generateProto
|
|
|
|
model {
|
|
components {
|
|
all {
|
|
it.sources.each {
|
|
it.exportedHeaders {
|
|
srcDirs 'src/main/native/include',
|
|
'src/main/native/thirdparty/eigen/include',
|
|
'src/main/native/thirdparty/gcem/include'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
api project(":wpiunits")
|
|
api "org.ejml:ejml-simple:0.43.1"
|
|
api "com.fasterxml.jackson.core:jackson-annotations:2.15.2"
|
|
api "com.fasterxml.jackson.core:jackson-core:2.15.2"
|
|
api "com.fasterxml.jackson.core:jackson-databind:2.15.2"
|
|
api "us.hebi.quickbuf:quickbuf-runtime:1.3.2"
|
|
}
|
|
|
|
def wpilibNumberFileInput = file("src/generate/GenericNumber.java.jinja")
|
|
def natFileInput = file("src/generate/Nat.java.jinja")
|
|
def wpilibNumberFileOutputDir = file("$buildDir/generated/java/edu/wpi/first/math/numbers")
|
|
def wpilibNatFileOutput = file("$buildDir/generated/java/edu/wpi/first/math/Nat.java")
|
|
def maxNum = 20
|
|
|
|
task generateNumbers() {
|
|
description = "Generates generic number classes from template"
|
|
group = "WPILib"
|
|
|
|
inputs.file wpilibNumberFileInput
|
|
outputs.dir wpilibNumberFileOutputDir
|
|
|
|
doLast {
|
|
if(wpilibNumberFileOutputDir.exists()) {
|
|
wpilibNumberFileOutputDir.delete()
|
|
}
|
|
wpilibNumberFileOutputDir.mkdirs()
|
|
|
|
def config = new JinjavaConfig()
|
|
def jinjava = new Jinjava(config)
|
|
|
|
def template = wpilibNumberFileInput.text
|
|
|
|
for(i in 0..maxNum) {
|
|
def outputFile = new File(wpilibNumberFileOutputDir, "N${i}.java")
|
|
def replacements = new HashMap<String,?>()
|
|
replacements.put("num", i)
|
|
def output = jinjava.render(template, replacements)
|
|
outputFile.write(output)
|
|
}
|
|
}
|
|
}
|
|
|
|
task generateNat() {
|
|
description = "Generates Nat.java"
|
|
group = "WPILib"
|
|
inputs.file natFileInput
|
|
outputs.file wpilibNatFileOutput
|
|
dependsOn generateNumbers
|
|
|
|
doLast {
|
|
if(wpilibNatFileOutput.exists()) {
|
|
wpilibNatFileOutput.delete()
|
|
}
|
|
|
|
def config = new JinjavaConfig()
|
|
def jinjava = new Jinjava(config)
|
|
|
|
def template = natFileInput.text
|
|
|
|
def replacements = new HashMap<String,?>()
|
|
replacements.put("nums", 0..maxNum)
|
|
|
|
def output = jinjava.render(template, replacements)
|
|
wpilibNatFileOutput.write(output)
|
|
}
|
|
}
|
|
|
|
sourceSets.main.java.srcDir "${buildDir}/generated/java"
|
|
compileJava.dependsOn generateNumbers
|
|
compileJava.dependsOn generateNat
|
|
|
|
task unitsHeaders(type: Zip) {
|
|
destinationDirectory = file("$buildDir/outputs")
|
|
archiveBaseName = zipBaseName
|
|
archiveClassifier = "units"
|
|
|
|
from(licenseFile) {
|
|
into '/'
|
|
}
|
|
|
|
ext.includeDirs = [
|
|
project.file('src/main/native/include/units')
|
|
]
|
|
|
|
ext.includeDirs.each {
|
|
from(it) {
|
|
into '/units'
|
|
}
|
|
}
|
|
}
|
|
|
|
addTaskToCopyAllOutputs(unitsHeaders)
|