forked from opprop/checker-framework-inference
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
370 lines (313 loc) · 11.7 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
plugins {
id 'com.github.johnrengelman.shadow' version '6.0.0'
}
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"
z3Jar = "${projectDir}/lib/com.microsoft.z3.jar"
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
errorproneJavacVersion = '9+181-r4173-1'
}
println '===================================='
println ' Checker Framework Inference '
println '===================================='
println ''
println '-------------------------------'
println 'Important Environment Variables'
println '-------------------------------'
println 'CHECKERFRAMEWORK: ' + checkerFrameworkPath
repositories {
jcenter()
mavenCentral()
}
configurations {
javacJar
}
dependencies {
if (isJava8) {
javacJar group: 'com.google.errorprone', name: 'javac', version: "$errorproneJavacVersion"
}
compile files("${checkerJar}")
compile group: 'com.google.errorprone', name: 'javac', version: "$errorproneJavacVersion"
compile 'org.plumelib:options:1.0.4'
// Serialize constraints
compile 'com.googlecode.json-simple:json-simple:1.1.1'
// Pretty print serialized constraints
compile 'com.google.code.gson:gson:2.8.6'
compile 'org.ow2.sat4j:org.ow2.sat4j.core:2.3.5'
compile 'org.ow2.sat4j:org.ow2.sat4j.maxsat:2.3.5'
compile files(z3Jar)
testCompile fileTree(dir: "${checkerFrameworkPath}/framework-test/build/libs", include: "framework-test-*.jar")
// Mocking library. Used in a couple tests
testCompile 'org.mockito:mockito-all:2.0.2-beta'
testCompile 'junit:junit:4.13'
}
sourceSets {
main {
java {
srcDirs = ["src"]
}
resources {
srcDir "src"
include "**/*.astub"
}
}
test {
java {
srcDirs = ["tests"]
}
}
}
task buildZ3(type: Exec) {
description 'Build Z3 solver'
onlyIf { !(new File(z3Jar).exists()) }
workingDir './scripts'
commandLine './buildZ3'
}
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)
}
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(buildZ3)
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'
archiveName = "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'
destinationDir = file("${projectDir}/dist")
archiveName = "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/jdk8.jar",
"${checkerFrameworkPath}/checker/dist/checker.jar",
"${checkerFrameworkPath}/checker/dist/checker-qual.jar",
"${checkerFrameworkPath}/checker/dist/javac.jar",
)
into file('dist')
}
task dependenciesJar(dependsOn: dist, type: Jar) {
description 'Create a jar file with all the dependencies.'
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
configurations.testCompile.collect { it.isDirectory() ? it : zipTree(it) }
}
archiveName 'dependencies.jar'
destinationDir file("${projectDir}/dist/")
}
task testLibJar(dependsOn: dist, type: Jar) {
from sourceSets.test.output.classesDirs
include ('checkers/inference/test/**')
archiveName 'inference-framework-test-lib.jar'
destinationDir 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'
}
baseName = 'release'
}
task cloneAndBuildDependencies(type: Exec) {
description 'Clones (or updates) and builds all dependencies'
executable './.travis-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/travis-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"
}