-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
381 lines (324 loc) · 11.5 KB
/
build.gradle
File metadata and controls
381 lines (324 loc) · 11.5 KB
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
plugins {
id 'application'
id 'jacoco'
id 'org.ajoberstar.grgit' version '4.1.1'
id 'org.graalvm.buildtools.native' version '0.10.6'
}
// TODO TEST DEPS TypeGeneratorTest has a hard coded list of jars it uses for tests
// Need to figure out a better way
// TODO TEST add a test that starts the SDK in a docker container and checks some simple cmds
// EDIT - run against the kb-sdk+ binary
group = 'us.kbase.sdk'
repositories {
mavenCentral()
maven { // for syslog4j
name = 'Clojars'
url = 'https://repo.clojars.org/'
}
maven {
name = 'Jitpack'
url = 'https://jitpack.io'
}
}
application {
mainClass = 'us.kbase.sdk.ModuleBuilder'
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
task buildGitCommitFile {
doLast {
def commitId = grgit.head().id
// is there a variable for builddir/classes/java/main?
file("$buildDir/classes/java/main/us/kbase/sdk/gitcommit").text = commitId
}
}
compileJava {
// tell annotation processors the project name to avoid name collisions
options.compilerArgs += ["-Aproject=${project.group}/${project.name}"]
options.release = 17
finalizedBy buildGitCommitFile
}
task kb_sdk_plusScript {
// creates a kb-sdk script based on the jars in their default locations
dependsOn jar
doLast {
def dependencies = sourceSets.main.runtimeClasspath.collect { File file ->
file.absolutePath
}
def buildjar = "$buildDir/libs/${project.name}.jar"
def classpath = buildjar + ':' + dependencies.join(':')
def scriptContent = """#!/bin/sh
CLASSPATH=$classpath
java -cp \$CLASSPATH us.kbase.sdk.ModuleBuilder \$@
"""
def outfile = "$buildDir/kb-sdk"
file(outfile).text = scriptContent
file(outfile).setExecutable(true)
}
}
task prepareRunnableDir {
// like kb_sdk_plusScript but localizes all the jars and the script
// into a directory for easy copying
// Note requires bash vs just sh
dependsOn jar
def runnableDir = file("$buildDir/runnable")
def runnerScript = new File(runnableDir, 'kb-sdk')
doFirst {
// Clean and recreate runnable dir
delete runnableDir
mkdir runnableDir
// Copy all runtime jars
sourceSets.main.runtimeClasspath.each { File dep ->
copy {
from dep
into runnableDir
}
}
// Copy the project's jar
def jarFile = file("$buildDir/libs/${project.name}.jar")
copy {
from jarFile
into runnableDir
}
// Write the runner script
runnerScript.text = """#!/bin/bash
SCRIPT_DIR="\$(cd "\$(dirname "\${BASH_SOURCE[0]}")" && pwd)"
CLASSPATH="\$(ls \$SCRIPT_DIR/*.jar | tr '\\n' ':')"
java -cp \$CLASSPATH us.kbase.sdk.ModuleBuilder \$@
"""
runnerScript.setExecutable(true)
}
}
// this is used in TypeGeneratorTest to supply dependencies for compiler tests
def genCodeLibDir = file("$buildDir/generated-code-libs")
task resolveGeneratedCodeDeps {
inputs.files { configurations.generatedCodeClasspath }
outputs.dir genCodeLibDir
doLast {
delete genCodeLibDir
copy {
from configurations.generatedCodeClasspath
into genCodeLibDir
}
}
}
test {
dependsOn resolveGeneratedCodeDeps
dependsOn kb_sdk_plusScript // tests use script to compile sdk modules
useJUnitPlatform()
testLogging {
exceptionFormat = 'full'
showStandardStreams = true
}
finalizedBy jacocoTestReport
}
jacocoTestReport {
reports {
xml.required = true
csv.required = true
}
}
// TODO BUILD the other script tasks could possibly be made simpler with some of the
// variables in this task
tasks.register('generateNativeAgentScript') {
description = """
Generates a script to run the application with the GraalVM native-image-agent.
Will init and test an SDK app called 'testapp', so run this in a location where
creating that directory is safe.
"""
group = 'native-image'
dependsOn jar
doLast {
def scriptFile = file("${buildDir}/run-native-agent.sh")
def classpath = sourceSets.main.runtimeClasspath.asPath
def mainClass = application.mainClass.get()
scriptFile.text = """#!/bin/bash
set -euo pipefail
if [ "\$#" -lt 2 ]; then
echo "Usage: \$0 <output-config-dir> <KBase CI token>"
exit 1
fi
OUTDIR="\$(realpath "\$1")"
TOKEN="\$2"
COMMON_OPTS="-agentlib:native-image-agent=experimental-class-loader-support=tracer,config-output-dir=\$OUTDIR"
CP="${classpath}"
echo "Running application with native-image-agent output to: \$OUTDIR"
echo
echo "*** Running init command ***"
java \$COMMON_OPTS/init -cp "\$CP" ${mainClass} init \\
-u userhere \\
-l java \\
testapp
cd testapp
# set up the test config
sed -i "s#^test_token=.*#test_token=\$TOKEN#" test_local/test.cfg
sed -i "s#appdev\\.kbase\\.us*#ci\\.kbase\\.us#" test_local/test.cfg
echo "*** Running compile command ***"
# py compilation runs different code paths so we do both
java \$COMMON_OPTS/compile -cp "\$CP" ${mainClass} compile \\
testapp.spec \\
--out lib \\
--pyclname testappClient \\
--pysrvname testappServer \\
--pyimplname testappImpl \\
--javasrc src \\
--java \\
--javasrv \\
--javapackage .
echo
echo "*** Running test command ***"
java \$COMMON_OPTS/test -cp "\$CP" ${mainClass} test
echo
echo "*** Running prepare_deploy_cfg command ***"
echo "[global]" > conf.props
java \$COMMON_OPTS/prep -cp "\$CP" ${mainClass} _internal prepare_deploy_cfg deploy.cfg conf.props
# comes with GraalVM 17
native-image-configure generate \\
--output-dir=\$OUTDIR/merged \\
--input-dir=\$OUTDIR/init \\
--input-dir=\$OUTDIR/compile \\
--input-dir=\$OUTDIR/test \\
--input-dir=\$OUTDIR/prep
echo
echo "Done. NOTE: Inspect the merged output carefully; the agent is better"
echo "than starting from scratch but is imperfect."
echo "When merging into src/main/resources/META-INF/native-image carefully"
echo "check that:"
echo ""
echo " * all, not just specific resources from this repo are included in the"
echo " configuration files"
echo " * test classes are not included (e.g. KBaseReport)"
echo " * Narrative method store objects have all methods, constructors, and "
echo " fields included"
echo ""
echo "Edit manually if necessary."
"""
scriptFile.setExecutable(true)
println "Generated script at: ${scriptFile.absolutePath}"
}
}
graalvmNative {
binaries {
named('main') {
imageName.set('kb-sdk')
// Don't fall back to a jar based build
buildArgs.addAll([
'--no-fallback',
'--enable-url-protocols=https,http',
'-H:+AddAllCharsets'
])
def arch = System.getProperty("os.arch")
println "Detected architecture: ${arch}"
if (arch == "x86_64" || arch == "amd64") {
println "Adding -march=x86-64-v2 to build args"
// the KBase CI catalog service hardware is oooooold
// TODO KBASE_HW remove this stuff if we ever get modern HW
buildArgs.add("-march=x86-64-v2")
} else {
println "Skipping -march option for architecture: ${arch}"
}
}
}
}
configurations {
// can't directly access testImplementation, so extend and access
testimpl.extendsFrom testImplementation
// isolate the sdk generated code dependencies from the standard dependencies
generatedCodeClasspath
}
configurations.all {
// not sure why, but couldn't get an exclusion on the auth2 client to work, which
// was upgrading slf4j and breaking tests
resolutionStrategy {
force 'org.slf4j:slf4j-api:1.7.7'
}
}
dependencies {
// required for GraalVM native compilation
annotationProcessor('info.picocli:picocli-codegen:4.7.7')
compileOnly('javax.servlet:servlet-api:2.5')
implementation('com.github.kbase:auth2_client_java:0.5.0') {
exclude group: 'com.fasterxml.jackson.core' // don't upgrade yet, breaks tests
}
implementation('com.github.kbase:catalog:2.3.1') {
exclude group: 'com.github.kbase', module: 'java_common'
exclude group: 'com.fasterxml.jackson.core' // don't upgrade yet, breaks tests
}
implementation('com.github.kbase:java_common:0.3.1') {
exclude group: 'com.fasterxml.jackson.core' // don't upgrade yet, breaks tests
exclude group: 'net.java.dev.jna' // don't include in runtime path
exclude group: 'org.eclipse.jetty.aggregate' // don't include in runtime path
exclude group: 'org.syslog4j', module: 'syslog4j'
}
implementation('com.github.kbase:java_kidl:0.2.0')
implementation('com.github.kbase:narrative_method_store:v0.3.13') {
exclude group: 'com.github.kbase', module: 'java_common'
exclude group: 'com.fasterxml.jackson.core' // don't upgrade yet, breaks tests
// TODO DEPS fix these in NMS
exclude group: 'org.mongodb'
exclude group: 'org.eclipse.jetty.aggregate' // don't include in runtime path
}
implementation('com.fasterxml.jackson.core:jackson-annotations:2.2.3')
implementation('com.fasterxml.jackson.core:jackson-databind:2.2.3')
implementation('com.google.guava:guava:18.0')
implementation('com.googlecode.jsonschema2pojo:jsonschema2pojo-core:0.3.6')
implementation('com.j2html:j2html:0.7') {
exclude group: 'junit', module: 'junit' // bro
}
implementation('commons-io:commons-io:2.4')
implementation('info.picocli:picocli:4.7.7')
// TODO DEPS the annotation api is needed for
// a couple of SDK compiled classes in mobu/runner that should be factored out
implementation('javax.annotation:javax.annotation-api:1.3.2')
implementation('org.apache.commons:commons-lang3:3.1')
implementation('org.apache.velocity:velocity:1.7')
implementation('org.ini4j:ini4j:0.5.2')
implementation('com.sun.codemodel:codemodel:2.4.1')
implementation('org.yaml:snakeyaml:1.11')
implementation('com.github.zafarkhaja:java-semver:0.10.2')
testImplementation('ch.qos.logback:logback-classic:1.1.2')
testImplementation ('com.github.kbase:java_test_utilities:0.1.0') {
exclude group: 'com.fasterxml.jackson.core' // don't upgrade yet, breaks tests
exclude group: 'junit', module: 'junit'
}
testImplementation('com.github.kbase.workspace_deluxe:workspace-client:0.15.0') {
exclude group: 'com.fasterxml.jackson.core' // don't upgrade yet, breaks tests
exclude group: 'net.java.dev.jna' // don't include in runtime path
}
// needed for syslog4j. Used in java test modules and JsonServerServlet subclasses in tests
// but not in SDK code proper.
testImplementation('net.java.dev.jna:jna:3.4.0')
testImplementation("nl.jqno.equalsverifier:equalsverifier:4.0.7")
// this is OOOOOOLD. But that probably means updating java_common
testImplementation('org.eclipse.jetty.aggregate:jetty-all:7.0.0.v20091005')
testImplementation('org.hamcrest:hamcrest:3.0')
testImplementation('org.junit.jupiter:junit-jupiter:5.13.1')
testImplementation('org.slf4j:slf4j-api:1.7.7')
// TODO DEPS Need to rework the java common logger to not use syslog4j at all since it's
// abandonware and has a ton of CVEs, even in the newer versions.
// Note that the java SDK modules use syslog4j, so we'll need to figure something out
// there. I doubt any of the apps actually use the logging code that triggers it though
testImplementation('org.syslog4j:syslog4j:0.9.46')
testImplementation('uk.org.webcompere:system-stubs-jupiter:2.1.8')
// isolate the sdk generated code dependencies from the standard dependencies
generatedCodeClasspath('ch.qos.logback:logback-classic:1.1.2')
generatedCodeClasspath('com.fasterxml.jackson.core:jackson-databind:2.2.3')
generatedCodeClasspath('com.github.kbase:auth2_client_java:0.5.0') {
exclude group: 'com.fasterxml.jackson.core' // don't upgrade yet, breaks tests
}
generatedCodeClasspath('com.github.kbase:java_common:0.3.1') {
exclude group: 'com.fasterxml.jackson.core' // don't upgrade yet, breaks tests
}
generatedCodeClasspath('javax.annotation:javax.annotation-api:1.3.2')
generatedCodeClasspath('junit:junit:4.12')
generatedCodeClasspath('org.ini4j:ini4j:0.5.2')
generatedCodeClasspath('org.syslog4j:syslog4j:0.9.46')
}
task showTestClassPath {
doLast {
configurations.testimpl.each { println it }
}
}