Skip to content

Commit 512a5b1

Browse files
committed
make sqliter fully support windows
1 parent 862d5de commit 512a5b1

File tree

10 files changed

+647
-31
lines changed

10 files changed

+647
-31
lines changed

SQLiter/build.gradle

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ buildscript {
1313
apply plugin: 'org.jetbrains.kotlin.multiplatform'
1414

1515
repositories {
16-
// mavenLocal()
1716
mavenCentral()
1817
maven {
1918
url 'https://oss.sonatype.org/content/repositories/snapshots/'
@@ -39,6 +38,16 @@ kotlin {
3938
}
4039
}
4140

41+
fromPreset(presets.mingwX64, 'mingw'){
42+
compilations.each {
43+
it.extraOpts("-linker-options", "-Lc:\\msys64\\mingw64\\lib")
44+
it.extraOpts("-linker-options", "-lsqlite3")
45+
}
46+
compilations.test {
47+
it.extraOpts("-native-library", "../KotlinCpp/bcdist/mingw_x64/tlruntime.bc")
48+
}
49+
}
50+
4251
fromPreset(presets.iosX64, 'iosX64'){
4352
compilations.each {
4453
it.extraOpts("-linker-options", "-lsqlite3")
@@ -91,6 +100,11 @@ kotlin {
91100
implementation 'org.jetbrains.kotlin:kotlin-test-junit'
92101
}
93102
}
103+
mingwMain {
104+
dependencies {
105+
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
106+
}
107+
}
94108

95109
nativeCommonMain { }
96110
nativeCommonTest { }
@@ -99,11 +113,15 @@ kotlin {
99113
dependsOn nativeCommonMain
100114
}
101115

116+
configure([mingwMain]) {
117+
dependsOn nativeCommonMain
118+
}
119+
102120
configure([iosX64Main, iosArm64Main, macosMain, iosArm32Main]) {
103121
dependsOn appleMain
104122
}
105123

106-
configure([iosX64Test, iosArm64Test, macosTest, iosArm32Test]) {
124+
configure([iosX64Test, iosArm64Test, macosTest, iosArm32Test, mingwTest]) {
107125
dependsOn nativeCommonTest
108126
}
109127
}
@@ -133,6 +151,7 @@ task mergeCppAll(dependsOn:build) {
133151
mergeCppOutput("iosArm64", "ios_arm64")
134152
mergeCppOutput("iosX64", "ios_x64")
135153
mergeCppOutput("macos", "macos_x64")
154+
mergeCppOutput("mingw", "mingw_x64")
136155
}
137156
}
138157

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package co.touchlab.sqliter
2+
3+
import co.touchlab.sqliter.internal.File
4+
import co.touchlab.sqliter.internal.FileFilter
5+
import co.touchlab.sqliter.internal.Utils
6+
7+
actual object DatabaseFileContext {
8+
actual fun deleteDatabase(name: String, basePath:String?) {
9+
deleteDatabaseFile(databaseFile(name, basePath))
10+
}
11+
12+
internal fun databasePath(databaseName:String, inMemory:Boolean, datapathPath:String?):String {
13+
return if(inMemory) {
14+
"file:$databaseName?mode=memory&cache=shared"
15+
} else {
16+
databaseFile(databaseName, datapathPath).path
17+
}
18+
}
19+
20+
internal fun databaseFile(databaseName:String, datapathPath:String?):File {
21+
return File(datapathPath ?: Utils.getUserDirectory(), databaseName)
22+
}
23+
24+
internal fun deleteDatabaseFile(file:File):Boolean {
25+
var deleted = false
26+
deleted = deleted or file.delete()
27+
deleted = deleted or File(file.getPath() + "-journal").delete()
28+
deleted = deleted or File(file.getPath() + "-shm").delete()
29+
deleted = deleted or File(file.getPath() + "-wal").delete()
30+
31+
val dir = file.getParentFile()
32+
if (dir != null) {
33+
val prefix = file.getName() + "-mj"
34+
val files = dir.listFiles(object: FileFilter {
35+
override fun accept(candidate: File):Boolean {
36+
return candidate.getName().startsWith(prefix)
37+
}
38+
})
39+
if (files != null) {
40+
for (masterJournal in files) {
41+
deleted = deleted or masterJournal.delete()
42+
}
43+
}
44+
}
45+
return deleted
46+
}
47+
}

0 commit comments

Comments
 (0)