mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
This adds gradle support for building wpilibj and wpilibc. At this point, both of these libraries should be fully ready to go. Gradle should give us a number of improvements, including less dependencies for getting building up and running, and MUCH faster build times. I'm noticing significantly faster build times already compared to Maven, with neither system building the plugins. The changes here should be pretty straight forward. The basic command for gradle is './gradlew'. This is the gradle wrapper, and it will find and download the correct gradle executable for your system. There is no need to install anything yourself. To see every task available, run './gradlew tasks'. The important tasks for us are listed under the WPILib header when the tasks command is run. To generate unit test binaries, the fRCUserProgramExecutable command will create the C++ tester, and the wpilibjIntegrationTestJar command will create the Java tester. The Jenkins deploy scripts have been modified to know the difference between maven generated and gradle generated jars with an environment variable. Creating the eclipse plugins still requires Maven, but gradle will handle calling it correctly and generating the proper dependencies for it. Create the plugins by calling ./gradlew eclipsePlugins. Jenkins can now be modified to support the new build system. Unit tests are run with ./gradlew test. Generating the integration tests uses the above two commands, and then process proceeds exactly as it did before. For publishing documentation, a new task has been created, ./gradlew publishDocs, which handles putting the documentation where Jenkins expects for publishing. Change-Id: I9a260d391984f98ef9170993efe933e4026161dc
187 lines
7.2 KiB
Groovy
187 lines
7.2 KiB
Groovy
import org.apache.tools.ant.taskdefs.condition.Os
|
|
|
|
// This regex matches either a Windows or Unix style file separator, then the lib part of the library,
|
|
// then the name of the library itself, and finally the .so extension at the end. The name of the library
|
|
// is in the libName capture group, which is extracted and used for the linker flags
|
|
def libPattern = /.*((\\/|\\).*)+lib(?<libName>.+).so$/
|
|
def niLibraryArgs = []
|
|
def wpiLibraryArgs = []
|
|
def niLibraryPath = file('ni-libraries').path
|
|
|
|
// The NI Library tree includes all non-wpi libraries, which is everything that doesn't have libwpi in the name
|
|
def niLibraryTree = fileTree(niLibraryPath)
|
|
niLibraryTree.include '*.so'
|
|
niLibraryTree.exclude '*libwpi*.so'
|
|
|
|
// This adds all linker flags to the list of ni library linker flags
|
|
niLibraryTree.each { lib ->
|
|
def nameMatcher = (lib.path =~ libPattern)
|
|
if (nameMatcher[0].size() > 1) {
|
|
def name = nameMatcher.group('libName')
|
|
niLibraryArgs << '-l' + name
|
|
}
|
|
}
|
|
|
|
// The WPI libraries are libraries in the ni-libraries folder that have libwpi in their names
|
|
def wpiLibraryTree = fileTree(niLibraryPath)
|
|
wpiLibraryTree.include '*libwpi*.so'
|
|
|
|
// This adds all linker flags to the list of wpi library linker flags
|
|
wpiLibraryTree.each { lib ->
|
|
def nameMatcher = (lib.path =~ libPattern)
|
|
if (nameMatcher[0].size() > 1) {
|
|
def name = nameMatcher[0][1]
|
|
wpiLibraryArgs << '-l' + name
|
|
}
|
|
}
|
|
|
|
// Shells out to maven for generates the eclipse plugins.
|
|
// TODO: Get gradle to build this natively, rather than relying on maven. A plugin exists to do this, called Wuff, but this needs more investigation
|
|
// https://github.com/akhikhl/wuff
|
|
task eclipsePlugins(type: Exec) {
|
|
description = 'Executes the maven build of the eclipse plugins'
|
|
group = 'WPILib'
|
|
workingDir 'eclipse-plugins'
|
|
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
executable 'mvn.bat'
|
|
} else {
|
|
executable 'mvn'
|
|
}
|
|
args 'package'
|
|
}
|
|
|
|
// Rather than a normal clean, which executes whenever the clean task is run, this must be manually invoked. This
|
|
// is because the maven processes is very verbose and takes a long time, checking all of the eclipse repositories
|
|
task cleanEclipsePlugins(type: Exec) {
|
|
description = 'Cleans the maven build of the eclipse plugins'
|
|
group = 'WPILib'
|
|
workingDir 'eclipse-plugins'
|
|
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
executable 'mvn.bat'
|
|
} else {
|
|
executable 'mvn'
|
|
}
|
|
args 'clean'
|
|
}
|
|
|
|
subprojects {
|
|
apply plugin: 'eclipse'
|
|
apply plugin: 'idea'
|
|
repositories {
|
|
mavenCentral()
|
|
mavenLocal()
|
|
}
|
|
|
|
// Disables doclint in java 8.
|
|
if (JavaVersion.current().isJava8Compatible()) {
|
|
allprojects {
|
|
tasks.withType(Javadoc) {
|
|
options.addStringOption('Xdoclint:none', '-quiet')
|
|
}
|
|
}
|
|
}
|
|
|
|
// Make sure that all maven publishing routines are run before the maven process starts
|
|
plugins.withType(MavenPublishPlugin).whenPluginAdded {
|
|
eclipsePlugins.dependsOn publishToMavenLocal
|
|
}
|
|
|
|
plugins.withType(CppPlugin).whenPluginAdded {
|
|
model {
|
|
buildTypes {
|
|
debug
|
|
}
|
|
// Adds a custom toolchain for our compiler prefix and options
|
|
toolChains {
|
|
gcc(Gcc) {
|
|
target('arm') {
|
|
// We use a custom-built cross compiler with the prefix arm-frc-linux-gnueabi-<util name>
|
|
// If this ever changes, the prefix will need to be changed here
|
|
def compilerPrefix = 'arm-frc-linux-gnueabi-'
|
|
cppCompiler.executable = compilerPrefix + cppCompiler.executable
|
|
linker.executable = compilerPrefix + linker.executable
|
|
assembler.executable = compilerPrefix + assembler.executable
|
|
// Gradle auto-adds the -m32 argument to the linker and compiler. Our compiler only supports
|
|
// arm, and doesn't understand this flag, so it is removed from both
|
|
cppCompiler.withArguments { args ->
|
|
args << '-std=c++1y' << '-Wformat=2' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic'
|
|
args << '-Wno-psabi' << '-Wno-unused-parameter' << '-fPIC' << '-O0' << '-g3' << '-rdynamic'
|
|
args.remove('-m32')
|
|
}
|
|
linker.withArguments { args ->
|
|
args << '-rdynamic'
|
|
args.remove('-m32')
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// The only platform is arm linux
|
|
platforms {
|
|
arm {
|
|
architecture 'arm'
|
|
operatingSystem 'linux'
|
|
}
|
|
}
|
|
}
|
|
|
|
// This task adds the appropriate linker flags for the NI libraries
|
|
task addNiLibraryLinks() {
|
|
description = 'Adds the linker flags for the NI libraries in the ni-library folders'
|
|
group = 'WPILib'
|
|
doLast {
|
|
binaries.all {
|
|
tasks.withType(CppCompile) {
|
|
linker.args << '-L' + niLibraryPath
|
|
linker.args.addAll(niLibraryArgs)
|
|
}
|
|
}
|
|
model {
|
|
repositories {
|
|
libs(PrebuiltLibraries) { libs ->
|
|
// Loops through all .so files (except files matching *libwpi*.so) in ../ni-libraries
|
|
// and includes them for linking
|
|
niLibraryTree.each { niLib ->
|
|
libs.create(niLib) {
|
|
binaries.withType(SharedLibraryBinary) {
|
|
sharedLibraryFile = file(niLib.path)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// This task adds the appropriate linker flags for the WPI libraries
|
|
task addWpiLibraryLinks() {
|
|
description = 'Adds the linker flags for the WPI libraries in the ni-library folders'
|
|
group = 'WPILib'
|
|
doLast {
|
|
binaries.all {
|
|
linker.args.addAll(wpiLibraryArgs)
|
|
}
|
|
model {
|
|
repositories {
|
|
libs(PrebuiltLibraries) { libs ->
|
|
// Loops through all libwpi*.so files in ../ni-libraries and includes them for linking
|
|
wpiLibraryTree.each { niLib ->
|
|
libs.create(niLib) {
|
|
binaries.withType(SharedLibraryBinary) {
|
|
sharedLibraryFile = file(niLib.path)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Whenever we add the WPI library links, we'll also need the ni libraries, so set up that dependency
|
|
addWpiLibraryLinks.dependsOn addNiLibraryLinks
|
|
}
|
|
}
|
|
|