forked from metaphori/experiment21-scafi-efc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle.kts
169 lines (149 loc) · 5.56 KB
/
build.gradle.kts
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
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import java.io.ByteArrayOutputStream
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
plugins {
java
scala
id("com.github.johnrengelman.shadow") version "4.0.3"
idea
// kotlin("jvm") version "1.3.50"
}
repositories {
mavenCentral()
}
val alchemistVersion = "9.3.0"
dependencies {
implementation("it.unibo.alchemist:alchemist:$alchemistVersion")
implementation("it.unibo.alchemist:alchemist-incarnation-scafi:$alchemistVersion")
implementation("org.scala-lang:scala-library:2.12.2")
implementation("it.unibo.apice.scafiteam:scafi-core_2.12:0.3.2")
/*
implementation("com.github.cb372:scalacache-guava_2.12:0.9.3")
implementation("org.danilopianini:thread-inheritable-resource-loader:0.3.2")
implementation("org.protelis:protelis-lang:13.0.2")
implementation("org.jgrapht:jgrapht-core:1.3.1")
implementation("org.apache.commons:commons-lang3:3.9")
implementation("com.github.ben-manes.caffeine:caffeine:2.8.0")
implementation(kotlin("stdlib"))
*/
}
tasks.withType<ScalaCompile> {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}
idea {
module {
isDownloadJavadoc = true
isDownloadSources = true
}
}
sourceSets.getByName("main") {
resources {
srcDirs("src/main/protelis")
}
}
// Needed to avoid error:
// > shadow.org.apache.tools.zip.Zip64RequiredException: archive contains more than 65535 entries.
tasks.withType<ShadowJar> {
isZip64 = true
classifier = null
version = null
// baseName = "anotherBaseName"
}
tasks.register<Jar>("fatJar") {
manifest {
attributes(mapOf(
"Implementation-Title" to "Alchemist",
"Implementation-Version" to rootProject.version,
"Main-Class" to "it.unibo.alchemist.Alchemist",
"Automatic-Module-Name" to "it.unibo.alchemist"
))
}
archiveBaseName.set("${rootProject.name}-redist")
isZip64 = true
from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) }) {
// remove all signature files
exclude("META-INF/")
exclude("ant_tasks/")
exclude("about_files/")
exclude("help/about/")
exclude("build")
exclude("out")
exclude("bin")
exclude(".gradle")
exclude("build.gradle.kts")
exclude("gradle")
exclude("gradlew")
exclude("gradlew.bat")
}
with(tasks.jar.get() as CopySpec)
}
fun makeTest(
file: String,
name: String = file,
sampling: Double = 1.0,
time: Double = Double.POSITIVE_INFINITY,
vars: Set<String> = setOf(),
maxHeap: Long? = null,
taskSize: Int = 1024,
threads: Int? = null,
debug: Boolean = false,
effects: String = ""
) {
val heap: Long = maxHeap ?: if (System.getProperty("os.name").toLowerCase().contains("linux")) {
ByteArrayOutputStream()
.use { output ->
exec {
executable = "bash"
args = listOf("-c", "cat /proc/meminfo | grep MemAvailable | grep -o '[0-9]*'")
standardOutput = output
}
output.toString().trim().toLong() / 1024
}
.also { println("${name} >> Detected ${it}MB RAM available.") } * 9 / 10
} else {
// Guess 10GB RAM of which 2 used by the OS
10 * 1024L
}
val threadCount = threads ?: maxOf(1, minOf(Runtime.getRuntime().availableProcessors(), heap.toInt() / taskSize ))
println("${name} has size ${taskSize} and would run on $threadCount threads")
val today = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))
task<JavaExec>("$name") {
dependsOn("build")
classpath = sourceSets["main"].runtimeClasspath
classpath("src/main/protelis")
main = "it.unibo.alchemist.Alchemist"
maxHeapSize = "${heap}m"
jvmArgs("-XX:+AggressiveHeap")
jvmArgs("-XX:-UseGCOverheadLimit")
//jvmArgs("-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap") // https://stackoverflow.com/questions/38967991/why-are-my-gradle-builds-dying-with-exit-code-137
if (debug) {
jvmArgs("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044")
}
File("data").mkdirs()
args(
"-y", "src/main/yaml/${file}.yml",
"-g", "src/main/resources/${effects}.aes",
"-t", "$time",
"-e", "data/${name}", // ${today}-${name}",
"-p", threadCount,
"-i", "$sampling"
)
if (vars.isNotEmpty()) {
args("-b", "-var", *vars.toTypedArray())
}
}
/*tasks {
"runTests" {
dependsOn("$name")
}
}*/
}
makeTest(name="hello", file = "casestudy", time = 10000.0, vars = setOf(), taskSize = 2800, effects = "casestudy")
makeTest(name="channel", file = "channel", effects = "channel")
makeTest(name="g", file = "channel", time = 100.0, vars = setOf("random"), taskSize = 2800)
makeTest(name="casestudy", file = "casestudy", time = 300.0, vars = setOf("random"), taskSize = 2800)
makeTest(name="matrix", file = "casestudy", time = 300.0, vars = setOf("random","commRadius","totalNumOfDevices","moveSpeed","sigmaWarning"), taskSize = 2800)
makeTest(name="kickthetires", file = "casestudy", time = 300.0, vars = setOf("sigmaWarning"), taskSize = 2800)
defaultTasks("fatJar")