forked from JetBrains/markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
239 lines (223 loc) · 7 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
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.configureBintrayPublicationIfNecessary
import org.jetbrains.configureSonatypePublicationIfNecessary
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.registerPublicationFromKotlinPlugin
import org.jetbrains.signPublicationsIfNecessary
import java.io.ByteArrayOutputStream
plugins {
kotlin("multiplatform") apply true
id("org.jetbrains.dokka") apply true
`maven-publish`
signing
}
fun Project.obtainProjectVersion(): String {
val baseVersion = property("version").toString()
val isSnapshot = property("snapshot")?.toString()?.toBoolean() != false
if (!isSnapshot) {
return baseVersion
}
val (major, minor, patch) = baseVersion.substringBefore("-").split('.')
return "$major.$minor.${patch.toInt() + 1}-SNAPSHOT"
}
group = "org.jetbrains"
version = obtainProjectVersion()
repositories {
mavenCentral()
}
kotlin {
targets.all {
compilations.all {
compilerOptions.configure {
languageVersion.set(KotlinVersion.KOTLIN_1_7)
apiVersion.set(KotlinVersion.KOTLIN_1_7)
}
}
}
jvm {
compilations {
all {
kotlinOptions.jvmTarget = "1.8"
}
}
testRuns["test"].executionTask.configure {
useJUnit {
excludeCategories("org.intellij.markdown.ParserPerformanceTest")
}
}
}
js(IR) {
nodejs()
}
linuxX64()
mingwX64()
macosX64()
macosArm64()
iosSimulatorArm64()
watchosSimulatorArm64()
tvosSimulatorArm64()
ios()
sourceSets {
val commonMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val fileBasedTest by creating {
dependsOn(commonTest)
}
val jvmTest by getting {
dependsOn(fileBasedTest)
}
val jsTest by getting {
dependsOn(fileBasedTest)
}
val nativeMain by creating {
dependsOn(commonMain)
}
val nativeTest by creating {
dependsOn(fileBasedTest)
}
val jvmMain by getting {
dependencies {
api("it.unimi.dsi:fastutil-core:8.5.12")
}
}
val nativeSourceSets = listOf(
"linuxX64",
"mingwX64",
"macosX64",
"macosArm64",
"ios",
"iosSimulatorArm64",
"watchosSimulatorArm64",
"tvosSimulatorArm64"
).map { "${it}Main" }
for (set in nativeSourceSets) {
named(set) {
dependsOn(nativeMain)
}
}
val nativeTestSourceSets = listOf(
"linuxX64",
"mingwX64",
"macosX64",
"macosArm64"
).map { "${it}Test" }
for (set in nativeTestSourceSets) {
named(set) {
dependsOn(nativeTest)
dependsOn(fileBasedTest)
}
}
}
}
tasks {
register<Test>("performanceTest") {
val testCompilation = kotlin.jvm().compilations["test"]
group = "verification"
testClassesDirs = testCompilation.output.classesDirs
classpath = testCompilation.runtimeDependencyFiles
dependsOn("compileTestKotlinJvm")
useJUnit {
includeCategories("org.intellij.markdown.ParserPerformanceTest")
}
testLogging {
exceptionFormat = TestExceptionFormat.FULL
}
}
val downloadCommonmark by registering(Exec::class) {
group = "Code Generation"
description = "Clone the CommonMark repo locally"
onlyIf { !File("commonmark-spec").exists() }
executable("git")
args("clone", "https://github.com/commonmark/commonmark-spec")
}
val downloadGfm by registering(Exec::class) {
group = "Code Generation"
description = "Clone the GFM repo locally"
onlyIf { !File("cmark-gfm").exists() }
executable("git")
args("clone", "https://github.com/github/cmark-gfm")
}
val generateCommonMarkTest by registering(Exec::class) {
group = "Code Generation"
description = "Generate unit tests for the CommonMark spec"
dependsOn(downloadCommonmark)
executable("python")
workingDir("commonmark-spec")
args("test/spec_tests.py", "--dump-tests")
val output = ByteArrayOutputStream()
standardOutput = output
doLast {
val tests = String(output.toByteArray())
generateSpecTest(
tests,
"CommonMarkSpecTest",
"org.intellij.markdown.flavours.commonmark.CommonMarkFlavourDescriptor"
)
}
}
val generateGfmTest by registering(Exec::class) {
group = "Code Generation"
description = "Generate unit tests for the GFM spec"
dependsOn(downloadGfm)
executable("python")
workingDir("cmark-gfm/test")
args("spec_tests.py", "--dump-tests")
val output = ByteArrayOutputStream()
standardOutput = output
doLast {
val tests = String(output.toByteArray())
generateSpecTest(
tests,
"GfmSpecTest",
"org.intellij.markdown.flavours.gfm.GFMFlavourDescriptor"
)
}
}
val generateAllTests by registering {
group = "Code Generation"
description = "Generate unit tests for the all markdown specs"
dependsOn(generateCommonMarkTest, generateGfmTest)
}
}
val dokkaOutputDir: File
get() = project.buildDir.resolve("dokkaHtml")
subprojects {
tasks.withType<DokkaTask> {
outputDirectory.set(dokkaOutputDir)
}
}
tasks.register<Jar>("javadocJar") {
dependsOn(":docs:dokkaHtml")
archiveClassifier.set("javadoc")
from(dokkaOutputDir)
}
val publicationsToArtifacts = mapOf(
"kotlinMultiplatform" to "markdown",
"jvm" to "markdown-jvm",
"js" to "markdown-js",
"linuxX64" to "markdown-linuxx64",
"mingwX64" to "markdown-mingwx64",
"macosX64" to "markdown-macosx64",
"macosArm64" to "markdown-macosarm64",
"iosX64" to "markdown-iosx64",
"iosArm64" to "markdown-iosarm64",
"iosSimulatorArm64" to "markdown-iossimulatorarm64",
"watchosSimulatorArm64" to "markdown-watchossimulatorarm64",
"tvosSimulatorArm64" to "markdown-tvossimulatorarm64",
"metadata" to "markdown-metadata"
)
for ((publication, artifact) in publicationsToArtifacts) {
registerPublicationFromKotlinPlugin(publication, artifact)
}
signPublicationsIfNecessary(*publicationsToArtifacts.keys.toTypedArray())
configureSonatypePublicationIfNecessary()
configureBintrayPublicationIfNecessary()
tasks.withType<AbstractPublishToMaven>().configureEach {
val signingTasks = tasks.withType<Sign>()
mustRunAfter(signingTasks)
}