forked from typetools/checker-framework
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathbuild.gradle
264 lines (228 loc) · 11.1 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
plugins {
id 'java-library'
id 'base'
}
dependencies {
api project(':javacutil')
api project(':checker-qual')
// Node implements org.plumelib.util.UniqueId, so this dependency must be "api".
api "org.plumelib:plume-util:${versions.plumeUtil}"
// plume-util has an `implementation` dependency on hashmap-util.
// That follows Gradle's rules, but Gradle's rules are not entirely correct:
// https://github.com/gradle/gradle/issues/30054
// To build with JDK 22+, we need to redeclare that dependency here.
implementation "org.plumelib:hashmap-util:${versions.hashmapUtil}"
// External dependencies:
// If you add an external dependency, you must shadow its packages both in the dataflow-shaded
// artifact (see shadowJar block below) and also in checker.jar (see the comment in
// ../build.gradle in the createDataflowShaded task).
}
// Shadowing Test Sources and Dependencies
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
/**
* Creates a task with name dataflow${shadedPkgName} that creates a shaded dataflow jar. The packages will be shaded to
* "org.checkerframework.{@code shadedPkgName}" and the jar name is dataflow-${shadedPkgName}.jar.
* @param shadedPkgName
* @return
*/
def createDataflowShaded(shadedPkgName) {
tasks.create(name: "dataflow${shadedPkgName}Jar", type: ShadowJar, dependsOn: compileJava, group: 'Build') {
description "Builds dataflow-${shadedPkgName}.jar."
includeEmptyDirs = false
archiveBaseName.set("dataflow-${shadedPkgName}")
// Without this line, the Maven artifact will have the classifier "all".
archiveClassifier.set('')
from shadowJar.source
configurations = shadowJar.configurations
destinationDirectory = file("${buildDir}/shadow/dataflow${shadedPkgName}")
relocate('org.checkerframework', "org.checkerframework.${shadedPkgName}") {
// Shade all Checker Framework packages, except for the dataflow qualifiers.
exclude 'org.checkerframework.dataflow.qual.*'
}
// Relocate external dependencies
relocate 'org.plumelib', "org.checkerframework.${shadedPkgName}.org.plumelib"
relocate 'com.google', "org.checkerframework.${shadedPkgName}.com.google"
}
}
// Creates a new shaded dataflow artifact. To add a new one, add a new method call below, and add
// the new jar to publishing and signing blocks.
createDataflowShaded('shaded')
createDataflowShaded('nullaway')
createDataflowShaded('errorprone')
task manual(group: 'Documentation') {
description 'Build the manual'
doLast {
exec {
commandLine 'make', '-C', 'manual'
}
}
}
tasks.withType(Test) {
// Disable the gradle generated test task as the dataflow framework does not use JUnit for testing. If it were kept enabled (which is the default), gradlew would produce a deprecation warning.
// The `allDataflowTests` task dependency is still enabled.
enabled = false
dependsOn('allDataflowTests')
}
tasks.create(name: 'allDataflowTests', group: 'Verification') {
description 'Run all dataflow analysis tests'
// 'allDataflowTests' is automatically populated by testDataflowAnalysis().
}
/**
* Create a task to run a dataflow analysis test case.
* To add a new dataflow analysis test, you need to provide the
* task name, the directory which contains the test files, and the fully-qualified class
* name of the test class.
* Optionally, when option {@code diff} is true, the output is compared against a
* {@code Expected.txt} file.
* See org.checkerframework.dataflow.cfg.visualize.CFGVisualizeLauncher for more details.
* @param taskName the task name for the new task
* @param dirName the directory name of the directory that contains the test files
* @param className the fully-qualified name of the test class
* @param diff whether to compare the generated output with a {@code Expected.txt} file
* @return
*/
def testDataflowAnalysis(taskName, dirName, className, diff) {
tasks.create(name: taskName, dependsOn: [assemble, compileTestJava], group: 'Verification') {
description "Run the ${dirName} dataflow framework test."
if (diff) {
inputs.file("tests/${dirName}/Expected.txt")
}
inputs.file("tests/${dirName}/Test.java")
outputs.file("tests/${dirName}/Out.txt")
outputs.file("tests/${dirName}/Test.class")
delete("tests/${dirName}/Out.txt")
delete("tests/${dirName}/Test.class")
doLast {
javaexec {
workingDir = "tests/${dirName}"
if (!JavaVersion.current().java9Compatible) {
jvmArgs += "-Xbootclasspath/p:${configurations.javacJar.asPath}".toString()
}
else if (JavaVersion.current() > JavaVersion.VERSION_11) {
jvmArgs += [
'--add-opens',
'jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED',
'--add-opens',
'jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED',
'--add-opens',
'jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED',
'--add-opens',
'jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED',
'--add-opens',
'jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED',
'--add-opens',
'jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED',
'--add-opens',
'jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED',
]
}
classpath = sourceSets.test.runtimeClasspath
classpath += sourceSets.test.output
mainClass = "${className}"
}
if (diff) {
exec {
workingDir = "tests/${dirName}"
executable 'diff'
args = [
'-u',
'Expected.txt',
'Out.txt'
]
}
}
}
}
allDataflowTests.dependsOn << taskName
}
// When adding a new test case, don't forget to add the temporary files to `../.gitignore`.
testDataflowAnalysis("busyExpressionTest", "busyexpr", "busyexpr.BusyExpression", true)
testDataflowAnalysis("cfgConstructionTest", "cfgconstruction", "cfgconstruction.CFGConstruction", false)
testDataflowAnalysis("constantPropagationTest", "constant-propagation", "constantpropagation.ConstantPropagation", true)
testDataflowAnalysis("issue3447Test", "issue3447", "livevar.LiveVariable", false)
testDataflowAnalysis("liveVariableTest", "live-variable", "livevar.LiveVariable", true)
testDataflowAnalysis("reachingDefinitionTest", "reachingdef", "reachingdef.ReachingDefinition", true)
apply from: rootProject.file('gradle-mvn-push.gradle')
/** Adds information to the publication for uploading the dataflow artifacts to Maven repositories. */
final dataflowPom(publication) {
sharedPublicationConfiguration(publication)
publication.from components.java
// Information that is in all pom files is configured in checker-framework/gradle-mvn-push.gradle.
publication.pom {
name = 'Dataflow'
description = 'Dataflow is a dataflow framework based on the javac compiler.'
licenses {
license {
name = 'GNU General Public License, version 2 (GPL2), with the classpath exception'
url = 'http://www.gnu.org/software/classpath/license.html'
distribution = 'repo'
}
}
}
}
/**
* Adds information to the publication for uploading the dataflow-${shadedPkgName} artifacts to Maven repositories.
* @param shadedPkgName the name of the shaded package to use; also used as part of the artifact name: "dataflow-${shadePkgName}"
*/
final dataflowShadedPom(MavenPublication publication, String shadedPkgName) {
sharedPublicationConfiguration(publication)
publication.artifactId = "dataflow-${shadedPkgName}"
publication.pom {
name = "Dataflow (${shadedPkgName})"
description = "dataflow-${shadedPkgName} is a dataflow framework based on the javac compiler.\n" +
'\n' +
'It differs from the org.checkerframework:dataflow artifact in two ways.\n' +
"First, the packages in this artifact have been renamed to org.checkerframework.${shadedPkgName}.*.\n" +
'Second, unlike the dataflow artifact, this artifact contains the dependencies it requires.'
licenses {
license {
name = 'GNU General Public License, version 2 (GPL2), with the classpath exception'
url = 'http://www.gnu.org/software/classpath/license.html'
distribution = 'repo'
}
}
}
}
publishing {
publications {
dataflow(MavenPublication) {
dataflowPom it
}
dataflowShaded(MavenPublication) {
dataflowShadedPom(it, 'shaded')
artifact project.tasks.getByName('dataflowshadedJar').archiveFile
artifact sourcesJar
artifact javadocJar
}
dataflowShadednullaway(MavenPublication) {
dataflowShadedPom(it, 'nullaway')
artifact project.tasks.getByName('dataflownullawayJar').archiveFile
artifact sourcesJar
artifact javadocJar
}
dataflowShadederrorprone(MavenPublication) {
dataflowShadedPom(it, 'errorprone')
artifact project.tasks.getByName('dataflowerrorproneJar').archiveFile
artifact sourcesJar
artifact javadocJar
}
}
}
signing {
sign publishing.publications.dataflow
sign publishing.publications.dataflowShaded
sign publishing.publications.dataflowShadednullaway
sign publishing.publications.dataflowShadederrorprone
}
publishDataflowPublicationToMavenRepository.dependsOn(signDataflowShadedPublication)
publishDataflowPublicationToMavenRepository.dependsOn(signDataflowShadederrorpronePublication)
publishDataflowPublicationToMavenRepository.dependsOn(signDataflowShadednullawayPublication)
publishDataflowShadedPublicationToMavenRepository.dependsOn(signDataflowPublication)
publishDataflowShadedPublicationToMavenRepository.dependsOn(signDataflowShadederrorpronePublication)
publishDataflowShadedPublicationToMavenRepository.dependsOn(signDataflowShadednullawayPublication)
publishDataflowShadederrorpronePublicationToMavenRepository.dependsOn(signDataflowShadedPublication)
publishDataflowShadederrorpronePublicationToMavenRepository.dependsOn(signDataflowPublication)
publishDataflowShadederrorpronePublicationToMavenRepository.dependsOn(signDataflowShadednullawayPublication)
publishDataflowShadednullawayPublicationToMavenRepository.dependsOn(signDataflowShadederrorpronePublication)
publishDataflowShadednullawayPublicationToMavenRepository.dependsOn(signDataflowShadedPublication)
publishDataflowShadednullawayPublicationToMavenRepository.dependsOn(signDataflowPublication)