-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbuild.gradle.kts
184 lines (149 loc) · 4.84 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import org.gradle.kotlin.dsl.support.uppercaseFirstChar
plugins {
java
`maven-publish`
}
group = "cc.tweaked"
version = "0.9.5"
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
withSourcesJar()
}
repositories {
mavenCentral()
}
val buildTools by configurations.creating {
isCanBeConsumed = false
isCanBeResolved = true
}
val checkerFramework by configurations.creating {
isCanBeConsumed = false
isCanBeResolved = true
}
dependencies {
compileOnly(libs.checkerFramework.qual)
"checkerFramework"(libs.checkerFramework)
testCompileOnly(libs.checkerFramework.qual)
testImplementation(libs.bundles.test)
testRuntimeOnly(libs.bundles.testRuntime)
testAnnotationProcessor(libs.bundles.testAnnotationProcessor)
"buildTools"(project(":build-tools"))
}
/**
* Create a task which runs checker framework against our source code.
*
* This runs separately from the main compile task, allowing us to run checker framework multiple times with different
* options.
*/
fun runCheckerFramework(name: String, args: List<String>) {
val sourceSet = sourceSets.main.get()
val runCheckerFramework = tasks.register("checker${name.uppercaseFirstChar()}", JavaCompile::class) {
description = "Runs CheckerFramework against the $name sources."
group = LifecycleBasePlugin.VERIFICATION_GROUP
javaCompiler = javaToolchains.compilerFor(java.toolchain)
source = sourceSet.java
classpath = sourceSets.main.get().compileClasspath
destinationDirectory = layout.buildDirectory.dir("classes/java/${sourceSet.name}Doubles")
options.annotationProcessorPath = checkerFramework
options.compilerArgs.add("-proc:only")
options.compilerArgs.addAll(args)
options.isFork = true
options.forkOptions.jvmArgs!!.addAll(
listOf(
"--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
),
)
}
tasks.check { dependsOn(runCheckerFramework) }
}
runCheckerFramework(
"doubles",
listOf(
"-processor", "org.checkerframework.checker.signedness.SignednessChecker",
"""-AonlyDefs=^cc\.tweaked\.cobalt\.internal\.doubles\.""",
),
)
runCheckerFramework(
"nonNull",
listOf(
"-processor", "org.checkerframework.checker.nullness.NullnessChecker",
"""-AonlyDefs=^cc\.tweaked\.cobalt\.""",
),
)
// Point compileJava to emit to classes/uninstrumentedJava/main, and then add a task to instrument these classes,
// saving them back to the the original class directory. This is held together with so much string :(.
val mainSource = sourceSets.main.get()
val javaClassesDir = mainSource.java.classesDirectory.get()
val untransformedClasses = project.layout.buildDirectory.dir("classes/uninstrumentedJava/main")
val instrumentJava = tasks.register(mainSource.getTaskName("Instrument", "Java"), JavaExec::class) {
dependsOn(tasks.compileJava, "cleanInstrumentJava")
inputs.dir(untransformedClasses).withPropertyName("inputDir")
outputs.dir(javaClassesDir).withPropertyName("outputDir")
javaLauncher = javaToolchains.launcherFor(java.toolchain)
mainClass = "cc.tweaked.cobalt.build.MainKt"
classpath = buildTools
args = listOf(
untransformedClasses.get().asFile.absolutePath,
javaClassesDir.asFile.absolutePath,
)
}
mainSource.compiledBy(instrumentJava)
tasks.compileJava {
destinationDirectory = untransformedClasses
finalizedBy(instrumentJava)
}
publishing {
publications {
register<MavenPublication>("maven") {
from(components["java"])
pom {
name = "Cobalt"
description = "A reentrant fork of LuaJ for Lua 5.2"
url = "https://github.com/cc-tweaked/Cobalt"
scm {
url = "https://github.com/cc-tweaked/Cobalt.git"
}
issueManagement {
system = "github"
url = "https://github.com/cc-tweaked/Cobalt/issues"
}
licenses {
license {
name = "MIT"
url = "https://github.com/cc-tweaked/Cobalt/blob/master/LICENSE"
}
}
}
}
}
repositories {
maven("https://maven.squiddev.cc") {
name = "SquidDev"
credentials(PasswordCredentials::class)
}
}
}
tasks.withType(JavaCompile::class) {
options.compilerArgs.add("-Xlint")
}
tasks.test {
useJUnitPlatform()
testLogging {
events("skipped", "failed")
}
}
val benchmark by tasks.registering(JavaExec::class) {
description = "Run our benchmarking suite"
classpath(sourceSets.test.map { it.runtimeClasspath })
mainClass = "cc.tweaked.cobalt.benchmark.BenchmarkFull"
}