forked from typetools/checker-framework-inference
-
Notifications
You must be signed in to change notification settings - Fork 13
/
build.gradle
443 lines (381 loc) · 14.2 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
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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
buildscript {
dependencies {
if (JavaVersion.current() >= JavaVersion.VERSION_11) {
// Code formatting; defines targets "spotlessApply" and "spotlessCheck".
// https://github.com/diffplug/spotless/tags ; see tags starting "gradle/"
// Only works on JDK 11+.
classpath 'com.diffplug.spotless:spotless-plugin-gradle:6.22.0'
}
}
}
plugins {
id 'com.github.johnrengelman.shadow' version '7.1.2'
}
apply plugin: 'java'
// Note: For this setup to work you must follow the instructions outlined in the
// checker manual Section 25.3 "Building from Source"
// http://types.cs.washington.edu/checker-framework/current/checkers-manual.html#build-source
ext {
jsr308 = System.getenv('JSR308') ?: file(new File("..")).absolutePath
checkerFrameworkPath = System.getenv('CHECKERFRAMEWORK') ?: "${jsr308}/checker-framework"
checkerJar = "${checkerFrameworkPath}/checker/dist/checker.jar"
afu = "${jsr308}/annotation-tools/annotation-file-utilities"
lingelingTar = "${projectDir}/lib/lingeling.tar.gz"
dljcScript = "${jsr308}/do-like-javac/dljc"
// On a Java 8 JVM, use error-prone javac and source/target 8.
// On a Java 9+ JVM, use the host javac, default source/target, and required module flags.
isJava8 = JavaVersion.current() == JavaVersion.VERSION_1_8
isJava11plus = JavaVersion.current() >= JavaVersion.VERSION_11
errorproneJavacVersion = '9+181-r4173-1'
// Keep in sync with checker-framework/build.gradle.
// TODO: find a way to directly use that variable.
compilerArgsForRunningCF = [
"--add-exports",
"jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-exports",
"jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
"--add-exports",
"jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
"--add-exports",
"jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
"--add-exports",
"jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
"--add-exports",
"jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
"--add-exports",
"jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"--add-exports",
"jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
"--add-opens",
"jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
]
if (isJava11plus) {
apply plugin: 'com.diffplug.spotless'
spotless {
format 'misc', {
target '*.md', '*.tex', '.gitignore', 'Makefile'
indentWithSpaces(2)
trimTrailingWhitespace()
}
java {
googleJavaFormat().aosp()
importOrder('com', 'jdk', 'lib', 'lombok', 'org', 'java', 'javax')
formatAnnotations().addTypeAnnotation("PolyInitialized")
}
groovyGradle {
target '**/*.gradle'
greclipse() // which formatter Spotless should use to format .gradle files.
indentWithSpaces(4)
trimTrailingWhitespace()
}
}
}
}
println '===================================='
println ' Checker Framework Inference '
println '===================================='
println ''
println '-------------------------------'
println 'Important Environment Variables'
println '-------------------------------'
println 'CHECKERFRAMEWORK: ' + checkerFrameworkPath
repositories {
mavenCentral()
}
configurations {
javacJar
}
dependencies {
if (isJava8) {
javacJar group: 'com.google.errorprone', name: 'javac', version: "$errorproneJavacVersion"
}
implementation files("${checkerJar}")
implementation group: 'com.google.errorprone', name: 'javac', version: "$errorproneJavacVersion"
implementation 'org.plumelib:options:1.0.5'
implementation 'org.plumelib:plume-util:1.8.1'
implementation 'com.google.guava:guava:31.1-jre'
// AFU is an "includedBuild" imported in settings.gradle, so the version number doesn't matter.
// https://docs.gradle.org/current/userguide/composite_builds.html#settings_defined_composite
implementation('io.github.eisop:annotation-file-utilities:*') {
exclude group: 'com.google.errorprone', module: 'javac'
}
// Serialize constraints
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
// Pretty print serialized constraints
implementation 'com.google.code.gson:gson:2.9.1'
implementation 'org.ow2.sat4j:org.ow2.sat4j.core:2.3.6'
implementation 'org.ow2.sat4j:org.ow2.sat4j.maxsat:2.3.6'
implementation 'tools.aqua:z3-turnkey:4.11.2'
testImplementation fileTree(dir: "${checkerFrameworkPath}/framework-test/build/libs", include: "framework-test-*.jar")
// Mocking library. Used in a couple tests
testImplementation 'org.mockito:mockito-all:2.0.2-beta'
testImplementation 'junit:junit:4.13.2'
}
sourceSets {
main {
java {
srcDirs = ["src"]
}
resources {
srcDir "src"
include "**/*.astub"
}
}
test {
java {
srcDirs = ["tests"]
}
}
}
task buildLingeling(type: Exec) {
description 'Build Lingeling solver'
onlyIf { !(new File(lingelingTar).exists()) }
workingDir './scripts'
commandLine './buildLingeling'
}
task buildDLJC(type: Exec) {
description 'Build DLJC Tool'
onlyIf { !(new File(dljcScript).exists()) }
workingDir './scripts'
commandLine './buildDLJC'
}
test {
dependsOn(shadowJar)
dependsOn('dist')
systemProperties 'path.afu.scripts': "${afu}/scripts",
'use.hacks': true
systemProperties += [JDK_JAR: "${checkerFrameworkPath}/checker/dist/jdk8.jar"]
if (project.hasProperty('emit.test.debug')) {
systemProperties += ["emit.test.debug": 'true']
}
if (isJava8) {
jvmArgs += [
"-Xbootclasspath/p:${configurations.javacJar.asPath}"
]
} else {
// Without this, the test throw "java.lang.OutOfMemoryError: Java heap space"
// Corresponding pull request: https://github.com/opprop/checker-framework-inference/pull/263
forkEvery(1)
jvmArgs += compilerArgsForRunningCF
}
testLogging {
// Always run the tests
outputs.upToDateWhen { false }
// The following prints out each time a test is passed.
// events "passed", "skipped", "failed", "standardOut", "standardError"
// Show the found unexpected diagnostics and expected diagnostics not found.
exceptionFormat "full"
}
// After each test, print a summary.
afterSuite { desc, result ->
if (desc.getClassName() != null) {
long mils = result.getEndTime() - result.getStartTime()
double seconds = mils / 1000.0
println "Testsuite: ${desc.getClassName()}\n" +
"Tests run: ${result.testCount}, " +
"Failures: ${result.failedTestCount}, " +
"Skipped: ${result.skippedTestCount}, " +
"Time elapsed: ${seconds} sec\n"
}
}
}
compileJava {
dependsOn(buildLingeling)
dependsOn(buildDLJC)
options.compilerArgs = [
'-implicit:class',
'-Awarns',
'-Xmaxwarns',
'10000',
// Can't use this because JSON library contains raw types:
// '-Xlint:unchecked',
'-Xlint:deprecation',
'-Werror',
]
}
// Exclude parts of the build directory that don't include classes from being packaged in
// the jar file.
// IMPORTANT: If "libs" is packaged in the JAR file you end up with an infinitely
// recursive jar task that will fill up your hard drive (eventually)
jar {
description = 'Makes a jar with ONLY the classes compiled for checker ' +
'framework inference and NONE of its dependencies'
archiveFileName = "checker-framework-inference.jar"
manifest.attributes("Main-Class": "checkers.inference.InferenceLauncher")
exclude("dependency-cache", "libs", "tmp")
}
shadowJar {
dependencies {
exclude(dependency("junit:.*:.*"))
}
description 'Creates the "fat" checker.jar in dist'
destinationDirectory = file("${projectDir}/dist")
archiveFileName = "checker-framework-inference.jar"
}
task dist(dependsOn: shadowJar, type: Copy) {
description = "If your Checker Framework project is fully built, this task " +
"will build checker-framework-inference.jar, copy all the relevant runtime jars into " +
"the dist directory."
from files(
"${checkerFrameworkPath}/checker/dist/checker.jar",
"${checkerFrameworkPath}/checker/dist/checker-qual.jar",
"${checkerFrameworkPath}/checker/dist/checker-util.jar",
"${checkerFrameworkPath}/checker/dist/javac.jar",
)
into file('dist')
}
task dependenciesJar(dependsOn: dist, type: Jar) {
description 'Create a jar file with all the dependencies.'
duplicatesStrategy DuplicatesStrategy.EXCLUDE
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
archiveFileName = 'dependencies.jar'
destinationDirectory = file("${projectDir}/dist/")
}
task testLibJar(dependsOn: dist, type: Jar) {
from sourceSets.test.output.classesDirs
include ('checkers/inference/test/**')
archiveFileName = 'inference-framework-test-lib.jar'
destinationDirectory = file("${projectDir}/dist/")
}
tasks.clean {
delete += "build/libs/checker-framework-inference.zip"
delete += "jdk8.jar"
delete += "javac.jar"
delete += fileTree('dist') {
include '**/*.jar'
}
delete += "testdata/tmp"
}
task release(type: Zip) {
from('src') {
into('release/src')
}
from('dist') {
into('release/dist')
}
from('scripts') {
into('release/scripts')
include '*.py'
}
archiveBaseName = 'release'
}
task cloneAndBuildDependencies(type: Exec) {
description 'Clones (or updates) and builds all dependencies'
executable './.ci-build-without-test.sh'
}
task testCheckerInferenceScript(type: Exec, dependsOn: dist) {
description 'Basic sanity check of scripts/inference'
executable './scripts/inference'
args = [
'--mode',
'TYPECHECK',
'--checker',
'ostrusted.OsTrustedChecker',
'--solver',
'checkers.inference.solver.PropagationSolver',
'testdata/ostrusted/Test.java'
]
}
task testCheckerInferenceDevScript(type: Exec, dependsOn: [dist, dependenciesJar]) {
description 'Basic sanity check of scripts/inference-dev'
executable './scripts/inference-dev'
args = [
'--mode',
'INFER',
'--checker',
'interning.InterningChecker',
'--solver',
'checkers.inference.solver.MaxSat2TypeSolver',
'--hacks=true',
'testdata/interning/MapAssignment.java'
]
}
task testDataflowExternalSolvers(type: Exec, dependsOn: [dist, dependenciesJar]) {
description 'Test Dataflow type system on its external solvers Lingeling and LogicBlox'
executable './testing/dataflowexample/ci-test.sh'
}
afterEvaluate {
// Create a task for each test class whose name is the same as the class name.
sourceSets.test.java.filter {
it.path.contains('tests/checkers') &&
it.path.endsWith('Test.java') &&
!it.path.contains('CFInferenceTest')
}.forEach { file ->
String junitClassName = file.name.replaceAll(".java", "")
tasks.create(name: "${junitClassName}", type: Test, group: 'Verification') {
description "Run ${junitClassName} tests."
include "**/${name}.class"
}
}
// Configure Tests
tasks.withType(Test) {
dependsOn(shadowJar)
systemProperties 'path.afu.scripts': "${afu}/scripts",
'path.inference.script': "${projectDir}/scripts/inference",
'use.hacks': true,
JDK_JAR: "${checkerFrameworkPath}/checker/dist/jdk8.jar"
if (project.hasProperty('emit.test.debug')) {
systemProperties += ["emit.test.debug": 'true']
}
if (isJava8) {
jvmArgs += [
"-Xbootclasspath/p:${configurations.javacJar.asPath}"
]
}
testLogging {
// Always run the tests
outputs.upToDateWhen { false }
// The following prints out each time a test is passed.
// events "passed", "skipped", "failed", "standardOut", "standardError"
events "failed"
// Show the found unexpected diagnostics and expected diagnostics not found.
exceptionFormat "full"
}
// After each test, print a summary.
afterSuite { desc, result ->
if (desc.getClassName() != null) {
long mils = result.getEndTime() - result.getStartTime()
double seconds = mils / 1000.0
println "Testsuite: ${desc.getClassName()}\n" +
"Tests run: ${result.testCount}, " +
"Failures: ${result.failedTestCount}, " +
"Skipped: ${result.skippedTestCount}, " +
"Time elapsed: ${seconds} sec\n"
}
}
}
}
/// Commented out because plugins section is commented out
// /* Configuration for formatting */
// googleJavaFormat {
// // toolVersion '1.3'
// options style: 'AOSP'
// }
// tasks.googleJavaFormat {
// group 'Formatting'
// description = "Reformat Java source code with Google-Java-format"
// exclude 'testing'
// exclude 'testinputs'
// }
// tasks.verifyGoogleJavaFormat {
// group 'Formatting'
// description = "Check Java source code is in Google-Java-format"
// exclude 'testing'
// exclude 'testinputs'
// }
task etags {
doLast {
def sources = (sourceSets.main.java).getFiles().collect({ src -> src.getPath() }).sort()
def sourcesStr = sources.inject(null, { acc, source -> acc ? acc + " " + source : source })
def proc = "etags ${sourcesStr} ".execute()
proc.in.eachLine { line -> println line }
proc.err.eachLine { line -> println 'ERROR: ' + line }
proc.waitFor()
}
}
task tags(dependsOn: etags)
task countHacks(type: Exec) {
commandLine "bash", "-c", "grep -r 'InferenceMain.isHackMode(' src/ | wc -l"
}