-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
456 lines (388 loc) · 12.5 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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
////////////////////////////////////////////////////////////////////////
//
// plugin configuration must precede everything else
//
buildscript {
dependencies.classpath 'commons-io:commons-io:2.11.0'
// lock all dependencies
configurations.classpath {
resolutionStrategy.activateDependencyLocking()
}
}
plugins {
id 'com.diffplug.eclipse.mavencentral' version '3.31.0' 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.1.1'
}
repositories {
// to get the google-java-format jar and dependencies
mavenCentral()
}
ext.osName = System.getProperty('os.name')
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
ext.eclipseVersion = '4.14.0'
ext.eclipseWstJsdtVersion = '1.0.201.v2010012803'
subprojects { subproject ->
// skip generic Java setup for the few projects that have no Java code whatsoever
switch (subproject.name) {
case 'cast':
case 'smoke_main':
case 'xlator_test':
case 'com.ibm.wala-repository':
case ~/.*_feature/:
return
}
apply plugin: 'eclipse'
apply plugin: 'java-library'
apply plugin: 'java-test-fixtures'
apply plugin: 'maven-publish'
apply plugin: 'signing'
java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8
version rootProject.version
repositories {
mavenCentral()
// to get r8
maven {
url 'https://storage.googleapis.com/r8-releases/raw'
}
}
dependencies.constraints {
[
'org.eclipse.platform:org.eclipse.core.resources',
'org.eclipse.platform:org.eclipse.equinox.common',
].forEach {
implementation(it) {
version { strictly '(,3.15)' }
because 'Versions 3.15 and later of this artifact require Java 11.'
}
}
implementation('org.eclipse.platform:org.eclipse.core.commands') {
version { strictly '(,3.9.800)' }
because 'Versions 3.10.0 and later of this artifact require Java 11.'
}
}
configurations {
implementation {
// See https://github.com/wala/WALA/issues/823. This group was renamed to
// net.java.dev.jna. The com.sun.jna dependency is only pulled in from
// com.ibm.wala.ide.* projects. Since we only try to compile those projects from
// Gradle, but not run them, excluding the group as a dependence is a reasonable
// solution.
exclude group: 'com.sun.jna'
}
}
eclipse {
synchronizationTasks 'processTestResources'
}
tasks.named('test') {
include '**/*Test.class'
include '**/*TestCase.class'
include '**/*Tests.class'
include '**/Test*.class'
exclude '**/*AndroidLibs*.class'
if (project.hasProperty('excludeSlowTests')) {
dependencies {
testRuntimeOnly testFixtures(project(':com.ibm.wala.core'))
}
useJUnit {
excludeCategories 'com.ibm.wala.tests.util.SlowTests'
}
}
if (project.hasProperty('trial')) {
outputs.upToDateWhen { false }
afterTest { descriptor, result ->
def csv = new File("$rootProject.buildDir/time-trials.csv")
if (!csv.exists()) {
csv.append('trial,className,name,resultType,startTime,endTime\n')
}
csv.append("$trial,$descriptor.className,$descriptor.name,$result.resultType,$result.startTime,$result.endTime\n")
}
} else {
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
}
}
final ecjCompileTaskProviders = sourceSets.collect { sourceSet ->
JavaCompileUsingEcj.withSourceSet(subproject, sourceSet)
}
project.tasks.named('check').configure {
dependsOn ecjCompileTaskProviders
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}
// Special hack for WALA as an included build. Composite
// builds only build and use artifacts from the default
// configuration of included builds:
// <https://docs.gradle.org/current/userguide/composite_builds.html#included_build_substitution_limitations>.
// This known limitation makes WALA test fixtures unavailable
// when WALA is included in a composite build. As a
// workaround for composite projects that rely on those test
// fixtures, we extend the main sourceSet to include all
// test-fixture sources too. This hack is only applied when
// WALA itself is an included build.
if (project.gradle.parent != null) {
afterEvaluate {
sourceSets {
main.java.srcDirs testFixtures.java.srcDirs
}
dependencies {
implementation configurations.testFixturesImplementation.dependencies
}
}
}
// lock all dependencies for now (buildscript deps are locked at the top of
// this file); we can relax the policy in the future if needed
dependencyLocking {
lockAllConfigurations()
// SWT packages vary by operating system, and lockfiles are not expressive enough
// to handle that. So, ignore those dependencies for purposes of locking.
ignoredDependencies.add('org.eclipse.platform:org.eclipse.swt.*')
}
}
///////////////////////////////////////////////////////////////////////
//
// Javadoc documentation
//
allprojects {
tasks.withType(Javadoc).configureEach {
options.addBooleanOption('Xdoclint:all,-missing', true)
options.encoding = 'UTF-8'
options.quiet()
options.tags += "apiNote:a:API Note:"
}
}
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
//
// Gradle build scripts
// disabled until <https://github.com/gradle/gradle/issues/6246> is fixed
/*
allprojects {
apply plugin: 'nebula.lint'
gradleLint.alwaysRun = false
gradleLint {
rules = ['all-dependency']
excludedRules = [
// <https://github.com/nebula-plugins/gradle-lint-plugin/issues/203>
'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 = ''
}
}
// 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
}
////////////////////////////////////////////////////////////////////////
//
// 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) {}
}