-
Notifications
You must be signed in to change notification settings - Fork 22
/
build.gradle
549 lines (473 loc) · 17.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
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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
import org.apache.commons.io.FileUtils
import org.apache.tools.ant.types.Commandline
import java.nio.file.Files
import static java.nio.file.attribute.PosixFilePermissions.*
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'commons-io:commons-io:2.4'
classpath 'org.apache.ant:ant:1.10.7'
}
}
plugins {
id 'application'
id 'groovy'
id 'java-library'
id 'maven-publish'
//see https://github.com/researchgate/gradle-release
id 'net.researchgate.release' version '2.8.1'
}
// Warning: -Xss is restricted in recent Java versions.
def factGenXmx='12000m'
def factGenStack='1000m'
def defaultFactGenJvmArgs = ["-DmaxHeapSize=${factGenXmx}", "-DstackSize=${factGenStack}"]
// Should the fact generators be linked as normal Java libraries? By
// default this is false, as this integrates many (possibly duplicate
// or incompatible) libraries due to the different front ends.
boolean linkFactGenerators = project.hasProperty('linkFactGenerators') ? project.property('linkFactGenerators') : false
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
group = "org.clyze"
// Doop entry point.
mainClassName = "org.clyze.doop.Main"
// Windows support flag.
def onWindows = System.properties['os.name'].toLowerCase().contains('windows')
if (project.hasProperty('heapDLVersion'))
heapDLVersion = project.property('heapDLVersion')
wrapper {
gradleVersion = "8.7"
}
def allGeneratorProjects = subprojects.findAll { it.name.contains('fact-generator') }
def codeProcessorProject = project(':generators:code-processor')
(allGeneratorProjects + codeProcessorProject).each {
//common configuration for all generator sub-projects
it.with {
apply(plugin: 'java')
group = gradle.rootProject.group
sourceCompatibility = gradle.rootProject.sourceCompatibility
targetCompatibility = gradle.rootProject.targetCompatibility
repositories {
mavenLocal()
mavenCentral()
// maven { url 'https://clyze.jfrog.io/artifactory/default-maven-local' }
// maven {
// url "http://centauri.di.uoa.gr:8081/artifactory/plast-public"
// allowInsecureProtocol true // for Gradle 7 compatibility
// }
}
}
}
// Set variables for subprojects.
gradle.rootProject.ext.resourcesDir='src/main/resources'
gradle.rootProject.ext.testResourcesDir='src/test/resources'
def frontendGeneratorProjects = allGeneratorProjects.findAll { it.name.contains('-fact-generator') }
//all frontends have a fatJar task, which we explicitly (re)define it here, so we can reference it without issues in
//the publishing spec
frontendGeneratorProjects.each { Project p ->
p.with {
version = null
}
// fatJar
p.tasks.register('fatJar', Jar)
p.tasks.fatJar.dependsOn p.tasks.jar
distZip.dependsOn p.tasks.fatJar
// installJar
p.tasks.register('installJar', Copy)
p.tasks.installJar {
from p.tasks.fatJar.outputs.files.singleFile
into p.file("../../${resourcesDir}")
}
p.tasks.installJar.dependsOn p.tasks.fatJar
// uninstallJar
p.tasks.register('uninstallJar')
p.tasks.uninstallJar() {
doLast {
def jar = p.tasks.fatJar.outputs.files.singleFile
if (jar && jar.name) { delete p.file("../../${resourcesDir}/${jar.name}") }
}
}
}
repositories {
mavenLocal()
mavenCentral()
maven { url 'https://jitpack.io' }
// maven { url "http://centauri.di.uoa.gr:8081/artifactory/plast-deps"
// allowInsecureProtocol true
// }
// maven {
// url "http://centauri.di.uoa.gr:8081/artifactory/plast-public"
// allowInsecureProtocol true // for Gradle 7 compatibility
// }
// maven { url 'https://clyze.jfrog.io/artifactory/default-maven-local' }
}
configurations {
apktool {
transitive = false
}
}
configurations.configureEach {
//This is required for SNAPSHOT dependencies
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
//This is required for dependencies using the "+" notation
resolutionStrategy.cacheDynamicVersionsFor 0, 'seconds'
}
compileGroovy {
groovyOptions.optimizationOptions.indy = true
}
// Set dependency version so that they are available to subprojects.
gradle.rootProject.ext.antlrVersion='4.9.1'
gradle.rootProject.ext.commonsCliVersion='1.2'
gradle.rootProject.ext.metadataVersion='2.2.3'
gradle.rootProject.ext.groovyVersion='4.0.21'
gradle.rootProject.ext.clueCommonVersion='3.25.7'
gradle.rootProject.ext.log4jVersion='1.2.17'
gradle.rootProject.ext.spockVersion='2.4-M4-groovy-4.0'
def heapDLVersion = "1.1.18"
dependencies {
// apktool "ext:apktool:2.4.0" // old artifactory dependency
// apktool 'Apktool-fork.brut.apktool:apktool-cli:2.4.2' // artifactory dependency
apktool files('local-dependencies/apktool-cli-2.4.2.jar') // needed for decoding APK inputs
api project(path: ':generators:fact-generator-common', configuration: 'shadow')
api codeProcessorProject
api "com.github.plast-lab:HeapDL:$heapDLVersion"
implementation "org.apache.groovy:groovy:${groovyVersion}", // Groovy
"org.apache.groovy:groovy-ant:${groovyVersion}",
"org.apache.groovy:groovy-cli-commons:${groovyVersion}", // Command line processor (Groovy wrapper)
"commons-logging:commons-logging:1.1", // Logging wrapper
"log4j:log4j:${log4jVersion}", // Logging implementation
"commons-cli:commons-cli:${commonsCliVersion}", // Command line processor
'commons-io:commons-io:2.11.0', // File Utils
"com.github.plast-lab:clue-common:${clueCommonVersion}",
"com.google.guava:guava:33.1.0-jre" // for Scaler
runtimeOnly "org.clyze:jphantom:1.3" // JPhantom is a runtime dependency
testImplementation "org.spockframework:spock-core:${spockVersion}"
}
// If fact generators are linked, mark them as dependencies and set up
// an appropriate environment.
if (linkFactGenerators) {
dependencies {
runtime project(':generators:dex-fact-generator')
runtime project(':generators:soot-fact-generator')
runtime project(':generators:wala-fact-generator')
}
def jvmMemArgs = ["-Xmx${factGenXmx}", "-Xss${factGenStack}"] as List<String>
application {
applicationDefaultJvmArgs = jvmMemArgs
}
test {
jvmArgs jvmMemArgs
}
}
// Otherwise, pass the memory options for Doop to use when invoking fact generators.
else {
application {
applicationDefaultJvmArgs = defaultFactGenJvmArgs
}
}
applicationDistribution.from(file("$projectDir/logic")) {
into 'logic'
}
applicationDistribution.from(file("$projectDir/souffle-logic")) {
into 'souffle-logic'
}
applicationDistribution.from(file("$projectDir/bin")) {
into 'bin'
}
applicationDistribution.from(file("${projectDir}/${resourcesDir}")) {
into resourcesDir
}
applicationDistribution.from(projectDir) {
include 'docs', 'COLLABORATORS', 'LICENSE', 'README.md'
}
def testSubprojects = [ '016-reflection', '104-method-references', '107-lambdas', '115-invokedynamic' ]
testSubprojects.each {
def path = "tests/${it}/build/libs"
applicationDistribution.from(file("$projectDir/${path}")) { into path }
}
String doopCP() {
return String.join(":", sourceSets.main.runtimeClasspath.collect { it.toString() })
}
tasks.register('writeGitCommitHash') {
String hash
if (file('.git').exists()) {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', 'HEAD'
standardOutput = stdout
ignoreExitValue = true
}
hash = stdout.toString().trim()
} else
hash = ''
new File(projectDir, "${resourcesDir}/git-hash.txt").withWriter { w -> w.writeLine(hash) }
}
[jar, run].each { it.dependsOn writeGitCommitHash }
jar {
manifest {
attributes 'Implementation-Version' : archiveVersion.get()
}
}
run {
//debug true
// We set the DOOP_HOME environment variable (see org.clyze.doop.Main)
environment.DOOP_HOME = projectDir
if (project.hasProperty('args')) {
def splitArgs = Commandline.translateCommandline(project.property('args'))
args splitArgs
}
}
// Auxiliary task to print the environment variable needed for
// isolated execution of Soot-based front end.
tasks.register('printExtClasspath') {
doLast {
println(doopCP())
}
}
tasks.register('zipper', JavaExec) {
description 'Run Zipper'
group = 'Doop'
main = 'ptatoolkit.zipper.doop.Main'
classpath = sourceSets.main.runtimeClasspath.filter {
!it.name.startsWith("scaler")
}
if (project.hasProperty("args"))
args project.property("args").split()
//jvmArgs = ['-Xmx=48g']
}
tasks.register('soot', JavaExec) {
description 'Run Soot front-end'
group = 'Doop'
main = 'org.clyze.doop.soot.Main$Standalone'
classpath = sourceSets.main.runtimeClasspath
if (project.hasProperty("args"))
args project.property("args").split()
//jvmArgs = ['-Xmx=48g']
}
tasks.register('souffleScript', JavaExec) {
description 'Run a custom Souffle script'
group = 'Doop'
main = 'org.clyze.doop.utils.SouffleScriptMain'
classpath = sourceSets.main.runtimeClasspath
if (project.hasProperty("args"))
args project.property("args").split()
}
tasks.register('xtractor', JavaExec) {
// We set the DOOP_HOME environment variable (see org.clyze.doop.Main)
environment.DOOP_HOME = projectDir
description 'Run xTractor logic'
group = 'Doop'
main = 'org.clyze.doop.utils.XTractor'
classpath = sourceSets.main.runtimeClasspath
if (project.hasProperty("args"))
args project.property("args").split()
}
def testNames = new File(this.projectDir, "src/inputTests").list()
sourceSets {
testNames.each { t -> "$t" { java { srcDirs = ["src/inputTests/$t"] } } }
}
testNames.each {name ->
task "${name}JAR"(type:Jar, dependsOn: "${name}Classes") {
group = 'other'
from sourceSets.getByName(name).output.classesDirs
archiveFileName.set("${name}.jar")
manifest { attributes 'Main-Class': "A" }
xtractor.dependsOn it
}
}
tasks.register('createEmptyProperties') {
doLast {
def urls = sourceSets.main.runtimeClasspath.files.collect { it.toURI().toURL() } as URL[]
def classloader = new URLClassLoader(urls, null as ClassLoader)
Class
.forName("org.clyze.doop.CommandLineAnalysisFactory", true, classloader)
.createEmptyProperties(new File("empty.properties"))
}
}
tasks.register('resolveApktool') {
doLast {
copy {
from configurations.apktool.files[0]
into "${projectDir}/${resourcesDir}"
}
}
}
compileJava {
options.compilerArgs << '-Xlint:unchecked'
}
test {
useJUnitPlatform()
// failFast = true
maxParallelForks = 1
// forkEvery = 1
jvmArgs(['-DreservedCodeCacheSize=1g'] + defaultFactGenJvmArgs)
testLogging {
exceptionFormat = 'full'
}
environment.DOOP_HOME = projectDir
File tmpDir = new File(getTmpDir())
tmpDir.mkdirs() // needed for 'clean' targets
java.nio.file.Path lbTestHomeDir = Files.createTempDirectory(tmpDir.toPath(), 'lb-test-home-dir', onWindows ? ([] as java.nio.file.attribute.FileAttribute[]) : asFileAttribute(fromString("rwxrwxrwx")))
environment.HOME = lbTestHomeDir.toString()
}
// Workaround from https://stackoverflow.com/questions/4597850/gradle-build-without-tests/4600845#4600845
// since "./gradlew release -x test" may be broken in recent Gradle releases.
test.onlyIf { ! Boolean.getBoolean('skip.tests') }
// Copy resources to src/test/resources or they will not be found by tests.
tasks.register('copyResourcesForTest') {
doLast {
copy {
from file(resourcesDir)
into testResourcesDir
}
}
}
tasks.register('buildTests') {
description 'Build test subprojects.'
}
testSubprojects.each { buildTests.dependsOn("tests:${it}:jar") }
test.dependsOn buildTests
tasks.register('testAll', Test) {}
testAll.dependsOn test
// Task that configures installing/cleaning resources.
tasks.register('resourceInstaller') {}
resourceInstaller.dependsOn resolveApktool
frontendGeneratorProjects.collect { it.name }.each { fg ->
resourceInstaller.dependsOn(":generators:${fg}:installJar")
clean.dependsOn(":generators:${fg}:uninstallJar")
testAll.dependsOn(":generators:${fg}:test")
}
processResources.dependsOn resourceInstaller
// Ensure that all resources have been built before trying to copy them.
copyResourcesForTest.dependsOn resourceInstaller
test.dependsOn copyResourcesForTest
tasks.register('cleanTestResources') {
doLast {
file(resourcesDir).eachFileRecurse { File f ->
if (f.file) {
File testResource = new File(file(testResourcesDir), f.name)
if (testResource.exists())
FileUtils.deleteQuietly(testResource)
}
}
}
}
clean.dependsOn cleanTestResources
def getTmpDir() { return System.getenv('DOOP_TMP') ?: "$projectDir/tmp" }
tasks.register('fullClean') {
description 'Clean everything, including caches and analysis results.'
doLast {
def out = System.getenv('DOOP_OUT') ?: "$projectDir/out"
def cache = System.getenv('DOOP_CACHE') ?: "$projectDir/cache"
def tmp = getTmpDir()
file(out).list().each { f -> delete "$out/$f" }
file(cache).list().each { f -> delete "$cache/$f" }
file(tmp).list().each { f -> delete "$tmp/$f" }
file('results').list().each { f -> delete "results/$f" }
FileUtils.deleteQuietly(new File('last-analysis'))
}
}
fullClean.dependsOn clean
tasks.register('printRuntimeClasspath') {
def runtimeClasspath = sourceSets.main.runtimeClasspath
inputs.files( runtimeClasspath )
doLast {
println runtimeClasspath.asPath
}
}
tasks.register('sourcesJar', Jar) {
dependsOn classes
archiveClassifier.set('sources')
from sourceSets.main.allSource
exclude("*.jar")
}
tasks.register('javadocJar', Jar) {
dependsOn javadoc
archiveClassifier.set('javadoc')
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
// Make publishing tasks trigger subproject builds.
Closure shadowDep = { Task it ->
it.dependsOn(':generators:fact-generator-common:shadowJar')
it.dependsOn(':generators:code-processor:jar')
}
tasks.withType(PublishToMavenRepository).configureEach { shadowDep(it) }
tasks.withType(PublishToMavenLocal).configureEach { shadowDep(it) }
// if (project.hasProperty('artifactory_user')) {
// // Generate a jar with all the logic files
// tasks.register('logicFilesJar', Jar) {
// into('souffle-logic') { from "souffle-logic" }
// }
// publishing {
// publications {
// mavenJava(MavenPublication) {
// from components.java
// artifact tasks.sourcesJar
// artifact tasks.javadocJar
// artifact logicFilesJar {
// archiveClassifier.set( "logic-files")
// }
// }
// // Publish fact-generator-common and code-processor.
// [[project(':generators:fact-generator-common'), "fact-generator-common-${version}-all.jar"],
// [codeProcessorProject, "code-processor-${version}.jar"]]
// .forEach { List l ->
// Project p = l[0]
// create(p.name, MavenPublication) {
// // The artifact generator can be a file or a Gradle task
// def artifactGenerator = p.file('build/libs/' + l[1])
// artifact(artifactGenerator) {
// groupId 'org.clyze'
// artifactId p.name
// }
// }
// }
// }
// repositories {
// maven {
// credentials {
// username artifactory_user
// password artifactory_password
// }
// url "$artifactory_contextUrl/libs-public-release-local"
// allowInsecureProtocol true
// }
// }
// }
// release {
// failOnSnapshotDependencies = false
// git {
// commitVersionFileOnly = true
// }
// }
// afterReleaseBuild.dependsOn publish
// tasks.release.doLast {
// println "WARNING: Tag may not be pushed upstream, please use:"
// println "WARNING: git remote add upstream <UPSTREAM_REPO>"
// println "WARNING: git push upstream <TAG>"
// }
// }
/* Handy for debugging task dependencies
gradle.taskGraph.whenReady {taskGraph ->
println "Found task graph: " + taskGraph
println "Found " + taskGraph.allTasks.size() + " tasks."
taskGraph.allTasks.forEach { task ->
println task
task.dependsOn.forEach { dep ->
println " - " + dep
}
}
}
*/