Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
19 changes: 11 additions & 8 deletions sqliter-driver/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down