forked from intellij-rust/intellij-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
347 lines (299 loc) · 11.3 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
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
import org.jetbrains.intellij.tasks.PatchPluginXmlTask
import org.jetbrains.intellij.tasks.PublishTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import de.undercouch.gradle.tasks.download.Download
import org.gradle.api.internal.HasConvention
import org.gradle.api.tasks.SourceSet
import org.jetbrains.grammarkit.tasks.GenerateLexer
import org.jetbrains.grammarkit.tasks.GenerateParser
// since kotlin 1.3-rc `KotlinSourceSet` moved back to `org.jetbrains.kotlin.gradle.plugin` package
import org.jetbrains.kotlin.gradle.plugin.source.KotlinSourceSet
import org.gradle.api.JavaVersion.VERSION_1_8
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.gradle.jvm.tasks.Jar
import java.net.HttpURLConnection
import java.net.URL
import java.nio.file.Path
import kotlin.concurrent.thread
buildscript {
repositories {
maven { setUrl("https://jitpack.io") }
maven { setUrl("https://dl.bintray.com/kotlin/kotlin-eap") }
}
dependencies {
classpath("com.github.hurricup:gradle-grammar-kit-plugin:2018.1.7")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3-M2")
}
}
val CI = System.getenv("CI") != null
val channel = prop("publishChannel")
val platformVersion = prop("platformVersion")
plugins {
idea
id("org.jetbrains.intellij") version "0.3.7"
id("de.undercouch.download") version "3.4.3"
id("net.saliman.properties") version "1.4.6"
}
idea {
module {
// https://github.com/gradle/kotlin-dsl/issues/537/
excludeDirs = excludeDirs + file("testData") + file("deps")
}
}
allprojects {
apply {
plugin("idea")
plugin("kotlin")
plugin("org.jetbrains.grammarkit")
plugin("org.jetbrains.intellij")
}
repositories {
mavenCentral()
maven { setUrl("https://dl.bintray.com/kotlin/kotlin-eap") }
}
idea {
module {
generatedSourceDirs.add(file("src/gen"))
}
}
intellij {
version = prop("ideaVersion")
downloadSources = !CI
updateSinceUntilBuild = true
instrumentCode = false
ideaDependencyCachePath = file("deps").absolutePath
tasks.withType<PatchPluginXmlTask> {
sinceBuild(prop("sinceBuild"))
untilBuild(prop("untilBuild"))
}
}
tasks.withType<PublishTask> {
username(prop("publishUsername"))
password(prop("publishPassword"))
channels(channel)
}
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
languageVersion = "1.2"
apiVersion = "1.2"
}
}
configure<JavaPluginConvention> {
sourceCompatibility = VERSION_1_8
targetCompatibility = VERSION_1_8
}
sourceSets {
getByName("main").java.srcDirs("src/gen")
}
afterEvaluate {
tasks.withType<AbstractTestTask> {
testLogging {
if (hasProp("showTestStatus") && prop("showTestStatus").toBoolean()) {
events = setOf(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
exceptionFormat = TestExceptionFormat.FULL
}
}
}
}
}
val channelSuffix = if (channel.isBlank()) "" else "-$channel"
project(":") {
val clionVersion = prop("clionVersion")
val versionSuffix = "-$platformVersion$channelSuffix"
version = "0.2.0.${prop("buildNumber")}$versionSuffix"
intellij {
pluginName = "intellij-rust"
// alternativeIdePath = "deps/clion-$clionVersion"
setPlugins(project(":intellij-toml"), "IntelliLang")
}
repositories {
maven { setUrl("https://dl.bintray.com/jetbrains/markdown") }
}
dependencies {
compile("org.jetbrains:markdown:0.1.28") {
exclude(module = "kotlin-runtime")
exclude(module = "kotlin-stdlib")
}
}
sourceSets {
getByName("main").kotlin.srcDirs("src/$platformVersion/kotlin")
create("debugger") {
kotlin.srcDirs("debugger/src/main/kotlin", "debugger/src/$platformVersion/kotlin")
compileClasspath += getByName("main").compileClasspath +
getByName("main").output +
files("deps/clion-$clionVersion/lib/clion.jar")
}
}
tasks.withType<Jar> {
from(sourceSets.getByName("debugger").output)
}
val generateRustLexer = task<GenerateLexer>("generateRustLexer") {
source = "src/main/grammars/RustLexer.flex"
targetDir = "src/gen/org/rust/lang/core/lexer"
targetClass = "_RustLexer"
purgeOldFiles = true
}
val generateRustDocHighlightingLexer = task<GenerateLexer>("generateRustDocHighlightingLexer") {
source = "src/main/grammars/RustDocHighlightingLexer.flex"
targetDir = "src/gen/org/rust/lang/doc/lexer"
targetClass = "_RustDocHighlightingLexer"
purgeOldFiles = true
}
val generateRustParser = task<GenerateParser>("generateRustParser") {
source = "src/main/grammars/RustParser.bnf"
targetRoot = "src/gen"
pathToParser = "/org/rust/lang/core/parser/RustParser.java"
pathToPsiRoot = "/org/rust/lang/core/psi"
purgeOldFiles = true
}
val downloadClion = task<Download>("downloadClion") {
onlyIf { !file("${project.projectDir}/deps/clion-$clionVersion.tar.gz").exists() }
src("https://download.jetbrains.com/cpp/CLion-$clionVersion.tar.gz")
dest(file("${project.projectDir}/deps/clion-$clionVersion.tar.gz"))
}
val unpackClion = task<Copy>("unpackClion") {
onlyIf { !file("${project.projectDir}/deps/clion-$clionVersion").exists() }
from(tarTree("deps/clion-$clionVersion.tar.gz"))
into(file("${project.projectDir}/deps"))
dependsOn(downloadClion)
}
tasks.withType<KotlinCompile> {
dependsOn(
generateRustLexer, generateRustDocHighlightingLexer,
generateRustParser, unpackClion
)
}
tasks.withType<Test> {
testLogging {
exceptionFormat = TestExceptionFormat.FULL
}
}
task("resolveDependencies") {
dependsOn(unpackClion)
doLast {
rootProject.allprojects
.map { it.configurations }
.flatMap { listOf(it.compile, it.testCompile) }
.forEach { it.resolve() }
}
}
}
project(":intellij-toml") {
version = "0.2.0.${prop("buildNumber")}$channelSuffix"
val generateTomlLexer = task<GenerateLexer>("generateTomlLexer") {
source = "src/main/grammars/TomlLexer.flex"
targetDir = "src/gen/org/toml/lang/parse"
targetClass = "_TomlLexer"
purgeOldFiles = true
}
val generateTomlParser = task<GenerateParser>("generateTomlParser") {
source = "src/main/grammars/TomlParser.bnf"
targetRoot = "src/gen"
pathToParser = "/org/toml/lang/parse/TomlParser.java"
pathToPsiRoot = "/org/toml/lang/psi"
purgeOldFiles = true
}
tasks.withType<KotlinCompile> {
dependsOn(generateTomlLexer, generateTomlParser)
}
}
task("makeRelease") {
doLast {
val newChangelog = commitChangelog()
val newChangelogPath = newChangelog
.replace(".markdown", "")
.replaceFirst("-", "/").replaceFirst("-", "/").replaceFirst("-", "/")
val pluginXmlPath = "./src/main/resources/META-INF/plugin.xml"
val pluginXml = File(pluginXmlPath)
val oldText = pluginXml.readText()
val newText = oldText.replace(
"""https://intellij-rust\.github\.io/(.*)\.html""".toRegex(),
"https://intellij-rust.github.io/$newChangelogPath.html"
)
pluginXml.writeText(newText)
"git add $pluginXmlPath".execute()
"git commit -m Changelog".execute()
"git push".execute()
commitNightly()
}
}
fun commitChangelog(): String {
val website = "../intellij-rust.github.io"
val lastPost = File("$website/_posts").listFiles()
.map { it.name }
.sorted()
.last()
val postNumber = lastPost.substringAfterLast("-").substringBefore(".").toInt()
"python3 changelog.py -c".execute(website)
"git add _posts/$lastPost".execute(website)
listOf("git", "commit", "-m", "Changelog $postNumber").execute(website)
println()
"git show HEAD".execute(website)
println("Does ^^ look right? Answer `yes` to push changes\n")
val yes = readLine()!!.trim() == "yes"
if (!yes) error("Human says no")
"git push".execute(website)
return lastPost
}
fun commitNightly() {
// TODO: extract the latest versions of all supported platforms
val ideaArtifactName = "$platformVersion-EAP-SNAPSHOT"
val versionUrl = URL("https://www.jetbrains.com/intellij-repository/snapshots/com/jetbrains/intellij/idea/BUILD/$ideaArtifactName/BUILD-$ideaArtifactName.txt")
val ideaVersion = versionUrl.openStream().bufferedReader().readLine().trim()
println("\n NEW IDEA: $ideaVersion\n")
"rustup update nightly".execute()
val version = "rustup run nightly rustc --version".execute()
val date = """\d\d\d\d-\d\d-\d\d""".toRegex().find(version)!!.value
val rustVersion = "nightly-$date"
println("\n NEW RUST: $rustVersion\n")
val travisYml = File(rootProject.projectDir, ".travis.yml")
val updated = travisYml.readLines().joinToString("\n") { line ->
if ("modified by script" in line) {
line.replace("""RUST_VERSION=[\w\-\.]+""".toRegex(), "RUST_VERSION=$rustVersion")
.replace("""ORG_GRADLE_PROJECT_ideaVersion=[\w\-\.]+""".toRegex(), "ORG_GRADLE_PROJECT_ideaVersion=$ideaVersion")
} else {
line
}
}
travisYml.writeText(updated)
"git branch -Df nightly".execute(ignoreExitCode = true)
"git checkout -b nightly".execute()
"git add .travis.yml".execute()
listOf("git", "commit", "-m", ":arrow_up: nightly IDEA & rust").execute()
"git push origin nightly".execute()
}
fun hasProp(name: String): Boolean = extra.has(name)
fun prop(name: String): String =
extra.properties[name] as? String
?: error("Property `$name` is not defined in gradle.properties")
inline operator fun <T : Task> T.invoke(a: T.() -> Unit): T = apply(a)
val SourceSet.kotlin: SourceDirectorySet
get() =
(this as HasConvention)
.convention
.getPlugin(KotlinSourceSet::class.java)
.kotlin
fun SourceSet.kotlin(action: SourceDirectorySet.() -> Unit) =
kotlin.action()
fun String.execute(wd: String? = null, ignoreExitCode: Boolean = false): String =
split(" ").execute(wd, ignoreExitCode)
fun List<String>.execute(wd: String? = null, ignoreExitCode: Boolean = false): String {
val process = ProcessBuilder(this)
.also { pb -> wd?.let { pb.directory(File(it)) } }
.start()
var result = ""
val errReader = thread { process.errorStream.bufferedReader().forEachLine { println(it) } }
val outReader = thread {
process.inputStream.bufferedReader().forEachLine { line ->
println(line)
result += line
}
}
process.waitFor()
outReader.join()
errReader.join()
if (process.exitValue() != 0 && !ignoreExitCode) error("Non-zero exit status for `$this`")
return result
}