Files
allwpilib/wpilibc/build.gradle

270 lines
9.7 KiB
Groovy
Raw Permalink Normal View History

apply plugin: 'cpp'
apply plugin: 'c'
2018-04-29 13:29:07 -07:00
apply plugin: 'google-test-test-suite'
apply plugin: 'visual-studio'
apply plugin: 'org.wpilib.NativeUtils'
2018-04-29 13:29:07 -07:00
apply plugin: SingleNativeBuild
apply plugin: ExtraTasks
Gradle Build 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
2015-05-05 09:54:14 -04:00
2018-04-29 13:29:07 -07:00
ext {
nativeName = 'wpilibc'
}
2018-04-29 13:29:07 -07:00
apply from: "${rootDir}/shared/config.gradle"
2018-04-29 13:29:07 -07:00
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'
2018-04-29 13:29:07 -07:00
outputs.file wpilibVersionFileOutput
inputs.file wpilibVersionFileInput
if (wpilibVersioning.releaseMode) {
2018-04-29 13:29:07 -07:00
outputs.upToDateWhen { false }
}
// We follow a simple set of checks to determine whether we should generate a new version file:
2019-03-10 18:40:16 -07:00
// 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"
2018-04-29 13:29:07 -07:00
if (wpilibVersionFileOutput.exists()) {
wpilibVersionFileOutput.delete()
}
def read = wpilibVersionFileInput.text.replace('${wpilib_version}', version)
2018-04-29 13:29:07 -07:00
wpilibVersionFileOutput.write(read)
}
}
2018-04-29 13:29:07 -07:00
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 {
}
}
model {
components {
2018-04-29 13:29:07 -07:00
"${nativeName}Base"(NativeLibrarySpec) {
sources {
cpp {
source {
srcDirs = [
'src/main/native/cpp',
'src/generated/main/native/cpp'
]
2018-04-29 13:29:07 -07:00
include '**/*.cpp'
}
exportedHeaders {
srcDirs = [
'src/main/native/include',
'src/generated/main/native/include'
]
}
}
}
2018-04-29 13:29:07 -07:00
binaries.all {
if (it instanceof SharedLibraryBinarySpec) {
it.buildable = false
return
}
it.sources {
versionSources(CppSourceSet) {
source {
srcDirs = [
"${rootDir}/shared/singlelib",
"$buildDir/generated/cpp"
]
include '**/*.cpp'
}
exportedHeaders {
srcDirs 'src/main/native/include'
}
}
}
cppCompiler.define 'DYNAMIC_CAMERA_SERVER'
2022-10-08 10:01:31 -07:00
project(':ntcore').addNtcoreDependency(it, 'shared')
project(':hal').addHalDependency(it, 'shared')
lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
2018-04-29 13:29:07 -07:00
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
lib project: ':datalog', library: 'datalog', linkage: 'shared'
2018-04-29 13:29:07 -07:00
}
}
2018-04-29 13:29:07 -07:00
"${nativeName}"(NativeLibrarySpec) {
sources {
cpp {
source {
srcDirs "src/main/native/cppcs"
2018-04-29 13:29:07 -07:00
include '**/*.cpp'
}
exportedHeaders {
srcDirs 'src/main/native/include', 'src/generated/main/native/include', '../cameraserver/src/main/native/include'
2018-04-29 13:29:07 -07:00
}
}
}
binaries.all {
2022-10-08 10:01:31 -07:00
project(':ntcore').addNtcoreDependency(it, 'shared')
project(':hal').addHalDependency(it, 'shared')
lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
2018-04-29 13:29:07 -07:00
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')
}
2018-04-29 13:29:07 -07:00
}
appendDebugPathToBinaries(binaries)
}
// By default, a development executable will be generated. This is to help the case of
// testing specific functionality of the library.
2018-04-29 13:29:07 -07:00
"${nativeName}Dev"(NativeExecutableSpec) {
targetBuildTypes 'debug'
2018-04-29 13:29:07 -07:00
sources {
cpp {
source {
srcDirs 'src/dev/native/cpp'
include '**/*.cpp'
lib library: 'wpilibc'
}
exportedHeaders {
srcDirs 'src/dev/native/include'
}
}
}
2018-04-29 13:29:07 -07:00
binaries.all {
2022-10-08 10:01:31 -07:00
project(':ntcore').addNtcoreDependency(it, 'shared')
2018-04-29 13:29:07 -07:00
lib project: ':cscore', library: 'cscore', linkage: 'shared'
project(':hal').addHalDependency(it, 'shared')
lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
2018-04-29 13:29:07 -07:00
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
2018-04-29 13:29:07 -07:00
lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
nativeUtils.useRequiredLibrary(it, 'opencv_shared')
2018-04-29 13:29:07 -07:00
}
}
}
testSuites {
2018-04-29 13:29:07 -07:00
"${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'
}
}
generatedCpp(CppSourceSet) {
source {
srcDirs 'src/generated/test/native/cpp'
include '**/*.cpp'
}
exportedHeaders {
srcDirs 'src/test/native/include'
}
}
c {
source {
srcDirs 'src/test/native/c'
include '**/*.c'
}
exportedHeaders {
srcDirs 'src/test/native/include', 'src/main/native/c'
}
}
}
it.sources.each {
it.exportedHeaders {
srcDirs 'src/test/native/include'
}
}
}
}
binaries {
all {
tasks.withType(CppCompile) {
dependsOn generateCppVersion
}
}
withType(GoogleTestTestSuiteBinarySpec) {
2022-10-08 10:01:31 -07:00
project(':ntcore').addNtcoreDependency(it, 'shared')
lib project: ':cscore', library: 'cscore', linkage: 'shared'
project(':hal').addHalDependency(it, 'shared')
lib project: ':wpinet', library: 'wpinet', linkage: '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'
}
}
tasks {
2018-04-29 13:29:07 -07:00
def c = $.components
project.tasks.create('runCpp', Exec) {
def found = false
2018-04-29 13:29:07 -07:00
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
commandLine it.tasks.install.runScriptFile.get().asFile.toString()
found = true
}
}
}
}
}
}
Gradle Build 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
2015-05-05 09:54:14 -04:00
}
}
apply from: "${rootDir}/shared/cppDesktopTestTask.gradle"
apply from: 'publish.gradle'
2018-04-29 13:29:07 -07:00
def oldWpilibVersionFile = file('src/main/native/cpp/WPILibVersion.cpp')
clean {
delete oldWpilibVersionFile
}