-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuild.gradle
391 lines (342 loc) · 12.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
import org.gradle.plugins.ide.eclipse.model.Output
import org.gradle.plugins.ide.eclipse.model.SourceFolder
plugins {
id 'eclipse'
id 'java'
id 'maven-publish'
id 'com.diffplug.spotless' version '6.25.0'
id 'io.github.gradle-nexus.publish-plugin' version '1.3.0'
id 'net.ltgt.errorprone' version '4.1.0'
// To show task list as a tree, run: ./gradlew <taskname> taskTree
id 'com.dorongold.task-tree' version '4.0.0'
}
// Nexus Publish plugin requires a group/version at the root project.
group = 'org.jspecify.reference'
version = '0.0.0-SNAPSHOT'
sourceSets {
main {
resources {
// Minimized jspecify/jdk
srcDirs += [
"${buildDir}/generated/resources"
]
}
}
}
repositories {
mavenLocal()
maven {
// Nexus snapshot repository
url = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
}
mavenCentral()
}
nexusPublishing {
repositories {
sonatype {
// For users registered in Sonatype after 24 Feb 2021
nexusUrl = uri("https://s01.oss.sonatype.org/service/local/")
snapshotRepositoryUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
}
}
ext {
// null if not included with `--include-build path/to/checker-framework`
checkerFramework = gradle.includedBuilds.find { it.name == 'checker-framework' }
// null if not included with `--include-build path/to/jspecify`
jspecify = gradle.includedBuilds.find { it.name == 'jspecify' }
// Location of the jspecify/jdk clone, relative to this directory
jspecifyJdkHome = '../jdk'
}
configurations {
errorproneJavac
conformanceTestSuite {
// When including a local JSpecify build, depend on the local test suite.
// See https://docs.gradle.org/current/userguide/cross_project_publications.html#sec:variant-aware-sharing.
if (jspecify != null) {
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, 'conformance-tests'))
}
}
}
}
java {
sourceCompatibility = 1.9
}
dependencies {
implementation libs.checkerFramework.checker
implementation libs.checkerFramework.checker.qual
// Eventually, we would want to only depend on `framework` and
// `javacutil` artifacts instead of the entire `checker`.
// implementation libs.checkerFramework.framework
// implementation libs.checkerFramework.javacutil
implementation libs.jspecify
testImplementation libs.checkerFramework.framework.test
testImplementation libs.guava
testImplementation libs.junit
testImplementation libs.jspecify.conformanceTestFramework
testRuntimeOnly libs.jsr305 // jsr305 annotations are in some of the samples
conformanceTestSuite libs.jspecify.conformanceTests
errorproneJavac libs.errorProne.javac
errorprone libs.errorProne.core
}
// If built with `--include-build path/to/checker-framework` then
// assemble checker-framework when assembling the reference checker.
if (checkerFramework != null) {
compileJava.dependsOn(checkerFramework.task(":checker:assembleForJavac"))
}
// If built with `--include-build path/to/jspecify` then
// assemble jspecify when assembling the reference checker.
if (jspecify != null) {
assemble.dependsOn(jspecify.task(':assemble'))
}
// Enable exec/javaexec
interface InjectedExecOps {
@Inject
ExecOperations getExecOps()
}
tasks.withType(JavaCompile).configureEach {
options.compilerArgs.add("-Xlint:all")
// ErrorProne makes suppressing these easier
options.compilerArgs.add("-Xlint:-fallthrough")
options.errorprone.disable("BadImport")
options.errorprone.disable("VoidUsed")
options.compilerArgs.addAll(
[
"api",
"code",
"comp",
"file",
"main",
"model",
"parser",
"processing",
"resources",
"tree",
"util",
]
.collect { "--add-exports=jdk.compiler/com.sun.tools.javac.$it=ALL-UNNAMED" })
}
tasks.register('includeJSpecifyJDK') {
group = 'Build'
dependsOn 'compileJava'
def srcDir = "${jspecifyJdkHome}/src"
// This directory needs to be stored at the top-level of the resulting .jar file.
// org.checkerframework.framework.stub.AnnotationFileElementTypes will then load
// the JDK classes from here instead of from checker.jar.
def dstDir = "${buildDir}/generated/resources/annotated-jdk/src/"
inputs.dir file(srcDir)
outputs.dir file(dstDir)
def injected = project.objects.newInstance(InjectedExecOps)
doLast {
FileTree srcTree = fileTree(dir: srcDir)
NavigableSet<String> specFiles = new TreeSet<>();
srcTree.visit { FileVisitDetails fvd ->
if (!fvd.file.isDirectory() && fvd.file.name.matches('.*\\.java')) {
fvd.getFile().readLines().any { line ->
if (line.contains('org.jspecify')) {
specFiles.add(fvd.file.absolutePath)
return true;
}
}
}
}
String absoluteSrcDir = file(srcDir).absolutePath
int srcPrefixSize = absoluteSrcDir.size()
copy {
from(srcDir)
into(dstDir)
for (String specFile : specFiles) {
include specFile.substring(srcPrefixSize)
}
}
injected.execOps.javaexec {
classpath = sourceSets.main.runtimeClasspath
standardOutput = System.out
errorOutput = System.err
mainClass = 'org.checkerframework.framework.stub.JavaStubifier'
args dstDir
}
}
}
processResources.dependsOn(includeJSpecifyJDK)
tasks.withType(Test).configureEach {
if (!JavaVersion.current().java9Compatible) {
jvmArgs "-Xbootclasspath/p:${configurations.errorproneJavac.asPath}"
}
// Required because checker-framework uses APIs from these modules.
jvmArgs(
[
"code",
"comp",
"main",
"processing",
"tree",
"util",
]
.collect { "--add-opens=jdk.compiler/com.sun.tools.javac.$it=ALL-UNNAMED" })
testLogging {
showStackTraces = false
showStandardStreams = true
events "failed"
exceptionFormat = "full"
}
}
test {
include '**/NullSpecTest$Minimal.class'
inputs.files("${rootDir}/tests/minimal")
include '**/NullSpecTest$Regression.class'
inputs.files("${rootDir}/tests/regression")
}
tasks.register('jspecifySamplesTest', Test) {
description = 'Run the checker against the JSpecify samples.'
group = 'verification'
shouldRunAfter test
include '**/NullSpecTest$Lenient.class'
include '**/NullSpecTest$Strict.class'
inputs.files(unzipConformanceTestSuite)
}
tasks.register('unzipConformanceTestSuite', Copy) {
dependsOn configurations.conformanceTestSuite
from zipTree(configurations.conformanceTestSuite.singleFile)
into layout.buildDirectory.dir("conformanceTests")
}
tasks.register('conformanceTests', Test) {
group = 'verification'
include '**/ConformanceTest.class'
shouldRunAfter test
// Conformance tests
inputs.files(unzipConformanceTestSuite)
inputs.files("tests/ConformanceTest-report.txt")
doFirst {
systemProperties([
"JSpecifyConformanceTest.inputs": "${unzipConformanceTestSuite.destinationDir}/assertions/org/jspecify/conformance/tests",
"JSpecifyConformanceTest.report": "tests/ConformanceTest-report.txt",
"JSpecifyConformanceTest.deps" : fileTree("${unzipConformanceTestSuite.destinationDir}/deps").join(":")
])
}
// Conformance tests run on the samples directory
inputs.files("tests/ConformanceTestOnSamples-report.txt")
doFirst {
systemProperties([
"JSpecifyConformanceTest.samples.inputs": "${unzipConformanceTestSuite.destinationDir}/samples",
"JSpecifyConformanceTest.samples.report": "tests/ConformanceTestOnSamples-report.txt"
])
}
}
tasks.named('check').configure {
dependsOn('conformanceTests')
}
clean.doFirst {
delete "${rootDir}/tests/build/"
}
tasks.register('demoTest', Exec) {
group = 'verification'
shouldRunAfter 'conformanceTests'
dependsOn assemble
inputs.files('demo', 'SimpleSample.java')
executable '/bin/sh'
args 'demo', 'SimpleSample.java'
ignoreExitValue = true
errorOutput = new ByteArrayOutputStream()
doLast {
if (!errorOutput.toString().contains("SimpleSample.java:7: error:")) {
throw new AssertionError("`./demo SimpleSample.java` did not run correctly. Error output:\n$errorOutput")
}
}
}
/*
Spotless validates its formatters' dependencies eagerly, on project configuration.
google-java-format depends on checker-qual, which is built by a subproject.
On a clean build, the checker-qual JAR file doesn't exist yet, so Spotless throws an error.
The file doesn't have to be correct; it just has to be a JAR file.
So here, before the spotless block, we create a meaningless JAR file at that location if it doesn't already exist.
See https://github.com/jspecify/jspecify-reference-checker/issues/81
*/
if (checkerFramework != null) {
def cfQualJar =
checkerFramework.projectDir.toPath()
.resolve("checker-qual/build/libs/checker-qual-${libs.versions.checkerFramework.get()}.jar")
def injected = project.objects.newInstance(InjectedExecOps)
if (!cfQualJar.toFile().exists()) {
mkdir(cfQualJar.parent)
injected.execOps.exec {
executable 'jar'
args = [
'cf',
cfQualJar,
buildFile.path // Use this build script file!
]
}
}
}
spotless {
java {
target '**/*.java'
googleJavaFormat()
formatAnnotations()
}
groovyGradle {
target '**/*.gradle'
greclipse()
indentWithSpaces(4)
trimTrailingWhitespace()
}
}
// Use `./gradlew eclipseClasspath` to create Eclipse/VSCode configurations
eclipse.classpath {
defaultOutputDir = file("build/default")
file.whenMerged { cp ->
cp.entries.forEach { cpe ->
if (cpe instanceof SourceFolder) {
cpe.output = cpe.output.replace "bin/", "build/classes/java/"
}
if (cpe instanceof Output) {
cpe.path = cpe.path.replace "bin/", "build/"
}
}
}
}
publishing {
publications {
jspecifyReferenceChecker(MavenPublication) {
pom {
groupId = 'org.jspecify.reference'
artifactId = 'checker'
version = project.version
name = 'JSpecify Reference Checker'
description = 'The JSpecify Reference Checker'
url = 'http://jspecify.org/'
from components.java
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
scm {
connection = 'scm:git:git@github.com:jspecify/jspecify-reference-checker.git'
developerConnection = 'scm:git:git@github.com:jspecify/jspecify-reference-checker.git'
url = 'https://github.com/jspecify/jspecify-reference-checker'
}
developers {
developer {
id = 'cpovirk'
name = 'Chris Povirk'
email = 'cpovirk@google.com'
}
developer {
id = 'netdpb'
name = 'David P. Baker'
email = 'dpb@google.com'
}
developer {
id = 'wmdietl'
name = 'Werner M. Dietl'
email = 'wdietl@gmail.com'
}
}
}
}
}
}