Skip to content

Commit

Permalink
Add support for running glass from gradle (#470)
Browse files Browse the repository at this point in the history
* Add support for running glass from gradle

Currently does not support installing. Needed to enable support for installing glass in the installer

* Handle new cpp flag in tool json

* Actually do something...

* Fix glass classifier
  • Loading branch information
ThadHouse authored Dec 11, 2020
1 parent 0520221 commit a169ed4
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/cpp/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id "cpp"
id "google-test-test-suite"
id "edu.wpi.first.GradleRIO" version "2021.1.1-alpha-1"
id "edu.wpi.first.GradleRIO" version "2021.1.1-beta-3"
}

// Define my targets (RoboRIO) and artifacts (deployable files)
Expand Down
2 changes: 1 addition & 1 deletion examples/java/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "java"
id "edu.wpi.first.GradleRIO" version "2021.1.1-alpha-1"
id "edu.wpi.first.GradleRIO" version "2021.1.1-beta-3"
}

sourceCompatibility = JavaVersion.VERSION_11
Expand Down
2 changes: 1 addition & 1 deletion examples/jni/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id "java"
id "cpp"
id "edu.wpi.first.GradleRIO" version "2021.1.1-alpha-1"
id "edu.wpi.first.GradleRIO" version "2021.1.1-beta-3"
id 'edu.wpi.first.GradleJni' version '0.10.1'
}

Expand Down
2 changes: 1 addition & 1 deletion examples/kotlin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "org.jetbrains.kotlin.jvm" version "1.3.50"
id "edu.wpi.first.GradleRIO" version "2021.1.1-alpha-1"
id "edu.wpi.first.GradleRIO" version "2021.1.1-beta-3"
}

