From e6a4254488e08ef656522c9c75cfb37d0b7762f9 Mon Sep 17 00:00:00 2001 From: Thad House Date: Fri, 27 Nov 2020 21:44:47 -0800 Subject: [PATCH] [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. --- .../src/main/groovy/SingleNativeBuild.groovy | 18 ++++++++++++++++++ hal/build.gradle | 2 -- shared/config.gradle | 13 +++++++++++++ shared/jni/setupBuild.gradle | 9 +++++++++ wpilibNewCommands/build.gradle | 2 -- wpilibOldCommands/build.gradle | 2 -- wpilibc/build.gradle | 2 -- 7 files changed, 40 insertions(+), 8 deletions(-) diff --git a/buildSrc/src/main/groovy/SingleNativeBuild.groovy b/buildSrc/src/main/groovy/SingleNativeBuild.groovy index d43afff803..dfb42d1409 100644 --- a/buildSrc/src/main/groovy/SingleNativeBuild.groovy +++ b/buildSrc/src/main/groovy/SingleNativeBuild.groovy @@ -6,6 +6,8 @@ import java.nio.file.Files; import java.util.ArrayList; import java.util.List; +import org.gradle.api.tasks.Delete + import org.gradle.api.GradleException; import org.gradle.api.Plugin; import org.gradle.api.Project; @@ -87,6 +89,14 @@ class SingleNativeBuild implements Plugin { subs << component } } + Delete deleteObjects = null + if (project.hasProperty('buildServer')) { + deleteObjects = project.tasks.create('deleteObjects', Delete) + project.tasks.named('build').configure { Task t -> + t.dependsOn deleteObjects + return + } + } subs.each { ((NativeLibrarySpec) it).binaries.each { oBinary -> if (oBinary.buildable == false) { @@ -136,6 +146,10 @@ class SingleNativeBuild implements Plugin { tree.include '**/*.o' tree.include '**/*.obj' link.source tree + if (project.hasProperty('buildServer')) { + deleteObjects.dependsOn link + deleteObjects.delete tree + } } else if (binary instanceof StaticLibraryBinarySpec) { def sBinary = (StaticLibraryBinarySpec) binary ObjectFilesToBinary assemble = (ObjectFilesToBinary) sBinary.tasks.createStaticLib @@ -145,6 +159,10 @@ class SingleNativeBuild implements Plugin { tree.include '**/*.o' tree.include '**/*.obj' assemble.source tree + if (project.hasProperty('buildServer')) { + deleteObjects.dependsOn assemble + deleteObjects.delete tree + } } } } diff --git a/hal/build.gradle b/hal/build.gradle index e5b5f6cdc1..8e47a1750d 100644 --- a/hal/build.gradle +++ b/hal/build.gradle @@ -43,8 +43,6 @@ def generateUsageReporting = tasks.register('generateUsageReporting') { } } -apply plugin: DisableBuildingGTest - ext { addHalDependency = { binary, shared-> binary.tasks.withType(AbstractNativeSourceCompileTask) { diff --git a/shared/config.gradle b/shared/config.gradle index 194bde4525..8152840ea1 100644 --- a/shared/config.gradle +++ b/shared/config.gradle @@ -45,6 +45,19 @@ model { } } +apply plugin: DisableBuildingGTest + +if (project.hasProperty('buildServer')) { + tasks.withType(org.gradle.nativeplatform.test.tasks.RunTestExecutable) { + def exeFile = file(it.executable) + def folder = exeFile.parentFile + + it.doLast { + folder.deleteDir() + } + } +} + ext.appendDebugPathToBinaries = { binaries-> binaries.withType(StaticLibraryBinarySpec) { if (it.buildType.name.contains('debug')) { diff --git a/shared/jni/setupBuild.gradle b/shared/jni/setupBuild.gradle index 369422d4f3..5699ab2ed7 100644 --- a/shared/jni/setupBuild.gradle +++ b/shared/jni/setupBuild.gradle @@ -257,6 +257,15 @@ model { commandLine it.tasks.install.runScriptFile.get().asFile.toString() def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib' test.dependsOn it.tasks.install + + if (project.hasProperty('buildServer')) { + def folderDir = it.tasks.install.installDirectory.get().toString() + test.doLast { + def folder = file(folderDir) + folder.deleteDir() + } + } + test.systemProperty 'java.library.path', filePath test.environment 'LD_LIBRARY_PATH', filePath test.workingDir filePath diff --git a/wpilibNewCommands/build.gradle b/wpilibNewCommands/build.gradle index 82affa053c..adc778b495 100644 --- a/wpilibNewCommands/build.gradle +++ b/wpilibNewCommands/build.gradle @@ -43,8 +43,6 @@ nativeUtils.exportsConfigs { } } -apply plugin: DisableBuildingGTest - model { components {} binaries { diff --git a/wpilibOldCommands/build.gradle b/wpilibOldCommands/build.gradle index c8a4cb916e..9c2cb5c5ee 100644 --- a/wpilibOldCommands/build.gradle +++ b/wpilibOldCommands/build.gradle @@ -41,8 +41,6 @@ nativeUtils.exportsConfigs { } } -apply plugin: DisableBuildingGTest - model { components {} binaries { diff --git a/wpilibc/build.gradle b/wpilibc/build.gradle index ec85691c92..82a1adcce2 100644 --- a/wpilibc/build.gradle +++ b/wpilibc/build.gradle @@ -60,8 +60,6 @@ staticGtestConfigs["${nativeName}Test"] = [] apply from: "${rootDir}/shared/googletest.gradle" -apply plugin: DisableBuildingGTest - nativeUtils.exportsConfigs { wpilibc { x86ExcludeSymbols = ['_CT??_R0?AV_System_error', '_CT??_R0?AVexception', '_CT??_R0?AVfailure',