-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
150 lines (136 loc) · 6.04 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
plugins {
// Adds empty build, clean, and assemble tasks to project
id 'base'
// Simple way to push apps to raspberry pi
// Big shout out to https://github.com/int128/gradle-ssh-plugin
// for enabling interaction to remote system over ssh using gradle. Nice!
id 'org.hidetake.ssh' version '2.9.0'
}
allprojects {
// NOTE: If you do a build on Windows targeting another architecture, tests
// will (naturally) fail. Therefore, you can do:
// gradlew build -x test -Ptarget="arm-raspbian"
// If development of Windows and targeting windows, simply do:
// gradlew build
// valid targets = windows (default), arm-raspbian, armhf
// Also note that the python apps build source distributions only, so
// it does not matter which target is selected for those. 'pip install'
// will work appropriately regardless of the target platform.
ext.buildType = project.hasProperty('target') ? project.property('target') : 'windows'
}
def binDirectory = file("${rootDir}/bin")
def scriptsDirectory = "${rootDir}/scripts"
def pythonDirectory = "${binDirectory}/python"
remotes {
piccb {
host = 'visioncoproc.local'
user = 'pi'
password = 'raspberry'
}
}
ssh.settings {
knownHosts = allowAnyHosts
fileTransfer = 'scp'
}
// Normally this is implicit with java plugin, but base plugin makes no sub-project assumptions
build.dependsOn ':CameraServer:pydist', ':CameraVision:build', ':NTSimulator:pydist'
task copyStartupScript(type: Copy) {
description "Copies the startup application to the root bin directory."
destinationDir = binDirectory
if (buildType == "windows") {
from (file("${scriptsDirectory}/startup.bat")) {
}
from (file("${scriptsDirectory}/local-debug-startup.bat")) {
}
} else {
from (file("${scriptsDirectory}/startup.sh")) {
}
from (file("${scriptsDirectory}/startup-debug.sh")) {
}
from (file("${scriptsDirectory}/local-debug-startup.sh")) {
}
}
}
task buildPythonVirtualEnvironment(type: Exec) {
// Assumption: venv is installed...which it is for the binary msi version of Python I got for Windows
description "Creates a virtual python environment in the root bin directory."
outputs.dir "${pythonDirectory}"
commandLine "python3", "-m", "venv", "--clear", "${pythonDirectory}"
}
task installIPCameraApp(type: Exec) {
dependsOn ':CameraServer:pydist'
commandLine "${pythonDirectory}/bin/pip", "install", "--upgrade", "--find-links", "file://${rootProject.projectDir}/CameraServer/build/python/dist", "ipcamera"
doLast {
copy {
into binDirectory
if (buildType == "windows") {
from(file("./CameraServer/stream-camera.bat"))
} else {
from(file("./CameraServer/stream-camera.sh"))
from(file("./CameraServer/set-camera.sh"))
}
}
}
}
task installNTServerApp(type: Exec) {
dependsOn ':NTSimulator:pydist'
commandLine "${pythonDirectory}/bin/pip", "install", "--upgrade", "--find-links", "file://${rootProject.projectDir}/NTSimulator/build/python/dist", "ntserver"
}
task installVisionApp(type: Copy) {
dependsOn ':CameraVision:build'
from zipTree("${rootProject.projectDir}/CameraVision/build/distributions/CameraVision-all.zip")
into binDirectory
}
build.dependsOn copyStartupScript
build.dependsOn buildPythonVirtualEnvironment
build.dependsOn installIPCameraApp
build.dependsOn installNTServerApp
build.dependsOn installVisionApp
clean {
inputs.dir binDirectory
description "Remove the root bin directory."
delete binDirectory
}
// Make the deploy task accept a parameter that will tell below which remote
// to deploy to.
task deploy(dependsOn: build) {
doLast {
if (buildType == "windows") {
println "Windows deployment not coded at this time. You can run locally at ${binDirectory}"
} else {
ssh.run {
session(remotes.piccb) {
// Install dependencies
// This should bring up this project from a fresh raspbian install.
// You must have ssh installed first using `sudo raspi-config`.
// Will this work on the robo-rio?
// Doubt it...don't know...must test.
try {
// this little trick will quickly determine if we are connected
// to the internet and will throw an error if not
execute 'nc -z 8.8.8.8 53'
executeSudo 'apt-get --assume-yes update'
executeSudo 'apt-get --assume-yes install dos2unix'
executeSudo 'apt-get --assume-yes install python3'
executeSudo 'apt-get --assume-yes install python3-pip'
executeSudo 'apt-get --assume-yes install oracle-java8-jdk'
executeSudo 'apt-get --assume-yes install libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools'
} catch (Exception e)
{
println "Could not install dependencies. Connected to Internet?"
}
// Now copy the build
execute 'mkdir -p /home/pi/bin'
execute 'mkdir -p /home/pi/sw'
put from: fileTree(binDirectory).matching { exclude 'python/**'}, into: '/home/pi/bin'
put from: fileTree(dir: "${rootProject.projectDir}/CameraServer/build/python/dist"), into: '/home/pi/sw'
put from: fileTree(dir: "${rootProject.projectDir}/NTSimulator/build/python/dist"), into: '/home/pi/sw'
// Install the build
execute 'pip3 install -U --find-links file:///home/pi/sw ntserver ipcamera'
execute 'chmod u+x /home/pi/bin/*.sh'
execute 'dos2unix /home/pi/bin/*.sh'
}
}
}
}
}