forked from typetools/checker-framework-inference
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
288 lines (236 loc) · 9.93 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
import java.util.regex.Matcher
import java.util.regex.Pattern
apply plugin: 'java'
//Checker Framework Inference - build.gradle
//This script allows you to compile and jar checker-framework-inference along with
//all required dependencies
//gradle jar will create a NON-standalone jar
//gradle allJar will create a stand-alone jar providing that all projects upon which
//Checker Framework Inference depends are built
//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
//TODO: It seems like, at the moment this script doesn't do a great job of detecting
// when we do not need to recompile
//TODO: currently there are NO tests for this project, when there are they will need to be
// added to this script
//Questions: Mail [email protected]
def env = System.getenv()
def jsr308Dir = env["JSR308"] ?: ".."
// Support for backwards compatibility (CHECKERFRAMEWORK is the more correct).
def checkersDir = env["CHECKER_FRAMEWORK"] ?: env["CHECKERFRAMEWORK"] ?: (jsr308Dir + "/checker-framework")
def javaHome = env["JAVA_HOME"]
//Used to determine which version of the jdk<v>.jar to use when building and running
//Checker Framework Inference. If this "CFI_JRE_VERSION" variable is left unset then it will be
//determined based on the the version of the currently running JVM
def jreVersion = {
def envJreVersion = env["CFI_JRE_VERSION"];
if(envJreVersion == null) {
def jreVersionStr = System.getProperty("java.version");
def matches = ( jreVersionStr =~ /^(\d\.\d+)\..*$/ )
final double jreVer;
if(matches.matches()) {
jreVer = Double.parseDouble(matches.group(1));
} else {
throw new RuntimeException("Could not determine version from property java.version=" + jreVersionStr);
}
return jreVer
} else {
return envJreVersion;
}
}.call()
/**
* Returns JDK JAR filename corresponding to JRE version in use
* TODO: This is basically a copy of logic found in CheckerMain (and in Verigames/build.gradle), find a way
* TODO: to unify these?
*/
def jreJarName = {
final String fileName;
if(jreVersion == 1.4 || jreVersion == 1.5 || jreVersion == 1.6) {
fileName = "jdk6.jar";
} else if(jreVersion == 1.7) {
fileName = "jdk7.jar";
} else if(jreVersion == 1.8) {
fileName = "jdk8.jar";
} else {
throw new RuntimeException("Unsupported JRE version: " + jreVersion);
}
return fileName;
}.call()
println '===================================='
println ' Checker Framework Inference '
println '===================================='
println ''
println '-------------------------------'
println 'Important Environment Variables'
println '-------------------------------'
println 'JSR308 : ' + jsr308Dir
println 'CHECKERFRAMEWORK: ' + checkersDir
println 'JAVA_HOME : ' + javaHome
println 'CFI_JRE_VERSION : ' + jreVersion
println 'jreJarName : ' + jreJarName
if(javaHome == null) {
throw new RuntimeException("JAVA_HOME must be set to a valid Java 7 JRE.")
}
project.ext {
checkerInferenceJar = file("bin/libs/checker-framework-inference.jar").getAbsolutePath()
}
//Closure that creates a file from a base directory and a name of the file in that directory
def fromBaseDir = { baseDir, child -> baseDir ? new File(baseDir, child) : new File(child) }
//A function that, given a file name, creates a file object of that name with
//jsr308Dir as its parent
def jsr308Child = fromBaseDir.curry(jsr308Dir)
//A function that, given a file name, creates a file object of that name with
//checkersDir as its parent
def checkersChild = fromBaseDir.curry(checkersDir)
def afuDir = env["AFU"] ?: jsr308Child("annotation-tools/annotation-file-utilities")
//A function that, given a file name, creates a file object of that name with
//afuDir as its parent
def afuChild = fromBaseDir.curry(afuDir)
//JarsToPackage contains both all members that should be on the classpath for this build
//and all jars (except for checker-framework-inference.jar) that should be included in
//the jar produced by the allJars command
def jarsToPackage = [ //Annotation File Utilities paths //TODO: AFU Jar has some things that are also in checkers.jar
"annotation-file-utilities.jar"
].collect { afuChild(it).getAbsolutePath() } +
[
"plume-lib/java/plume.jar"
].collect { jsr308Child(it).getAbsolutePath() } +
[//checker relative paths
"checker/dist/$jreJarName",
"checker/dist/javac.jar",
"checker/dist/checker.jar",
].collect { checkersChild(it).getAbsolutePath() }
//A list of files to append to the class path during compilation
def toPackageClasspath = files(
jarsToPackage
+ new File(javaHome, "lib/tools.jar").getAbsolutePath()
+ new File(javaHome, "jre/lib/rt.jar").getAbsolutePath()
)
sourceSets {
main {
java {
srcDir "src"
}
resources {
srcDir "src"
include "**/*.astub"
}
//Leads to a dir structure of "checker-framework-inference/bin/checkers/...classes...
output.classesDir "bin"
compileClasspath += toPackageClasspath
compileClasspath += files("bin")
}
test {
java {
srcDirs = ["tests"]
include "**/*Test.java"
compileClasspath += toPackageClasspath
compileClasspath += files("bin")
runtimeClasspath += compileClasspath
}
}
}
buildDir = "bin"
repositories {
mavenCentral()
}
dependencies {
// Serialize constraints
compile 'com.googlecode.json-simple:json-simple:1.1.1'
// Pretty print serialized constraints
compile 'com.google.code.gson:gson:1.7.2'
// Mocking library. Used in a couple tests
compile 'org.mockito:mockito-all:1.8.4'
compile 'org.ow2.sat4j:org.ow2.sat4j.core:2.3.4'
compile 'org.ow2.sat4j:org.ow2.sat4j.maxsat:2.3.4'
testCompile 'junit:junit:4.12'
}
//Switch the Javac used to the JSR308
tasks.compileJava {
description = 'Compiles this project using the jsr308 compiler.'
options.fork = true
options.compilerArgs = [
'-implicit:class',
'-Awarns', '-Xmaxwarns', '10000', '-version']
if(jreVersion == 1.7) {
options.compilerArgs += ['-source' , '7', '-target', '7']
}
options.forkOptions.executable="$checkersDir/checker/bin/javac"
}
//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)
tasks.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")
}
tasks.clean {
delete += "build/libs/checker-framework-inference.zip"
delete += "bin/libs/checker-framework-inference-all.jar"
delete += "jdk6.jar"
delete += "jdk7.jar"
delete += "jdk8.jar"
delete += "javac.jar"
delete += fileTree('dist') {
include '**/*.jar'
}
}
task copyDeps(type : Copy) {
from tasks.getByPath('compileJava').getClasspath().filter({f -> f.getName().startsWith("json-")})
from tasks.getByPath('compileJava').getClasspath().filter({f -> f.getName().startsWith("gson")})
from tasks.getByPath('compileJava').getClasspath().filter({f -> f.getName().contains("mockito")})
from tasks.getByPath('compileJava').getClasspath().filter({f -> f.getName().contains("sat4j")})
into file('dist/')
}
task dist(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(jarsToPackage + checkerInferenceJar)
into file('dist')
} dependsOn(jar, copyDeps)
task copytest(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 tasks.getByPath('test').getClasspath().filter(
{ f -> f.getName().contains("junit") && f.getName().endsWith(".jar") &&
!f.getName().equals("rt.jar") && !f.getName().equals("tools.jar")
})
from tasks.getByPath('compileJava').getClasspath().filter(
{ f -> f.getName().endsWith(".jar") && !f.getName().equals("rt.jar") && !f.getName().equals("tools.jar")
})
from file(checkerInferenceJar)
into file('tests/deps')
} dependsOn(jar, copyDeps)
test {
scanForTestClasses = false // was running into weird runtime exception http://stackoverflow.com/questions/14814837/gradle-test-fails-with-error
include "**/*Test.class"
jvmArgs "-Xbootclasspath/p:" + toPackageClasspath.asPath
}
task release(type: Zip) {
from('src'){
into('release/src')
}
from('dist'){
into('release/dist')
}
from('scripts'){
into('release/scripts')
include '*.py'
}
baseName = 'release'
}
task etags << {
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()
}