diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 47049b6e..6d97cd85 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ macOS-latest, windows-latest, ubuntu-latest ] + os: [ windows-latest ] runs-on: ${{matrix.os}} steps: - name: Checkout the repo @@ -29,19 +29,12 @@ jobs: with: msystem: MINGW64 update: true - install: git mingw-w64-x86_64-toolchain libsqlite + install: mingw-w64-x86_64-sqlite3 + release: false - name: Setup Gradle uses: gradle/actions/setup-gradle@v6 - - name: Cache konan - uses: actions/cache@v4 - with: - path: ~/.konan - key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }} - restore-keys: | - ${{ runner.os }}-gradle- - - name: Update Environment Variables if: matrix.os == 'windows-latest' shell: bash diff --git a/sqliter-driver/build.gradle.kts b/sqliter-driver/build.gradle.kts index 0f9ec9aa..a892ff72 100644 --- a/sqliter-driver/build.gradle.kts +++ b/sqliter-driver/build.gradle.kts @@ -83,11 +83,14 @@ mavenPublishing { publishToMavenCentral(automaticRelease = true) } -listOf( - "linuxX64Test", - "linuxArm64Test", - "linkDebugTestLinuxX64", - "linkDebugTestLinuxArm64", - "mingwX64Test", - "linkDebugTestMingwX64", -).forEach { tasks.findByName(it)?.enabled = false } +val disabledTestLinks = mutableListOf("linkDebugTestLinuxArm64") + +if (!HostManager.hostIsLinux) { + disabledTestLinks += "linkDebugTestLinuxX64" +} + +if (!HostManager.hostIsMingw) { + disabledTestLinks += "linkDebugTestMingwX64" +} + +disabledTestLinks.forEach { tasks.findByName(it)?.enabled = false } diff --git a/sqliter-driver/src/mingwMain/kotlin/co/touchlab/sqliter/internal/File.kt b/sqliter-driver/src/mingwMain/kotlin/co/touchlab/sqliter/internal/File.kt index 59b9141c..af4d3c16 100644 --- a/sqliter-driver/src/mingwMain/kotlin/co/touchlab/sqliter/internal/File.kt +++ b/sqliter-driver/src/mingwMain/kotlin/co/touchlab/sqliter/internal/File.kt @@ -71,7 +71,8 @@ internal actual class File(dirPath:String? = null, name:String) { */ constructor(dir: File, name: String) : this(dir.path, name) - // Removes duplicate adjacent back slashes and any trailing back slashes. + // Removes duplicate adjacent separators and any trailing separator. Windows accepts either + // slash direction, so both count as separators and are normalized to [separatorChar]. private fun fixSlashes(origPath: String): String { // Remove duplicate adjacent slashes. var lastWasSlash = false @@ -81,7 +82,7 @@ internal actual class File(dirPath:String? = null, name:String) { val initialIndex = if (origPath.startsWith("file://", true)) 7 else 0 for (i in initialIndex until length) { val ch = newPath[i] - if (ch == separatorChar) { + if (isSeparator(ch)) { if (!lastWasSlash) { newPath[newLength++] = separatorChar lastWasSlash = true @@ -97,21 +98,24 @@ internal actual class File(dirPath:String? = null, name:String) { newLength-- } - // Reuse the original string if possible. - return if (newLength != length) buildString(newLength) { + // Always rebuild. An unchanged length doesn't mean an unchanged string here, as forward + // slashes are rewritten in place without shortening the path. + return buildString(newLength) { append(newPath) setLength(newLength) - } else origPath + } } + private fun isSeparator(ch: Char): Boolean = ch == '/' || ch == '\\' + /** * Returns the combination of the prefix and suffix with a back slash added if necessary. */ private fun join(prefix: String, suffix: String): String { val prefixLength = prefix.length - var haveSlash = prefixLength > 0 && prefix[prefixLength - 1] == separatorChar + var haveSlash = prefixLength > 0 && isSeparator(prefix[prefixLength - 1]) if (!haveSlash) { - haveSlash = suffix.isNotEmpty() && suffix[0] == separatorChar + haveSlash = suffix.isNotEmpty() && isSeparator(suffix[0]) } return if (haveSlash) prefix + suffix else prefix + separatorChar + suffix } diff --git a/sqliter-driver/src/nativeTest/kotlin/co/touchlab/sqliter/DatabaseConfigurationTest.kt b/sqliter-driver/src/nativeTest/kotlin/co/touchlab/sqliter/DatabaseConfigurationTest.kt index c98594a0..8e4af3a9 100644 --- a/sqliter-driver/src/nativeTest/kotlin/co/touchlab/sqliter/DatabaseConfigurationTest.kt +++ b/sqliter-driver/src/nativeTest/kotlin/co/touchlab/sqliter/DatabaseConfigurationTest.kt @@ -16,10 +16,15 @@ package co.touchlab.sqliter +import kotlin.native.OsFamily +import kotlin.native.Platform import kotlin.test.* class DatabaseConfigurationTest : BaseDatabaseTest(){ + // Paths are normalized to the host's separator, which is a back slash on Windows. + private val sep = if (Platform.osFamily == OsFamily.WINDOWS) "\\" else "/" + @Test fun pathTest(){ val dbPathString = DatabaseFileContext.databasePath(TEST_DB_NAME, null) @@ -29,19 +34,19 @@ class DatabaseConfigurationTest : BaseDatabaseTest(){ @Test fun databasePathRemovesExtraSlashes() { val dbPathString = DatabaseFileContext.databasePath(TEST_DB_NAME, "//tmp//") - assertEquals("/tmp/$TEST_DB_NAME", dbPathString) + assertEquals("${sep}tmp$sep$TEST_DB_NAME", dbPathString) } @Test fun databasePathRemovesFileUrlPrefix() { val dbPathString = DatabaseFileContext.databasePath(TEST_DB_NAME, "file:///tmp/") - assertEquals("/tmp/$TEST_DB_NAME", dbPathString) + assertEquals("${sep}tmp$sep$TEST_DB_NAME", dbPathString) } @Test fun databasePathRemovesFileUrlPrefixInCaps() { val dbPathString = DatabaseFileContext.databasePath(TEST_DB_NAME, "FILE:///tmp/") - assertEquals("/tmp/$TEST_DB_NAME", dbPathString) + assertEquals("${sep}tmp$sep$TEST_DB_NAME", dbPathString) } @Test