def ROBOT_MAIN_CLASS = "frc.team0000.robot.MainKt"
Expand Down
13 changes: 13 additions & 0 deletions src/main/groovy/edu/wpi/first/gradlerio/wpi/WPIExtension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class WPIExtension {
String outlineViewerVersion = "2021.1.1-beta-2"
String robotBuilderVersion = "2021.1.1-beta-3"
String pathWeaverVersion = "2021.1.1-beta-2"
String glassVersion = "2021.1.1-beta-3"

WPIMavenExtension maven
WPIDepsExtension deps
Expand All @@ -45,6 +46,7 @@ class WPIExtension {

final Project project
final String toolsClassifier
final String cppToolsClassifier

NativeUtilsExtension ntExt;

Expand All @@ -65,6 +67,17 @@ class WPIExtension {
null
)
}
if (project.hasProperty('forceCppToolsClassifier')) {
this.cppToolsClassifier = project.findProperty('forceCppToolsClassifier')
} else {
this.cppToolsClassifier = (
OperatingSystem.current().isWindows() ?
System.getProperty("os.arch") == 'amd64' ? 'windowsx86-64' : 'windowsx86' :
OperatingSystem.current().isMacOsX() ? "osxx86-64" :
OperatingSystem.current().isLinux() ? "linuxx86-64" :
null
)
}

platforms = new NativePlatforms();
deps = factory.newInstance(WPIDepsExtension, project, this)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package edu.wpi.first.gradlerio.wpi.dependencies.tools

import edu.wpi.first.gradlerio.SingletonTask
import groovy.transform.CompileStatic
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.TaskProvider
import org.gradle.internal.os.OperatingSystem
import org.gradle.process.ExecSpec

import javax.inject.Inject

@CompileStatic
class CppToolRunTask extends DefaultTask implements SingletonTask {
@Internal
String toolName

@Inject
CppToolRunTask(String name) {
group = 'GradleRIO'
description = "Run the tool $name"

this.toolName = name
}

@TaskAction
void runTool() {
def isWindows = OperatingSystem.current().isWindows()
if (isWindows) {
runToolWindows()
} else {
runToolUnix()
}
}

void runToolWindows() {
def outputFile = new File(ToolInstallTask.toolsFolder, toolName + '.vbs')
ProcessBuilder builder = new ProcessBuilder('wscript.exe', outputFile.absolutePath, 'silent')
Process proc = builder.start()
int result = proc.waitFor()
if (result != 0) {
def stdOut = proc.getInputStream().text;
def stdErr = proc.getErrorStream().text;
throw new ToolRunException(stdOut, stdErr)
}
}

void runToolUnix() {
def outputFile = new File(ToolInstallTask.toolsFolder, toolName + '.py')
project.exec { ExecSpec spec ->
spec.executable = outputFile.absolutePath
}
}

@Override
String singletonName() {
return toolName
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ToolInstallTask extends DefaultTask {
private static class ToolJson {
String name
String version
Boolean cpp
}

@Inject
Expand Down Expand Up @@ -129,6 +130,7 @@ class ToolInstallTask extends DefaultTask {
def toolJson = new ToolJson()
toolJson.name = toolName
toolJson.version = dependency.version
toolJson.cpp = false
setToolVersion(toolJson)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ class ToolRunTask extends DefaultTask implements SingletonTask {
description = "Run the tool $name"

this.toolName = name
this.installTask = installTask
dependsOn(installTask)
if (installTask != null) {
this.installTask = installTask
dependsOn(installTask)
}
}

@TaskAction
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package edu.wpi.first.gradlerio.wpi.dependencies.tools

import edu.wpi.first.gradlerio.wpi.WPIExtension
import groovy.transform.CompileStatic
import org.gradle.api.Project
import org.gradle.api.tasks.TaskProvider

@CompileStatic
class WPICppTool {
//TaskProvider<CppToolInstallTask> toolInstallTask
TaskProvider<CppToolRunTask> toolRunTask

String name

String version

WPICppTool(Project project, String name, String version, String artifactId) {
def config = project.configurations.getByName('wpiCppTools')
String toolsClassifier = project.extensions.getByType(WPIExtension).cppToolsClassifier
artifactId += ":${toolsClassifier}@zip"
def dependency = project.dependencies.add("wpiCppTools", artifactId)
//toolInstallTask = project.tasks.register("${name}Install".toString(), CppToolInstallTask, name, config, dependency)
toolRunTask = project.tasks.register(name, CppToolRunTask, name)
this.name = name
this.version = version
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ class WPIToolsPlugin implements Plugin<Project> {
@Override
void apply(Project project) {
project.configurations.maybeCreate("wpiTools")
project.configurations.maybeCreate("wpiCppTools")

def wpi = project.extensions.getByType(WPIExtension)
project.afterEvaluate {
List<WPITool> tools = []
List<WPICppTool> cppTools = []

def frcHome = wpi.frcHome
String toolFolder = new File(frcHome, 'tools').toString()
Expand All @@ -26,6 +28,7 @@ class WPIToolsPlugin implements Plugin<Project> {
tools << new WPITool(project, "OutlineViewer", wpi.outlineViewerVersion, "edu.wpi.first.tools:OutlineViewer:${wpi.outlineViewerVersion}", true)
tools << new WPITool(project, "RobotBuilder", wpi.robotBuilderVersion, "edu.wpi.first.tools:RobotBuilder:${wpi.robotBuilderVersion}", false)
tools << new WPITool(project, "PathWeaver", wpi.pathWeaverVersion, "edu.wpi.first.tools:PathWeaver:${wpi.pathWeaverVersion}", true)
cppTools << new WPICppTool(project, "Glass", wpi.glassVersion, "edu.wpi.first.tools:Glass:${wpi.glassVersion}")

project.tasks.register("InstallAllTools") { Task task->
task.group = 'GradleRIO'
Expand Down
1 change: 1 addition & 0 deletions versionupdates.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def versionMap = [
robotBuilderVersion: 'edu.wpi.first.tools:RobotBuilder:+',
shuffleboardVersion: 'edu.wpi.first.shuffleboard:shuffleboard:+:win64',
pathWeaverVersion: 'edu.wpi.first.tools:PathWeaver:+:win64',
glassVersion: 'edu.wpi.first.tools:Glass:+:windowsx86-64@zip',
opencvVersion: 'edu.wpi.first.thirdparty.frc2021.opencv:opencv-java:+',
googleTestVersion: 'edu.wpi.first.thirdparty.frc2021:googletest:+:headers',
niLibrariesVersion: 'edu.wpi.first.ni-libraries:chipobject:+:headers',
Expand Down

0 comments on commit a169ed4

Please sign in to comment.