-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathbuild.gradle.kts
176 lines (146 loc) · 4.99 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
import at.phatbl.shellexec.ShellExec
import java.io.File
import java.net.URI
import java.util.regex.Pattern
plugins {
idea
id("org.jetbrains.intellij") version "1.6.0"
antlr
`maven-publish`
kotlin("jvm")
id("at.phatbl.shellexec")
}
group = "org.jetbrains.kotlin.spec.grammar"
version = "0.1"
val archivePrefix = "kotlin-grammar-parser"
repositories {
maven {
url = URI("https://maven.apal-research.com")
}
mavenCentral()
}
publishing {
publications {
create<MavenPublication>("maven") {
groupId = group as String
artifactId = archivePrefix
version = version as String
from(components["java"])
}
}
}
sourceSets {
main {
java.srcDir("src/main")
}
test {
java.srcDir("src/test")
}
}
dependencies {
implementation("junit:junit:4.13.2")
antlr("org.antlr:antlr4:4.8")
}
tasks.compileKotlin {
dependsOn("generateGrammarSource")
}
intellij {
version.set("IC-2022.1")
}
tasks.withType<AntlrTask> {
outputDirectory =
File("${project.rootDir}/grammar/src/main/java/org/jetbrains/kotlin/spec/grammar").also { it.mkdirs() }
arguments.add("-package")
arguments.add("org.jetbrains.kotlin.spec.grammar")
}
tasks.create("removeFailedMarkerFiles") {
doFirst {
File("${project.rootDir}/${project.name}/testData")
.walkTopDown()
.filter { it.isFile && it.extension == "failed" }
.forEach { it.delete() }
}
}
tasks.withType<Test> {
dependsOn("removeFailedMarkerFiles")
workingDir = File("${project.rootDir}/${project.name}")
ignoreFailures = project.hasProperty("teamcity")
systemProperties["TEST_PATH_FILTER"] = System.getProperty("TEST_PATH_FILTER")
}
tasks.create("removeCompilerTestData") {
doFirst {
File("${project.rootDir}/${project.name}/testData").walkTopDown().forEach {
if (!it.name.endsWith("antlrtree.txt"))
it.delete()
}
}
}
tasks.create<ShellExec>("downloadCompilerTests") {
doFirst {
workingDir = File("$projectDir")
command = File("$projectDir/scripts/build/downloadCompilerTests.sh").readText()
}
}
tasks.create("syncWithCompilerTests") {
doFirst {
File("${project.rootDir}/${project.name}/testData").walkTopDown().forEach {
if (it.name.endsWith("antlrtree.txt") && !File("${it.parent}/${it.name.substringBefore(".antlrtree.txt")}.kt").exists())
it.delete()
}
}
}
tasks.create("prepareDiagnosticsCompilerTests") {
doFirst {
//language=RegExp
val individualDiagnostic = """[^!,]*"""
val rangeStartOrEndPattern = Pattern.compile("(<!(([^>])|((?<!\\!)\\>))+!>)|(<!>)")
val filePattern = Pattern.compile("""// ?FILE: ?""")
val ls = System.lineSeparator()
val sourceCodeByFilePattern =
Pattern.compile("""^(?<filename>.*?)\.(?<extension>kts?|java)($ls)*(?<code>[\s\S]*)$""")
File("${project.rootDir}/${project.name}/testData/diagnostics").walkTopDown().forEach {
println("Processing file $it")
if (it.name.endsWith(".fir.kt")) {
it.delete()
} else if (it.extension == "kt") {
val sourceCode = it.readText()
val sourceCodeByFiles = sourceCode.split(filePattern)
if (sourceCodeByFiles.size > 1) {
sourceCodeByFiles.forEachIndexed { index, content ->
if (index == 0)
return@forEachIndexed
val matcher = sourceCodeByFilePattern.matcher(content).apply { find() }
val filename = matcher.group("filename").replace("/", "_")
val extension = matcher.group("extension")
val code = matcher.group("code")
if (extension == "kt" || extension == "kts")
File("${it.parent}/${it.nameWithoutExtension}.$filename.$extension").writeText(
rangeStartOrEndPattern.matcher(code).replaceAll("")
)
}
it.delete()
} else {
it.writeText(rangeStartOrEndPattern.matcher(it.readText()).replaceAll(""))
}
} else if (!it.name.endsWith("antlrtree.txt")) {
it.delete()
}
}
}
}
val instrumentTestCodeTask = tasks.named("instrumentTestCode")
tasks.named("inspectClassesForKotlinIC") {
dependsOn(instrumentTestCodeTask)
}
tasks.withType<Jar> {
dependsOn(instrumentTestCodeTask)
archiveFileName.set("$archivePrefix-${archiveVersion.get()}.jar")
manifest {
attributes(
mapOf(
"Class-Path" to configurations.runtimeClasspath.get().files.joinToString(" ") { it.name }
)
)
}
from(configurations.runtimeClasspath.get().files.map { if (it.isDirectory) it else zipTree(it) })
}