Skip to content

Commit

Permalink
Cleanup build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
FirstTimeInForever committed Jul 13, 2023
1 parent 38bcc4b commit 93debc8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 54 deletions.
98 changes: 45 additions & 53 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ plugins {
signing
}

group = "org.jetbrains"
val baseVersion = project.property("version").toString()
version = if (project.property("snapshot")?.toString()?.toBoolean() != false) {
baseVersion.substringBefore("-").split('.').let { (major, minor, patch) ->
"$major.$minor.${patch.toInt() + 1}-SNAPSHOT"
fun Project.obtainProjectVersion(): String {
val baseVersion = property("version").toString()
val isSnapshot = property("snapshot")?.toString()?.toBoolean() != false
if (!isSnapshot) {
return baseVersion
}
} else {
baseVersion
val (major, minor, patch) = baseVersion.substringBefore("-").split('.')
return "$major.$minor.${patch.toInt() + 1}-SNAPSHOT"
}

group = "org.jetbrains"
version = obtainProjectVersion()

repositories {
mavenCentral()
Expand All @@ -34,9 +36,6 @@ kotlin {
all {
kotlinOptions.jvmTarget = "1.8"
}
val main by getting

val test by getting
}

testRuns["test"].executionTask.configure {
Expand All @@ -46,7 +45,7 @@ kotlin {
}
}
js(IR) {
nodejs {}
nodejs()
}
linuxX64()
mingwX64()
Expand All @@ -58,47 +57,45 @@ kotlin {
ios()

sourceSets {
val commonMain by getting {

}
val commonMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val fileBasedTest by creating {
dependsOn(commonTest)
}
val jvmMain by getting {

}
val jvmTest by getting {
dependsOn(fileBasedTest)
}
val jsMain by getting {

}
val jsTest by getting {
dependsOn(fileBasedTest)
}
val nativeMain by creating {
dependsOn(commonMain)
}
listOf("linuxX64", "mingwX64", "macosX64", "macosArm64", "ios", "iosSimulatorArm64",
"watchosSimulatorArm64", "tvosSimulatorArm64").forEach { target ->
getByName("${target}Main").dependsOn(nativeMain)
}

val nativeTest by creating {
dependsOn(fileBasedTest)
}

listOf("linuxX64", "mingwX64", "macosX64", "macosArm64").forEach { target ->
val sourceSet = getByName("${target}Test")
sourceSet.dependsOn(nativeTest)
sourceSet.dependsOn(fileBasedTest)
}
val iosTest by getting {
val nativeSourceSets = listOf(
"linuxX64",
"mingwX64",
"macosX64",
"macosArm64",
"ios",
"iosSimulatorArm64",
"watchosSimulatorArm64",
"tvosSimulatorArm64"
)
for (set in nativeSourceSets) {
named("${set}Main") {
dependsOn(nativeMain)
}
named("${set}Test") {
dependsOn(nativeTest)
dependsOn(fileBasedTest)
}
}
}
}
Expand All @@ -107,7 +104,6 @@ kotlin {
tasks {
register<Test>("performanceTest") {
val testCompilation = kotlin.jvm().compilations["test"]

group = "verification"
testClassesDirs = testCompilation.output.classesDirs
classpath = testCompilation.runtimeDependencyFiles
Expand All @@ -120,27 +116,24 @@ tasks {
}
}


task("downloadCommonmark", type = Exec::class) {
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")
}

task("downloadGfm", type = Exec::class) {
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")
}

task("generateCommonMarkTest", type = Exec::class) {
val generateCommonMarkTest by registering(Exec::class) {
group = "Code Generation"
description = "Generate unit tests for the CommonMark spec"
dependsOn("downloadCommonmark")
dependsOn(downloadCommonmark)
executable("python")
workingDir("commonmark-spec")
args("test/spec_tests.py", "--dump-tests")
Expand All @@ -149,17 +142,16 @@ tasks {
doLast {
val tests = String(output.toByteArray())
generateSpecTest(
tests,
"CommonMarkSpecTest",
"org.intellij.markdown.flavours.commonmark.CommonMarkFlavourDescriptor"
tests,
"CommonMarkSpecTest",
"org.intellij.markdown.flavours.commonmark.CommonMarkFlavourDescriptor"
)
}
}

task("generateGfmTest", type = Exec::class) {
val generateGfmTest by registering(Exec::class) {
group = "Code Generation"
description = "Generate unit tests for the GFM spec"
dependsOn("downloadGfm")
dependsOn(downloadGfm)
executable("python")
workingDir("cmark-gfm/test")
args("spec_tests.py", "--dump-tests")
Expand All @@ -168,21 +160,21 @@ tasks {
doLast {
val tests = String(output.toByteArray())
generateSpecTest(
tests,
"GfmSpecTest",
"org.intellij.markdown.flavours.gfm.GFMFlavourDescriptor"
tests,
"GfmSpecTest",
"org.intellij.markdown.flavours.gfm.GFMFlavourDescriptor"
)
}
}

task("generateAllTests") {
val generateAllTests by registering {
group = "Code Generation"
description = "Generate unit tests for the all markdown specs"
dependsOn("generateCommonMarkTest", "generateGfmTest")
dependsOn(generateCommonMarkTest, generateGfmTest)
}
}

val dokkaOutputDir = project.buildDir.resolve("dokkaHtml")
val dokkaOutputDir: File
get() = project.buildDir.resolve("dokkaHtml")

subprojects {
tasks.withType<DokkaTask> {
Expand Down
1 change: 0 additions & 1 deletion buildSrc/src/main/kotlin/org/jetbrains/publication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ fun Project.configureSonatypePublicationIfNecessary() {
}
}

@Suppress("UnstableApiUsage")
private fun Project.signPublicationsIfKeyPresent(vararg publications: String) {
val signingKeyId = System.getenv("SIGN_KEY_ID")
val signingKey = System.getenv("SIGN_KEY")
Expand Down

0 comments on commit 93debc8

Please sign in to comment.