From d48aac5beb720c4fbf8ffd59d1e2f520679a28f8 Mon Sep 17 00:00:00 2001 From: Fred Silberberg Date: Fri, 25 Nov 2016 02:44:35 -0500 Subject: [PATCH] Gradle Update (#372) This does a major cleanup on our gradle files, primarily converting all instances of manual dependency downloading to use the correct configuration-based method, which has the advantage of being both less code and more safe. --- build.gradle | 15 +- cppSettings.gradle | 214 +++++++-------------------- hal/build.gradle | 2 +- myRobot/build.gradle | 5 +- settings.gradle | 6 +- wpilibc/athena.gradle | 17 ++- wpilibc/build.gradle | 2 +- wpilibc/simulation.gradle | 2 +- wpilibj/build.gradle | 8 +- wpilibj/simulation.gradle | 4 +- wpilibjIntegrationTests/build.gradle | 4 +- 11 files changed, 89 insertions(+), 190 deletions(-) diff --git a/build.gradle b/build.gradle index ac2c7e061b..691dacfcc3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,19 +1,22 @@ plugins { id 'net.ltgt.errorprone' version '0.0.8' - id 'edu.wpi.first.wpilib.versioning.WPILibVersioningPlugin' version '1.4' + id 'edu.wpi.first.wpilib.versioning.WPILibVersioningPlugin' version '1.5.1' } -def enableSimulation = hasProperty('enableSimulation') - -if (!hasProperty('repo')) { - ext.repo = 'development' +// Ensure that the WPILibVersioningPlugin is setup by setting the release type, if releaseType wasn't +// already specified on the command line +if (!hasProperty('releaseType')) { + WPILibVersion { + releaseType = 'dev' + } } +def enableSimulation = hasProperty('makeSim') + ext.simulationInstallDir = "$rootDir/build/install/simulation" allprojects { ext.enableSimulation = enableSimulation - ext.repo = repo repositories { mavenCentral() diff --git a/cppSettings.gradle b/cppSettings.gradle index 9df3b3107a..54468dc8f0 100644 --- a/cppSettings.gradle +++ b/cppSettings.gradle @@ -2,173 +2,69 @@ def niLibraryPath = file('ni-libraries/lib').path def niLibrary = niLibraryPath + "/libnilibraries.so" -task downloadArmNetworkTables() { - description = 'Downloads the C++ ARM NetworkTables maven dependency.' - group = 'WPILib' - def depFolder = "$buildDir/dependencies" - def ntZip = file("$depFolder/ntcore-arm.zip") - outputs.file(ntZip) - def armNetTables +configurations.create('armDeps') - doFirst { - def armNtDependency = project.dependencies.create('edu.wpi.first.wpilib.networktables.cpp:NetworkTables:+:arm@zip') - def armConfig = project.configurations.detachedConfiguration(armNtDependency) - armConfig.setTransitive(false) - armNetTables = armConfig.files[0].canonicalFile - } +dependencies { + armDeps ntcoreDep('cpp', 'arm', 'zip') + armDeps wpiUtilDep('arm') + armDeps cscoreDep('cpp', 'athena-uberzip', 'zip') +} - doLast { - copy { - from armNetTables - rename 'NetworkTables(.+)', 'ntcore-arm.zip' - into depFolder - } +def depLocation = "$buildDir/dependencies" + +configurations.armDeps.files.each { file -> + def depName = file.name.substring(0, file.name.indexOf('-')) + def t = tasks.create("downloadArm${depName.capitalize()}", Copy) { + description = "Downloads and unzips the $depName dependency." + group = 'Dependencies' + from zipTree(file) + into "$depLocation/${depName.toLowerCase()}" } } -if (project.hasProperty('makeSim')) { - task downloadDesktopNetworkTables() { - description = 'Downloads the C++ Desktop NetworkTables maven dependency.' - group = 'WPILib' - def depFolder = "$buildDir/dependencies" - def ntZip = file("$depFolder/ntcore-desk.zip") - outputs.file(ntZip) - def desktopNetTables - doFirst { - def desktopNtDependency = project.dependencies.create("edu.wpi.first.wpilib.networktables.cpp:NetworkTables:+:desktop@zip") - def desktopConfig = project.configurations.detachedConfiguration(desktopNtDependency) - desktopConfig.setTransitive(false) - desktopNetTables = desktopConfig.files[0].canonicalFile - } - - doLast { - copy { - from desktopNetTables - rename 'NetworkTables(.+)', 'ntcore-desk.zip' - into depFolder - } - } - } -} - -def netTablesUnzipLocation = "$buildDir/networktables" - -// Create a task that will unzip the networktables files into a temporary build directory -task unzipNetworkTables(type: Copy) { - description = 'Unzips the networktables maven dependency so that the include files and libraries can be used' - group = 'WPILib' +task downloadNetworkTables { + description = 'Downloads all needed versions of networktables.' + group = 'Dependencies' dependsOn downloadArmNetworkTables - - if (project.hasProperty('makeSim')) { - dependsOn downloadDesktopNetworkTables - from zipTree(downloadDesktopNetworkTables.outputs.files.singleFile) - } - from zipTree(downloadArmNetworkTables.outputs.files.singleFile) - into netTablesUnzipLocation } -task downloadArmWpiUtil() { - description = 'Downloads the C++ ARM wpiutil maven dependency.' - group = 'WPILib' - def depFolder = "$buildDir/dependencies" - def utilZip = file("$depFolder/wpiutil-arm.zip") - outputs.file(utilZip) - def armWpiUtil +task downloadWpiutil { + description = 'Downloads all needed versions of WPIUtil.' + group = 'Dependencies' + dependsOn downloadArmWpiutil +} - doFirst { - def armWpiUtilDependency = project.dependencies.create("edu.wpi.first.wpilib:wpiutil:+:arm@zip") - def armWpiUtilConfig = project.configurations.detachedConfiguration(armWpiUtilDependency) - armWpiUtilConfig.setTransitive(false) - armWpiUtil = armWpiUtilConfig.files[0].canonicalFile +task downloadCscore { + description = 'Downloads all needed versions of cscore.' + group = 'Dependencies' + dependsOn downloadArmCscore +} + +if (enableSimulation) { + configurations.create('nativeDeps') + + dependencies { + nativeDeps ntcoreDep('cpp', 'desktop', 'zip') + nativeDeps wpiUtilDep('desktop') } - doLast { - copy { - from armWpiUtil - rename 'wpiutil(.+)', 'wpiutil-arm.zip' - into depFolder + configurations.nativeDeps.files.each { file -> + def depName = file.name.substring(0, file.name.indexOf('-')) + def t = tasks.create("downloadNative${depName.capitalize()}", Copy) { + description = "Downloads and unzips the $depName dependency." + group = 'Dependencies' + from zipTree(file) + into "$depLocation/${depName.toLowerCase()}" } } + + downloadNetworkTables.dependsOn downloadNativeNetworkTables + downloadWpiutil.dependsOn downloadNativeWpiutil } -if (project.hasProperty('makeSim')) { - task downloadDesktopWpiUtil() { - description = 'Downloads the C++ Desktop wpiutil maven dependency.' - group = 'WPILib' - def depFolder = "$buildDir/dependencies" - def wpiutilZip = file("$depFolder/wpiutil-desk.zip") - outputs.file(wpiutilZip) - def wpiUtil - - doFirst { - def desktopWpiUtilDependency = project.dependencies.create("edu.wpi.first.wpilib:wpiutil:+:desktop@zip") - def desktopWpiUtilConfig = project.configurations.detachedConfiguration(desktopWpiUtilDependency) - desktopWpiUtilConfig.setTransitive(false) - wpiUtil = desktopWpiUtilConfig.files[0].canonicalFile - } - - doLast { - copy { - from wpiUtil - rename 'wpiutil(.+)', 'wpiutil-desk.zip' - into depFolder - } - } - } -} - -def wpiUtilUnzipLocation = "$buildDir/wpiutil" - -// Create a task that will unzip the wpiutil files into a temporary build directory -task unzipWpiUtil(type: Copy) { - description = 'Unzips the wpiutil maven dependency so that the include files and libraries can be used' - group = 'WPILib' - dependsOn downloadArmWpiUtil - - if (project.hasProperty('makeSim')) { - dependsOn downloadDesktopWpiUtil - from zipTree(downloadDesktopWpiUtil.outputs.files.singleFile) - } - from zipTree(downloadArmWpiUtil.outputs.files.singleFile) - into wpiUtilUnzipLocation -} - -task downloadArmCsCore() { - description = 'Downloads the C++ ARM CsCore Uberzip maven dependency.' - group = 'WPILib' - def depFolder = "$buildDir/dependencies" - def csZip = file("$depFolder/cscore-arm.zip") - outputs.file(csZip) - def armCsCore - - doFirst { - def armCsDependency = project.dependencies.create('edu.wpi.cscore.cpp:cscore:+:athena-uberzip@zip') - def armConfig = project.configurations.detachedConfiguration(armCsDependency) - armConfig.setTransitive(false) - armCsCore = armConfig.files[0].canonicalFile - } - - doLast { - copy { - from armCsCore - rename 'cscore(.+)', 'cscore-arm.zip' - into depFolder - } - } -} - -def csCoreUnzipLocation = "$buildDir/cscore" - -// Create a task that will unzip the cscore files into a temporary build directory -task unzipCsCore(type: Copy) { - description = 'Unzips the cscore maven dependency so that the include files and libraries can be used' - group = 'WPILib' - dependsOn downloadArmCsCore - - from zipTree(downloadArmCsCore.outputs.files.singleFile) - into csCoreUnzipLocation -} - +def netTablesUnzipLocation = "$depLocation/networktables" +def wpiUtilUnzipLocation = "$depLocation/wpiutil" +def csCoreUnzipLocation = "$depLocation/cscore" task clean(type: Delete) { description = "Deletes the build directory" @@ -181,7 +77,7 @@ subprojects { ext.wpiUtil = wpiUtilUnzipLocation ext.wpiUtilInclude = "$wpiUtilUnzipLocation/include" ext.wpiUtilLibArmLocation = "$wpiUtilUnzipLocation/Linux/arm" - if (project.hasProperty('makeSim')) { + if (enableSimulation) { ext.wpiUtilLibDesktopLocation = "$wpiUtilUnzipLocation/Linux/amd64" } ext.wpiUtilSharedLib = "$wpiUtilLibArmLocation/libwpiutil.so" @@ -189,7 +85,7 @@ subprojects { ext.wpiUtilStaticLib = "$wpiUtilLibArmLocation/libwpiutil.a" ext.addWpiUtilLibraryLinks = { compileTask, linker, targetPlatform -> - compileTask.dependsOn project(':').unzipWpiUtil + compileTask.dependsOn project(':').downloadWpiutil String architecture = targetPlatform.architecture if (architecture.contains('arm')) { linker.args wpiUtilSharedLib @@ -197,7 +93,7 @@ subprojects { } ext.addStaticWpiUtilLibraryLinks = { compileTask, linker, targetPlatform -> - compileTask.dependsOn project(':').unzipWpiUtil + compileTask.dependsOn project(':').downloadWpiutil String architecture = targetPlatform.architecture if (architecture.contains('arm')) { linker.args wpiUtilStaticLib @@ -210,7 +106,7 @@ subprojects { ext.netTables = netTablesUnzipLocation ext.netTablesInclude = "$netTablesUnzipLocation/include" ext.netLibArmLocation = "$netTablesUnzipLocation/Linux/arm" - if (project.hasProperty('makeSim')) { + if (enableSimulation) { ext.netLibDesktopLocation = "$netTablesUnzipLocation/Linux/amd64" } ext.netSharedLib = "$netLibArmLocation/libntcore.so" @@ -218,7 +114,7 @@ subprojects { ext.netStaticLib = "$netLibArmLocation/libntcore.a" ext.addNetworkTablesLibraryLinks = { compileTask, linker, targetPlatform -> - compileTask.dependsOn project(':').unzipNetworkTables + compileTask.dependsOn project(':').downloadNetworkTables String architecture = targetPlatform.architecture if (architecture.contains('arm')) { linker.args netSharedLib @@ -227,7 +123,7 @@ subprojects { } ext.addStaticNetworkTablesLibraryLinks = { compileTask, linker, targetPlatform -> - compileTask.dependsOn project(':').unzipNetworkTables + compileTask.dependsOn project(':').downloadNetworkTables String architecture = targetPlatform.architecture if (architecture.contains('arm')) { linker.args netStaticLib @@ -245,7 +141,7 @@ subprojects { ext.cvSharedLib = "$csLibArmLocation/libopencv.so" ext.addCsCoreLibraryLinks = { compileTask, linker, targetPlatform -> - compileTask.dependsOn project(':').unzipCsCore + compileTask.dependsOn project(':').downloadCscore String architecture = targetPlatform.architecture if (architecture.contains('arm')) { linker.args << '-L' + csLibArmLocation diff --git a/hal/build.gradle b/hal/build.gradle index dbe93510ec..3300e5f4da 100644 --- a/hal/build.gradle +++ b/hal/build.gradle @@ -111,7 +111,7 @@ task athenaRuntimeZip(type: Zip) { } defineNetworkTablesProperties() - dependsOn project(':').unzipNetworkTables + dependsOn project(':').downloadNetworkTables from(project.file(netTablesInclude)) { into 'include' diff --git a/myRobot/build.gradle b/myRobot/build.gradle index e9da55055c..cb282902d8 100644 --- a/myRobot/build.gradle +++ b/myRobot/build.gradle @@ -18,9 +18,8 @@ def wpilibj = project(':wpilibj') dependencies { compile wpilibj compile files(wpilibj.sourceSets.test.output.classesDir) - compile 'edu.wpi.first.wpilib.networktables.java:NetworkTables:+:arm' - compile 'edu.wpi.first.wpilib.networktables.java:NetworkTables:+:arm' - compile 'edu.wpi.cscore.java:cscore:+:arm' + compile ntcoreDep('java', 'arm') + compile cscoreDep('java', 'arm') compile 'org.opencv:opencv-java:+' } diff --git a/settings.gradle b/settings.gradle index b92a97b0d2..ef54d0112b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -7,7 +7,7 @@ include 'hal', 'myRobotCpp' if (hasProperty("makeSim")){ -include 'simulation', - 'simulation:JavaGazebo', - 'simulation:SimDS' + include 'simulation', + 'simulation:JavaGazebo', + 'simulation:SimDS' } diff --git a/wpilibc/athena.gradle b/wpilibc/athena.gradle index 78df122a3d..1aaa7521e5 100644 --- a/wpilibc/athena.gradle +++ b/wpilibc/athena.gradle @@ -76,16 +76,17 @@ task wpilibcZip(type: Zip) { } if (checkDoxygen()) { - - def ntSourcesDependency = project.dependencies.create('edu.wpi.first.wpilib.networktables.cpp:NetworkTables:+:sources@zip') - def ntSourcesConfig = project.configurations.detachedConfiguration(ntSourcesDependency) - ntSourcesDependency.setTransitive(false) - def ntSources = ntSourcesConfig.singleFile + configurations.create('doc') + dependencies { + doc ntcoreDep('cpp', 'sources', 'zip') + } task unzipCppNtSources(type: Copy) { - description = 'Unzips the C++ networktables sources for doc creation' - group = 'WPILib' - from zipTree(ntSources) + description = 'Unzips the C++ networktables sources for doc creation.' + group = 'Dependencies' + configurations.doc.files.each { + from zipTree(it) + } exclude 'META-INF/*' into ntSourceDir } diff --git a/wpilibc/build.gradle b/wpilibc/build.gradle index 9fa2fa3928..981de4449a 100644 --- a/wpilibc/build.gradle +++ b/wpilibc/build.gradle @@ -65,6 +65,6 @@ ext.checkDoxygen = { apply from: 'athena.gradle' -if (hasProperty('makeSim')){ +if (enableSimulation){ apply from: 'simulation.gradle' } diff --git a/wpilibc/simulation.gradle b/wpilibc/simulation.gradle index fffda15f14..2bc2c4f62c 100644 --- a/wpilibc/simulation.gradle +++ b/wpilibc/simulation.gradle @@ -54,7 +54,7 @@ task gz_msgs(type: Exec, dependsOn: cmake) { } } -task wpilibcSim(type: Exec, dependsOn: ['cmake', ':unzipNetworkTables', ':unzipWpiUtil', 'generateCppVersion']) { +task wpilibcSim(type: Exec, dependsOn: ['cmake', ':downloadNetworkTables', ':downloadWpiutil', 'generateCppVersion']) { description = 'build WPILib C++ for simulation with cmake' group = 'WPILib Simulation' workingDir '../build' diff --git a/wpilibj/build.gradle b/wpilibj/build.gradle index 0257129d10..5b8257a5f7 100644 --- a/wpilibj/build.gradle +++ b/wpilibj/build.gradle @@ -59,18 +59,18 @@ sourceSets { compileSharedJava.dependsOn generateJavaVersion dependencies { - sharedCompile 'edu.wpi.first.wpilib.networktables.java:NetworkTables:+:arm' - sharedRuntime 'edu.wpi.first.wpilib.networktables.java:NetworkTables:+:arm' + sharedCompile ntcoreDep('java', 'arm') + sharedRuntime ntcoreDep('java', 'arm') testCompile 'org.hamcrest:hamcrest-all:1.3' testCompile 'junit:junit:4.12' - testCompile 'edu.wpi.first.wpilib.networktables.java:NetworkTables:+:desktop' + testCompile ntcoreDep('java', 'desktop') testCompile 'com.google.guava:guava:19.0' testCompile sourceSets.shared.output } apply from: 'athena.gradle' -if (project.hasProperty('makeSim')) { +if (enableSimulation) { apply from: 'simulation.gradle' } diff --git a/wpilibj/simulation.gradle b/wpilibj/simulation.gradle index 275c71b88d..79dbbf586a 100644 --- a/wpilibj/simulation.gradle +++ b/wpilibj/simulation.gradle @@ -5,8 +5,8 @@ sourceSets { dependencies { simCompile sourceSets.shared.output simCompile project(':simulation:JavaGazebo') - simCompile 'edu.wpi.first.wpilib.networktables.java:NetworkTables:+:desktop' - simRuntime "edu.wpi.first.wpilib.networktables.java:NetworkTables:+:desktop" + simCompile ntcoreDep('java', 'desktop') + simRuntime ntcoreDep('java', 'desktop') } task wpilibjSimJar(type: Jar, dependsOn: simClasses) { diff --git a/wpilibjIntegrationTests/build.gradle b/wpilibjIntegrationTests/build.gradle index 4688697f5c..bfe5dffe3f 100644 --- a/wpilibjIntegrationTests/build.gradle +++ b/wpilibjIntegrationTests/build.gradle @@ -18,8 +18,8 @@ def wpilibj = project(':wpilibj') dependencies { compile wpilibj compile files(wpilibj.sourceSets.test.output.classesDir) - compile 'edu.wpi.first.wpilib.networktables.java:NetworkTables:+:arm' - compile 'edu.wpi.cscore.java:cscore:+:arm' + compile ntcoreDep('java', 'arm') + compile cscoreDep('java', 'arm') compile 'org.opencv:opencv-java:+' compile 'junit:junit:4.11' compile 'com.googlecode.junit-toolbox:junit-toolbox:2.0'