Files
allwpilib/wpilibc/build.gradle
Thad House e6a4254488 [build] Delete test folders after tests execute (#2891)
Also deletes object files.

Both of these things are only done on the build server (-PbuildServer flag).

This will remove all test folders, which removes lots of copies of dependencies.

This also fixes an issue where gtest exectubables were installed for cross builds, even though they should not have been.
2020-11-27 21:44:47 -08:00

250 lines
9.2 KiB
Groovy

apply plugin: 'cpp'
apply plugin: 'c'
apply plugin: 'google-test-test-suite'
apply plugin: 'visual-studio'
apply plugin: 'edu.wpi.first.NativeUtils'
apply plugin: SingleNativeBuild
apply plugin: ExtraTasks
ext {
nativeName = 'wpilibc'
}
apply from: "${rootDir}/shared/config.gradle"
def wpilibVersionFileInput = file("src/generate/WPILibVersion.cpp.in")
def wpilibVersionFileOutput = file("$buildDir/generated/cpp/WPILibVersion.cpp")
task generateCppVersion() {
description = 'Generates the wpilib version class'
group = 'WPILib'
outputs.file wpilibVersionFileOutput
inputs.file wpilibVersionFileInput
if (wpilibVersioning.releaseMode) {
outputs.upToDateWhen { false }
}
// We follow a simple set of checks to determine whether we should generate a new version file:
// 1. If the release type is not development, we generate a new version file
// 2. If there is no generated version number, we generate a new version file
// 3. If there is a generated build number, and the release type is development, then we will
// only generate if the publish task is run.
doLast {
def version = wpilibVersioning.version.get()
println "Writing version ${version} to $wpilibVersionFileOutput"
if (wpilibVersionFileOutput.exists()) {
wpilibVersionFileOutput.delete()
}
def read = wpilibVersionFileInput.text.replace('${wpilib_version}', version)
wpilibVersionFileOutput.write(read)
}
}
gradle.taskGraph.addTaskExecutionGraphListener { graph ->
def willPublish = graph.hasTask(publish)
if (willPublish) {
generateCppVersion.outputs.upToDateWhen { false }
}
}
project(':').libraryBuild.dependsOn build
ext {
staticGtestConfigs = [:]
}
staticGtestConfigs["${nativeName}Test"] = []
apply from: "${rootDir}/shared/googletest.gradle"
nativeUtils.exportsConfigs {
wpilibc {
x86ExcludeSymbols = ['_CT??_R0?AV_System_error', '_CT??_R0?AVexception', '_CT??_R0?AVfailure',
'_CT??_R0?AVruntime_error', '_CT??_R0?AVsystem_error', '_CTA5?AVfailure',
'_TI5?AVfailure', '_CT??_R0?AVout_of_range', '_CTA3?AVout_of_range',
'_TI3?AVout_of_range', '_CT??_R0?AVbad_cast']
x64ExcludeSymbols = ['_CT??_R0?AV_System_error', '_CT??_R0?AVexception', '_CT??_R0?AVfailure',
'_CT??_R0?AVruntime_error', '_CT??_R0?AVsystem_error', '_CTA5?AVfailure',
'_TI5?AVfailure', '_CT??_R0?AVout_of_range', '_CTA3?AVout_of_range',
'_TI3?AVout_of_range', '_CT??_R0?AVbad_cast']
}
}
model {
components {
"${nativeName}Base"(NativeLibrarySpec) {
sources {
cpp {
source {
srcDirs = ['src/main/native/cpp', "$buildDir/generated/cpp"]
include '**/*.cpp'
}
exportedHeaders {
srcDirs 'src/main/native/include'
}
}
}
binaries.all {
if (it instanceof SharedLibraryBinarySpec) {
it.buildable = false
return
}
cppCompiler.define 'DYNAMIC_CAMERA_SERVER'
lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
project(':hal').addHalDependency(it, 'shared')
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
}
}
"${nativeName}"(NativeLibrarySpec) {
sources {
cpp {
source {
srcDirs "src/main/native/cppcs"
include '**/*.cpp'
}
exportedHeaders {
srcDirs 'src/main/native/include', '../cameraserver/src/main/native/include'
}
}
}
binaries.all {
lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
project(':hal').addHalDependency(it, 'shared')
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
if (it instanceof SharedLibraryBinarySpec) {
cppCompiler.define 'DYNAMIC_CAMERA_SERVER'
if (buildType == buildTypes.debug) {
cppCompiler.define 'DYNAMIC_CAMERA_SERVER_DEBUG'
}
} else {
lib project: ':cscore', library: 'cscore', linkage: 'shared'
lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
nativeUtils.useRequiredLibrary(it, 'opencv_shared')
}
}
appendDebugPathToBinaries(binaries)
}
// 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'
lib library: 'wpilibc'
}
exportedHeaders {
srcDirs 'src/dev/native/include'
}
}
}
binaries.all {
lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
lib project: ':cscore', library: 'cscore', linkage: 'shared'
project(':hal').addHalDependency(it, 'shared')
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
nativeUtils.useRequiredLibrary(it, 'opencv_shared')
if (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'
}
}
c {
source {
srcDirs 'src/test/native/c'
include '**/*.c'
}
exportedHeaders {
srcDirs 'src/test/native/include', 'src/main/native/c'
}
}
}
}
}
binaries {
all {
tasks.withType(CppCompile) {
dependsOn generateCppVersion
}
}
withType(GoogleTestTestSuiteBinarySpec) {
lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
lib project: ':cscore', library: 'cscore', linkage: 'shared'
project(':hal').addHalDependency(it, 'shared')
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
nativeUtils.useRequiredLibrary(it, 'opencv_shared')
lib library: nativeName, linkage: 'shared'
if (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) {
def found = false
c.each {
if (it in NativeExecutableSpec && it.name == "${nativeName}Dev") {
it.binaries.each {
if (!found) {
def arch = it.targetPlatform.architecture.name
if (arch == 'x86-64' || arch == 'x86') {
dependsOn it.tasks.install
found = true
}
}
}
}
}
}
}
}
apply from: "${rootDir}/shared/cppDesktopTestTask.gradle"
tasks.withType(RunTestExecutable) {
args "--gtest_output=xml:test_detail.xml"
outputs.dir outputDir
}
apply from: 'publish.gradle'
def oldWpilibVersionFile = file('src/main/native/cpp/WPILibVersion.cpp')
clean {
delete oldWpilibVersionFile
}