Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shorter aliases for C++ sim #492

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package edu.wpi.first.gradlerio.test

import edu.wpi.first.gradlerio.ExternalLaunchTask
import edu.wpi.first.gradlerio.test.TestPlugin
import groovy.transform.CompileStatic
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction
import org.gradle.nativeplatform.NativeExecutableBinarySpec
import org.gradle.nativeplatform.tasks.InstallExecutable

@CompileStatic
class NativeBinarySimulationTask extends ExternalLaunchTask {
@Internal
NativeExecutableBinarySpec binary

@TaskAction
void run() {
def installTask = binary.tasks.withType(InstallExecutable).first()
def dir = new File(installTask.installDirectory.asFile.get(), "lib")

environment.putAll(TestPlugin.getSimLaunchEnv(project, dir.absolutePath))

workingDir = dir
launch("\"${installTask.runScriptFile.get().asFile.absolutePath}\"")
}

}
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
package edu.wpi.first.gradlerio.test

import edu.wpi.first.gradlerio.ExternalLaunchTask
import edu.wpi.first.gradlerio.test.TestPlugin
import edu.wpi.first.gradlerio.wpi.simulation.SimulationExtension
import groovy.transform.CompileStatic
import org.gradle.api.DefaultTask
import org.gradle.api.Task
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction
import org.gradle.nativeplatform.NativeExecutableBinarySpec
import org.gradle.nativeplatform.tasks.InstallExecutable

@CompileStatic
class NativeSimulationTask extends ExternalLaunchTask {
@Internal
NativeExecutableBinarySpec binary

@TaskAction
void run() {
def installTask = binary.tasks.withType(InstallExecutable).first()
def dir = new File(installTask.installDirectory.asFile.get(), "lib")

environment.putAll(TestPlugin.getSimLaunchEnv(project, dir.absolutePath))

workingDir = dir
launch("\"${installTask.runScriptFile.get().asFile.absolutePath}\"")
class NativeSimulationTask extends DefaultTask {
void validate(List<String> binaryTasks) {
def simTask = project.extensions.getByType(SimulationExtension).cppSimTask
if (simTask != "") {
this.dependsOn(simTask)
return
}
if (binaryTasks.size() == 0) {
logger.error("No Binary Simulation tasks found.");
} else if (binaryTasks.size() == 1) {
this.dependsOn(binaryTasks.first())
} else {
logger.error("More than one binary simulation task was found.")
logger.error("Please set the `cppSimTask` variable in the `sim` block in your `build.gradle`.")
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ import org.gradle.model.ModelMap
import org.gradle.model.Mutate
import org.gradle.model.RuleSource
import org.gradle.model.Validate
import org.gradle.nativeplatform.NativeComponentSpec
import org.gradle.nativeplatform.NativeExecutableBinarySpec
import org.gradle.nativeplatform.NativeExecutableSpec
import org.gradle.nativeplatform.tasks.InstallExecutable
import org.gradle.nativeplatform.test.NativeTestSuiteBinarySpec
import org.gradle.nativeplatform.test.NativeTestSuiteSpec
import org.gradle.nativeplatform.test.googletest.GoogleTestTestSuiteBinarySpec
import org.gradle.platform.base.BinaryContainer
import org.gradle.platform.base.ComponentSpecContainer
Expand Down Expand Up @@ -66,19 +64,30 @@ class NativeTestPlugin implements Plugin<Project> {

@Mutate
void addSimulationTasks(ModelMap<Task> tasks, ComponentSpecContainer components) {
List<String> nativeSimTasks = new ArrayList<String>()
components.withType(NativeExecutableSpec).each { NativeExecutableSpec component ->
component.binaries.withType(NativeExecutableBinarySpec).each { NativeExecutableBinarySpec bin ->
if (bin.targetPlatform.operatingSystem.current && !bin.targetPlatform.name.equals(NativePlatforms.roborio)) {
def name = "simulate${((BinarySpecInternal) bin).getProjectScopedName().capitalize()}".toString()
tasks.create(name, NativeSimulationTask, { NativeSimulationTask task ->
if (name.contains("Debug")) { // TODO: when removing hardcoding simulation to debug, deal with this
nativeSimTasks.add(name)
}
tasks.create(name, NativeBinarySimulationTask, { NativeBinarySimulationTask task ->
task.group = "GradleRIO"
task.description = "Launch simulation for native component ${component.name}"
task.binary = bin
task.dependsOn(bin.tasks.install)
} as Action<NativeSimulationTask>)

} as Action<NativeBinarySimulationTask>)
System.err.println("abc, ${name}, ${nativeSimTasks.size()}")
}
}
tasks.create("simulateCpp", NativeSimulationTask) {
it.group = "GradleRIO"
it.validate(nativeSimTasks)
}
}
System.err.println("def, ${nativeSimTasks.size()}")
}

@Validate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.gradle.api.NamedDomainObjectContainer
@CompileStatic
class SimulationExtension {
Map<String, String> environment = [:]
String cppSimTask = ""

void envVar(String name, String value) {
environment[name] = value
Expand Down