forked from satamas/fortran-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
219 lines (183 loc) · 6.58 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
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.GrammarKitPluginExtension
import org.jetbrains.grammarkit.tasks.GenerateLexer
import org.jetbrains.grammarkit.tasks.GenerateParser
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.gradle.api.JavaVersion.VERSION_1_8
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.jvm.tasks.Jar
import org.jetbrains.intellij.tasks.PrepareSandboxTask
import java.net.HttpURLConnection
import java.net.URL
import java.nio.file.Path
import kotlin.concurrent.thread
buildscript {
repositories {
maven { setUrl("https://jitpack.io") }
}
dependencies {
classpath("com.github.hurricup:gradle-grammar-kit-plugin:2017.1.1")
}
}
val CI = System.getenv("CI") != null
plugins {
idea
kotlin("jvm") version "1.1.4"
id("org.jetbrains.intellij") version "0.2.17"
id("de.undercouch.download") version "3.2.0"
}
idea {
module {
excludeDirs = excludeDirs + file("testData") + file("deps")
}
}
allprojects {
apply {
plugin("idea")
plugin("kotlin")
plugin("org.jetbrains.grammarkit")
plugin("org.jetbrains.intellij")
}
repositories {
mavenCentral()
}
idea {
module {
generatedSourceDirs.add(file("src/gen"))
}
}
intellij {
version = prop("ideaVersion")
downloadSources = !CI
updateSinceUntilBuild = false
instrumentCode = false
ideaDependencyCachePath = file("deps").absolutePath
}
configure<GrammarKitPluginExtension> {
grammarKitRelease = "1.5.2"
}
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
languageVersion = "1.1"
apiVersion = "1.1"
}
}
configure<JavaPluginConvention> {
sourceCompatibility = VERSION_1_8
targetCompatibility = VERSION_1_8
}
java.sourceSets {
getByName("main").java.srcDirs("src/gen")
}
}
project(":") {
val clionVersion = prop("clionVersion")
intellij {
pluginName = "fortran-plugin"
alternativeIdePath = "debugger/lib/clion-$clionVersion"
}
java.sourceSets {
create("debugger") {
kotlin.srcDirs("debugger/src/main/kotlin")
compileClasspath += getByName("main").compileClasspath +
getByName("main").output +
files("debugger/lib/clion-$clionVersion/lib/clion.jar")
}
}
tasks.withType<Jar> {
from(java.sourceSets.getByName("debugger").output)
}
val generateFortranLexer = task<GenerateLexer>("generateFortranLexer") {
source = "src/main/kotlin/org/jetbrains/fortran/lang/lexer/FortranLexer.flex"
targetDir = "src/gen/org/jetbrains/fortran/lang/lexer"
targetClass = "_FortranLexer"
purgeOldFiles = true
}
val generateFortranParser = task<GenerateParser>("generateFortranParser") {
source = "src/main/kotlin/org/jetbrains/fortran/lang/parser/FortranParser.bnf"
targetRoot = "src/gen"
pathToParser = "/org/jetbrains/fortran/lang/parser/FortranParser.java"
pathToPsiRoot = "/org/jetbrains/fortran/lang/psi"
purgeOldFiles = true
}
val isWindows = System.getProperty("os.name").toLowerCase().indexOf( "win" ) >= 0
val downloadClion = task<Download>("downloadClion") {
if (isWindows) {
onlyIf { !file("${project.projectDir}/debugger/lib/clion-$clionVersion.zip").exists() }
src("https://download.jetbrains.com/cpp/CLion-$clionVersion.zip")
dest(file("${project.projectDir}/debugger/lib/clion-$clionVersion.zip"))
} else {
onlyIf { !file("${project.projectDir}/debugger/lib/clion-$clionVersion.tar.gz").exists() }
src("https://download.jetbrains.com/cpp/CLion-$clionVersion.tar.gz")
dest(file("${project.projectDir}/debugger/lib/clion-$clionVersion.tar.gz"))
}
}
val unpackClion = task<Copy>("unpackClion") {
if (isWindows) {
onlyIf { !file("${project.projectDir}/debugger/lib/clion-$clionVersion").exists() }
from(zipTree("debugger/lib/clion-$clionVersion.zip"))
into(file("${project.projectDir}/debugger/lib/clion-$clionVersion"))
} else {
onlyIf { !file("${project.projectDir}/debugger/lib/clion-$clionVersion").exists() }
from(tarTree("debugger/lib/clion-$clionVersion.tar.gz"))
into(file("${project.projectDir}/debugger/lib/"))
}
dependsOn(downloadClion)
}
tasks.withType<KotlinCompile> {
dependsOn(
generateFortranLexer, generateFortranParser, 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() }
}
}
}
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
}