-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
217 lines (182 loc) · 6.06 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import jaci.gradle.toolchains.*
import jaci.gradle.nativedeps.*
plugins {
id 'cpp'
id 'c'
id 'edu.wpi.first.wpilib.repositories.WPILibRepositoriesPlugin' version '2020.2'
id 'edu.wpi.first.NativeUtils' version '2020.7.2'
id 'edu.wpi.first.GradleJni' version '0.10.1'
id 'edu.wpi.first.GradleVsCode' version '0.11.0'
}
apply plugin: 'jaci.gradle.EmbeddedTools'
if (project.hasProperty('releaseMode')) {
wpilibRepositories.addAllReleaseRepositories(project)
} else {
wpilibRepositories.addAllDevelopmentRepositories(project)
}
apply from: 'config.gradle'
deploy {
targets {
target('roborio') {
directory = '/home/admin'
maxChannels = 4
locations {
ssh {
address = "172.22.11.2"
user = 'admin'
password = ''
ipv6 = false
}
}
}
}
artifacts {
all {
targets << 'roborio'
postdeploy << { ctx ->
ctx.execute("sync")
ctx.execute("ldconfig")
}
}
fileArtifact('myFileArtifact') {
file = file('FPGA/FPGA Bitfiles/Generated/NiFpga_OpenSourceRIO.lvbitx') // Set the file to deploy. Required.
filename = 'NiFpga_OpenSourceRIO.lvbitx' // Set the filename to deploy to. Default: same name as file
}
nativeArtifact('testStatic') {
predeploy << { ctx ->
ctx.execute('/usr/local/frc/bin/frcKillRobot.sh -t')
}
component = 'testExe'
targetPlatform = nativeUtils.wpi.platforms.roborio
buildType = 'debug'
postdeploy << { ctx ->
ctx.execute('chmod +x testExe')
}
}
}
}
model {
components {
wpiHal(NativeLibrarySpec) {
sources {
fpga(CSourceSet) {
source {
srcDirs 'src/main/native/fpga'
srcDir 'FPGA/FPGA Bitfiles/Generated'
include '**/*.c'
}
exportedHeaders {
srcDirs 'src/main/native/fpga'
srcDir 'FPGA/FPGA Bitfiles/Generated'
}
}
c {
source {
srcDirs 'src/main/native/c'
include '**/*.c'
}
exportedHeaders {
srcDirs 'src/main/native/fpga'
srcDir 'src/main/native/include'
srcDir 'FPGA/FPGA Bitfiles/Generated'
}
}
cppShared(CppSourceSet) {
source {
srcDirs 'src/main/native/cppshared'
include '**/*.cpp'
}
exportedHeaders {
srcDirs 'src/main/native/fpga'
srcDir 'src/main/native/include'
srcDir 'FPGA/FPGA Bitfiles/Generated'
}
}
cpp {
source {
srcDirs 'src/main/native/cpp'
include '**/*.cpp'
}
exportedHeaders {
srcDirs 'src/main/native/fpga'
srcDir 'src/main/native/include'
srcDir 'FPGA/FPGA Bitfiles/Generated'
}
}
}
nativeUtils.useRequiredLibrary(it, 'hal_headers', 'wpiutil_shared', 'visa_shared')
}
testExe(NativeExecutableSpec) {
nativeUtils.excludeBinariesFromStrip(it)
sources {
c {
source {
srcDirs 'src/main/exe/c'
include '**/*.c'
}
}
}
binaries.all {
lib library: 'wpiHal', linkage: 'static'
nativeUtils.useRequiredLibrary(it, 'hal_headers', 'ntcore_static', 'wpiutil_static', 'visa_shared', 'ni_runtime_shared')
}
}
}
}
wrapper {
gradleVersion = '6.0.1'
}
def genInterface = tasks.register('runFPGACGenerator', Exec) {
workingDir file('FPGA\\FPGA Bitfiles')
inputs.file file('FPGA\\FPGA Bitfiles\\roboriofpga_OpenSourceRIO_OpenSourceRIO.lvbitx')
outputs.dir file('FPGA\\FPGA Bitfiles\\GeneratedRaw')
commandLine 'C:\\Program Files (x86)\\National Instruments\\FPGA Interface C API\\nicapigencli.exe', 'roboriofpga_OpenSourceRIO_OpenSourceRIO.lvbitx', '-e', '--outputDirectory', file('FPGA\\FPGA Bitfiles\\GeneratedRaw')
}
def patchFPGA = tasks.register('patchFPGA') {
inputs.dir file('FPGA\\FPGA Bitfiles\\GeneratedRaw')
outputs.dir file('FPGA\\FPGA Bitfiles\\Generated')
dependsOn genInterface
doLast {
def headerFileLines = file('FPGA\\FPGA Bitfiles\\GeneratedRaw\\NiFpga_OpenSourceRIO.h').readLines()
def srcFileText = file('FPGA\\FPGA Bitfiles\\GeneratedRaw\\NiFpga_OpenSourceRIO.c').text
def typedefLines = [:]
// Add static to definitons
headerFileLines.eachWithIndex { line, index ->
if (line.startsWith('const')) {
headerFileLines.set(index, "static ${line}".toString())
}
if (line.startsWith('const NiFpga_FxpTypeInfo ')) {
def key = line.split(' ')[2]
def lineArr = typedefLines.get(key)
if (lineArr != null) {
lineArr << index
} else {
lineArr = [index]
typedefLines.put(key, lineArr)
}
}
}
def removed = 0
typedefLines.each { key, value ->
if (value.size > 1) {
// Found any duplicates, remove the next 7 lines
def toRemove = (value.size - 1) * 6
def start = value.get(1) - removed
for (int i = start; i < toRemove + start ; i++) {
headerFileLines.remove(start)
removed++
}
}
}
file('FPGA\\FPGA Bitfiles\\Generated\\NiFpga_OpenSourceRIO.h').text = headerFileLines.join(System.properties.'line.separator')
file('FPGA\\FPGA Bitfiles\\Generated\\NiFpga_OpenSourceRIO.c').text = srcFileText
copy {
from 'FPGA\\FPGA Bitfiles\\GeneratedRaw\\NiFpga_OpenSourceRIO.lvbitx'
into "FPGA\\FPGA Bitfiles\\Generated"
}
}
}
tasks.register('generateFPGA') {
dependsOn genInterface
dependsOn patchFPGA
}