From 93debc8091f11f6db8863737a6489c6424b516d0 Mon Sep 17 00:00:00 2001 From: Ivan Posti Date: Thu, 13 Jul 2023 14:52:30 +0200 Subject: [PATCH] Cleanup build scripts --- build.gradle.kts | 98 +++++++++---------- .../main/kotlin/org/jetbrains/publication.kt | 1 - 2 files changed, 45 insertions(+), 54 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 1fb9eb1..2e7674c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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() @@ -34,9 +36,6 @@ kotlin { all { kotlinOptions.jvmTarget = "1.8" } - val main by getting - - val test by getting } testRuns["test"].executionTask.configure { @@ -46,7 +45,7 @@ kotlin { } } js(IR) { - nodejs {} + nodejs() } linuxX64() mingwX64() @@ -58,9 +57,7 @@ kotlin { ios() sourceSets { - val commonMain by getting { - - } + val commonMain by getting val commonTest by getting { dependencies { implementation(kotlin("test")) @@ -68,15 +65,9 @@ kotlin { } 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) @@ -84,21 +75,27 @@ kotlin { 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) + } } } } @@ -107,7 +104,6 @@ kotlin { tasks { register("performanceTest") { val testCompilation = kotlin.jvm().compilations["test"] - group = "verification" testClassesDirs = testCompilation.output.classesDirs classpath = testCompilation.runtimeDependencyFiles @@ -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") @@ -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") @@ -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 { diff --git a/buildSrc/src/main/kotlin/org/jetbrains/publication.kt b/buildSrc/src/main/kotlin/org/jetbrains/publication.kt index 7ae027e..db7eb2c 100644 --- a/buildSrc/src/main/kotlin/org/jetbrains/publication.kt +++ b/buildSrc/src/main/kotlin/org/jetbrains/publication.kt @@ -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")