-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
411 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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
////////////////////////////////////////////////////////////////////////
//
// plugin configuration must precede everything else
//
buildscript {
dependencies.classpath 'commons-io:commons-io:2.11.0'
}
plugins {
id 'all.shared.gradle.file-lister' version '1.0.2'
id 'com.diffplug.eclipse.mavencentral' version '3.33.2' apply false
id 'com.dorongold.task-tree' version '2.1.0'
id 'com.github.ben-manes.versions' version '0.39.0'
id 'com.github.sherter.google-java-format' version '0.9'
id 'de.undercouch.download'
id 'nebula.lint' version '17.2.3'
}
apply from: "$rootDir/wala-javadoc.gradle"
repositories {
// to get the google-java-format jar and dependencies
mavenCentral()
}
ext.osName = System.getProperty('os.name')
ext.archName = System.getProperty('os.arch')
ext.isWindows = osName.startsWith('Windows ')
////////////////////////////////////////////////////////////////////////
//
// common Java setup shared by multiple projects
//
group name
version VERSION_NAME
// version of Eclipse JARs to use for Eclipse-integrated WALA components. On ARM-based Mac OS
// machines, we use a more recent Eclipse version which includes an SWT library built for the
// platform. We only use the recent version on ARM-based Macs as it requires JDK 11, and we would
// like to preserve JDK 8 compatibility on other platforms.
ext.eclipseVersion = (osName.equals('Mac OS X') && archName.equals('aarch64')) ? '4.21.0' : '4.14.0'
ext.eclipseWstJsdtVersion = '1.0.201.v2010012803'
///////////////////////////////////////////////////////////////////////
//
// Javadoc documentation
//
tasks.register('aggregatedJavadocs', Javadoc) { aggregated ->
description = 'Generate javadocs from all child projects as if they were a single project'
group = 'Documentation'
destinationDir = file("$buildDir/docs/javadoc")
title = "$project.name $version API"
options.author true
subprojects.each { proj ->
proj.tasks.withType(Javadoc) { javadocTask ->
aggregated.source += javadocTask.source
aggregated.classpath += javadocTask.classpath
aggregated.excludes += javadocTask.excludes
aggregated.includes += javadocTask.includes
}
}
}
////////////////////////////////////////////////////////////////////////
//
// linters for various specific languages or file formats
//
allprojects {
apply plugin: 'nebula.lint'
// We use no deprecated Gradle APIs ourselves, and we'd like to keep it that way.
// Unfortunately, the Gradle linter tasks produce a deprecation warning under Gradle 7.2. The
// warning message is not detailed by default, and could easily mask any new deprecation
// problems that we might introduce ourselves. So we don't run the linter by default for now.
gradleLint.alwaysRun = false
gradleLint {
rules = [
'all-dependency',
'archaic-wrapper',
'duplicate-dependency-class',
]
// These rules warn about platform-specific Eclipse SWT dependencies, such as
// `org.eclipse.platform:org.eclipse.swt.gtk.linux.x86_64:3.113.0`. There seems to be no
// way to suppress warnings just for specific dependencies or dependency patterns, so we
// have to exclude these rules entirely.
excludedRules = [
'undeclared-dependency',
'unused-dependency',
]
}
}
// shell scripts, provided they have ".sh" extension
if (isWindows) {
// create a no-op "shellCheck" task so that "gradlew shellCheck" vacuously passes on Windows
tasks.register('shellCheck')
} else {
// create a real "shellCheck" task that actually runs the "shellcheck" linter, if available
tasks.register('shellCheck', Exec) {
description 'Check all shell scripts using shellcheck, if available'
group 'verification'
inputs.files fileTree('.').exclude('**/build').include('**/*.sh')
outputs.file project.layout.buildDirectory.file('shellcheck.log')
doFirst {
// quietly succeed if "shellcheck" is not available
executable 'shellcheck'
final execPaths = System.getenv('PATH').split(File.pathSeparator)
final isAvailable = execPaths.any { file("$it/$executable").exists() }
if (!isAvailable) executable 'true'
args inputs.files
final consoleOutput = System.out
final fileOutput = new FileOutputStream(outputs.files.singleFile)
final bothOutput = new org.apache.tools.ant.util.TeeOutputStream(consoleOutput, fileOutput)
standardOutput = errorOutput = bothOutput
}
}
}
// Java formatting
googleJavaFormat {
group 'verification'
toolVersion = '1.7'
// exclude since various tests make assertions based on
// source positions in the test inputs. to auto-format
// we also need to update the test assertions
exclude 'com.ibm.wala.cast.java.test.data/**/*.java'
}
final verifyGoogleJavaFormat = tasks.named('verifyGoogleJavaFormat') {
group 'verification'
// workaround for <https://github.com/sherter/google-java-format-gradle-plugin/issues/43>
final stampFile = project.layout.buildDirectory.file(name)
outputs.file stampFile
doLast {
stampFile.get().asFile.text = ''
}
exclude '**/build/'
}
tasks.named('autoLintGradle') {
// `autoLintGradle` creates no output files, which causes Gradle to treat it as always
// out-of-date. By creating a simple, empty stamp file to record that this task has run and
// succeeded, we allow Gradle to avoid rerunning this task unnecessarily. This task will still
// be rerun when needed, though, such as when any of the `**/build.gradle` files changes.
final stampFile = project.layout.buildDirectory.file(name)
outputs.file stampFile
doLast {
stampFile.get().asFile.text = ''
}
}
// install Java reformatter as git pre-commit hook
tasks.register('installGitHooks', Copy) {
from 'config/hooks/pre-commit-stub'
rename { 'pre-commit' }
into '.git/hooks'
fileMode 0777
}
// run all known linters
final check = tasks.register('check') {
group = 'verification'
dependsOn(
// 'lintGradle',
'shellCheck',
)
if (!(isWindows && System.getenv('GITHUB_ACTIONS') == 'true')) {
// Known to be broken on Windows when running as a GitHub Action, but not intentionally so.
// Please fix if you know how! <https://github.com/wala/WALA/issues/608>
dependsOn verifyGoogleJavaFormat
}
}
tasks.register('build') {
dependsOn check
}
////////////////////////////////////////////////////////////////////////
//
// Run IntelliJ IDEA inspections on entire project tree
//
// We don't make `check` depend on `checkInspectionResults` for two
// reasons. First, `runInspections` is quite slow. Second,
// `runInspections` cannot run while the same user account is running a
// regular, graphical instance of IntelliJ IDEA. These limitations
// make `runInspections` and `checkInspectionResults` more suitable for
// use in CI/CD pipelines than for daily use by live WALA developers.
//
final runInspections = tasks.register('runInspections', Exec) {
group = 'intellij-idea'
description = 'Run all enabled IntelliJ IDEA inspections on the entire WALA project'
final ideaDir = file "$rootDir/.idea"
inputs.dir "$ideaDir/scopes"
final inspectionProfile = file "$ideaDir/inspectionProfiles/No_Back_Sliding.xml"
inputs.file inspectionProfile
final textResultsFile = file "$buildDir/${name}.txt"
outputs.file textResultsFile
// Inspections examine a wide variety of files, not just Java
// sources, so this task is out-of-date if nearly any other file has
// changed.
inputs.files fileLister.obtainPartialFileTree()
executable = findProperty('runInspections.IntelliJ-IDEA.command') ?: 'idea'
args 'inspect', rootDir, inspectionProfile, textResultsFile, '-v1', '-format', 'plain'
// The `idea` command above always fails with an
// `IllegalArgumentException` arising from
// `PlainTextFormatter.getPath`. Fortunately, this only happens
// *after* `idea` has already written out the results file. So we
// should ignore that command's exit value, and only fail this task
// if the results file is missing.
ignoreExitValue = true
doLast {
if (!textResultsFile.exists()) {
throw new GradleException("IntelliJ IDEA command failed without creating $textResultsFile.")
}
}
}
tasks.register('checkInspectionResults') {
group = 'intellij-idea'
description = 'Fail if any IntelliJ IDEA inspections produced errors or warnings'
inputs.files runInspections
doFirst {
def failed = false
inputs.files.singleFile.eachLine {
if (it =~ /\[(ERROR|WARNING)]/) {
failed = true
println it
}
}
if (failed) {
throw new GradleException("One or more IntelliJ IDEA inspections failed. See logged problems above, or \"$inputs.files.singleFile\" for full details. WEAK WARNINGs are allowed, but all ERRORs and WARNINGs must be corrected.")
}
}
final stampFile = file("$buildDir/${name}.stamp")
outputs.file stampFile
doLast { stampFile.createNewFile() }
}
////////////////////////////////////////////////////////////////////////
//
// Eclipse IDE integration
//
// workaround for <https://github.com/gradle/gradle/issues/4802>
allprojects {
apply plugin: 'eclipse'
eclipse.classpath.file.whenMerged {
entries.each {
if (it in org.gradle.plugins.ide.eclipse.model.AbstractClasspathEntry && it.entryAttributes['gradle_used_by_scope'] == 'test')
it.entryAttributes['test'] = true
}
}
}
////////////////////////////////////////////////////////////////////////
//
// IntelliJ IDEA IDE integration
//
subprojects { subproject ->
apply plugin: 'idea'
idea.module {
// workaround for <https://youtrack.jetbrains.com/issue/IDEA-140714>
excludeDirs += file('bin')
}
}
////////////////////////////////////////////////////////////////////////
//
// helpers for building native CAst components
//
@SuppressWarnings("unused")
final addCastLibrary(project, recipient) {
recipient.binaries.whenElementFinalized { binary ->
binary.linkTask.get().configure { linkTask ->
project.project(':com.ibm.wala.cast:cast').tasks.named(linkTask.name) { castTask ->
addRpath(linkTask, getNativeLibraryOutput(castTask))
}
}
}
addJvmLibrary(project, recipient)
}
final File findJvmLibrary(extension, currentJavaHome, subdirs) {
return subdirs
.collect { file "$currentJavaHome/$it/libjvm.$extension" }
.find { it.exists() }
}
final addJvmLibrary(project, recipient) {
project.with {
recipient.with {
binaries.whenElementFinalized { binary ->
def libJVM
project.dependencies {
final currentJavaHome = org.gradle.internal.jvm.Jvm.current().javaHome
def osIncludeSubdir
final family = targetMachine.operatingSystemFamily
switch (family) {
case 'linux':
osIncludeSubdir = 'linux'
libJVM = findJvmLibrary('so', currentJavaHome, [
'jre/lib/amd64/server',
'lib/amd64/server',
'lib/server',
])
break
case 'macos':
osIncludeSubdir = 'darwin'
libJVM = findJvmLibrary('dylib', currentJavaHome, [
'jre/lib/server',
'lib/server',
])
break
case 'windows':
osIncludeSubdir = 'win32'
//noinspection GrReassignedInClosureLocalVar
libJVM = file("$currentJavaHome/lib/jvm.lib")
break
default:
throw new TaskInstantiationException("unrecognized operating system family \"$family\"")
}
final jniIncludeDir = "$currentJavaHome/include"
add(binary.includePathConfiguration.name, files(jniIncludeDir, "$jniIncludeDir/$osIncludeSubdir"))
add(binary.linkLibraries.name, files(libJVM))
}
binary.linkTask.get().configure { task ->
addRpath(task, libJVM)
}
}
}
}
}
final addRpath(linkTask, library) {
if (!isWindows) {
linkTask.linkerArgs.add "-Wl,-rpath,$library.parent"
}
}
final getNativeLibraryOutput(task) {
final outputsFiles = task.outputs.files
final parent = outputsFiles[0]
final library = outputsFiles[1]
// on Windows, outputsFiles[2] is DLL
assert parent as String == library.parent
return library
}
////////////////////////////////////////////////////////////////////////
//
// Extra downloads pre-fetcher
//
tasks.register('downloads') {
final allDownloaders = allprojects*.tasks*.withType(VerifiedDownload)
final neededDownloaders = allDownloaders.flatten().findAll {
// not used in typical builds
it.name != 'downloadOcamlJava'
}
inputs.files neededDownloaders
}
////////////////////////////////////////////////////////////////////////
//
// Helpers for dependency locking
//
// this task resolves dependencies in all sub-projects, making it easy to
// generate lockfiles
allprojects {
tasks.register('allDeps', DependencyReportTask) {}
}