Skip to content

Commit

Permalink
Merge pull request #84 from akuleshov7/feature/build-scripts
Browse files Browse the repository at this point in the history
Changing build scripts for a proper supports of KotlinJS
  • Loading branch information
orchestr7 committed Nov 29, 2021
2 parents 7b56e4d + 999d00c commit 9033a73
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 27 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
push:
tags:
- 'v*'
branches:
- main

env:
PGP_SEC: ${{ secrets.PGP_SEC }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ However, to reduce the scope, ktoml now supports only the following platforms:
- mingwx64
- linuxx64
- macosx64
- js (only for ktoml-core)
- js (only for ktoml-core). Note, that `js(LEGACY)` is [not supported](https://github.com/Kotlin/kotlinx.serialization/issues/1448)

Other platforms could be added later on the demand (just create a corresponding issue) or easily built by users on their machines.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fun Project.configurePublishing() {

// https://kotlinlang.org/docs/mpp-publish-lib.html#avoid-duplicate-publications
// `configureNexusPublishing` adds sonatype publication tasks inside `afterEvaluate`.
rootProject.afterEvaluate {
afterEvaluate {
val publicationsFromMainHost = listOf("jvm", "js", "linuxX64", "kotlinMultiplatform", "metadata")
configure<PublishingExtension> {
publications.matching { it.name in publicationsFromMainHost }.all {
Expand Down
27 changes: 23 additions & 4 deletions ktoml-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import com.akuleshov7.buildutils.configurePublishing
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.getCurrentOperatingSystem
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest

Expand All @@ -9,6 +10,13 @@ plugins {

kotlin {
explicitApi()

js(IR) {
browser()
nodejs()
}

// building jvm task only on windows
jvm {
compilations.all {
kotlinOptions {
Expand All @@ -17,11 +25,14 @@ kotlin {
}
}

js(LEGACY)
val os = getCurrentOperatingSystem()

linuxX64()
mingwX64()
macosX64()
when {
os.isWindows -> mingwX64()
os.isLinux -> linuxX64()
os.isMacOsX -> macosX64()
else -> throw GradleException("Unknown operating system $os")
}

sourceSets {
all {
Expand All @@ -42,6 +53,12 @@ kotlin {
}
}

val jsTest by getting {
dependencies {
implementation(kotlin("test-js"))
}
}

val jvmTest by getting {
dependsOn(commonTest)
dependencies {
Expand All @@ -55,6 +72,8 @@ kotlin {
}
}

configurePublishing()

tasks.withType<KotlinJvmTest> {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ public inline class TomlParser(private val ktomlConf: KtomlConf) {
}
}

private fun String.isTableNode() = "\\[(.*?)]".toRegex().matches(this.trim())
private fun String.isTableNode(): Boolean {
val trimmed = this.trim()
return trimmed.startsWith("[") && trimmed.endsWith("]")
}

private fun String.isComment() = this.trim().startsWith("#")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.akuleshov7.ktoml.KtomlConf
import com.akuleshov7.ktoml.exceptions.InternalAstException
import com.akuleshov7.ktoml.exceptions.TomlParsingException
import com.akuleshov7.ktoml.parsers.splitKeyToTokens
import com.akuleshov7.ktoml.parsers.trimBrackets
import com.akuleshov7.ktoml.parsers.trimQuotes

/**
Expand Down Expand Up @@ -251,13 +252,7 @@ public class TomlTable(

init {
// getting the content inside brackets ([a.b] -> a.b)
val sectionFromContent = "\\[(.*?)]"
.toRegex()
.find(content)
?.groupValues
?.get(1)
?.trim()
?: throw Exception()
val sectionFromContent = content.trim().trimBrackets().trim()

if (sectionFromContent.isBlank()) {
throw TomlParsingException("Incorrect blank table name: $content", lineNo)
Expand Down
22 changes: 11 additions & 11 deletions ktoml-core/src/commonTest/kotlin/decoder/GeneralDecoderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,13 @@ class GeneralDecoderTest {
data class MyTest(val table: Table)

@Serializable
data class Table(val `1`: Inner, val `2`: Inner)
data class Table(val in1: Inner, val in2: Inner)

@Serializable
data class Inner(
val a: Long,
val `1`: InnerInner,
val `2`: InnerInner
val in1: InnerInner,
val in2: InnerInner
)

@Serializable
Expand All @@ -370,25 +370,25 @@ class GeneralDecoderTest {
@Test
fun severalTablesOnTheSameLevel() {
val test = """|[table]
|[table.1]
|[table.in1]
| a = 1
| [table.1.1]
| [table.in1.in1]
| a = 1
| [table.1.2]
| [table.in1.in2]
| a = 1
|[table.2]
|[table.in2]
| a = 1
| [table.2.1]
| [table.in2.in1]
| a = 1
| [table.2.2]
| [table.in2.in2]
| a = 1
""".trimMargin()

assertEquals(
MyTest(
table = Table(
`1` = Inner(a = 1, `1` = InnerInner(a = 1), `2` = InnerInner(a = 1)),
`2` = Inner(a = 1, `1` = InnerInner(a = 1), `2` = InnerInner(a = 1))
in1 = Inner(a = 1, in1 = InnerInner(a = 1), in2 = InnerInner(a = 1)),
in2 = Inner(a = 1, in1 = InnerInner(a = 1), in2 = InnerInner(a = 1))
)
), Toml.decodeFromString(test)
)
Expand Down
3 changes: 3 additions & 0 deletions ktoml-file/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import com.akuleshov7.buildutils.configurePublishing
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.getCurrentOperatingSystem
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest

Expand Down Expand Up @@ -78,6 +79,8 @@ kotlin {
}
}

configurePublishing()

tasks.withType<KotlinJvmTest> {
useJUnitPlatform()
}

0 comments on commit 9033a73

Please sign in to comment.