Skip to content

Commit 3eb9e41

Browse files
committed
Move framework Android and Native SQLite drivers.
This changes moves the SQLite KMP drivers for Android and Native that uses framework APIs. Bug: 300660920 Relnote: "Add AndroidSQLiteDriver and NativeSQLiteDriver which are the entry points to the Android and Native implementation of SQLite KMP." Test: ./sqlite/scripts/runConformanceTest Change-Id: Ib52494c4868be052dd10893027dc9662a61fe635
1 parent 86a5d2b commit 3eb9e41

19 files changed

Lines changed: 144 additions & 50 deletions

File tree

sqliteMultiplatform/conformanceTest/build.gradle renamed to sqlite/integration-tests/driver-conformance-test/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ androidXMultiplatform {
2727
sourceSets {
2828
commonMain {
2929
dependencies {
30-
api(project(":sqliteMultiplatform:sqlite"))
30+
api(project(":sqlite:sqlite"))
3131
implementation(libs.kotlinStdlib)
3232
implementation(libs.kotlinTest)
3333
implementation(project(":kruth:kruth"))
@@ -43,7 +43,7 @@ androidXMultiplatform {
4343
}
4444

4545
androidx {
46-
name = "SQLite KMP Coformance Base Tests"
46+
name = "SQLite Driver Coformance Base Tests"
4747
inceptionYear = "2023"
48-
description = "SQLite Kotlin Multiplatform coformance base tests"
48+
description = "SQLite Kotlin driver coformance base tests"
4949
}

sqliteMultiplatform/conformanceTest/src/commonMain/kotlin/androidx/sqliteMultiplatform/BaseConformanceTest.kt renamed to sqlite/integration-tests/driver-conformance-test/src/commonMain/kotlin/androidx/sqlite/driver/BaseConformanceTest.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17-
package androidx.sqliteMultiplatform
17+
package androidx.sqlite.driver
1818

1919
import androidx.kruth.assertThat
20+
import androidx.sqlite.SQLiteConnection
21+
import androidx.sqlite.SQLiteDriver
22+
import androidx.sqlite.SQLiteException
23+
import androidx.sqlite.execSQL
24+
import androidx.sqlite.use
2025
import kotlin.test.Test
2126
import kotlin.test.assertFailsWith
2227

sqliteMultiplatform/scripts/runConformanceTest.sh renamed to sqlite/scripts/runConformanceTest.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
# limitations under the License.
1515
#
1616

17-
ANDROIDX_PROJECTS=INFRAROGUE ./gradlew \
18-
:sqliteMultiplatform:sqlite-driver:test \
19-
:sqliteMultiplatform:sqlite-driver:connectedAndroidTest \
20-
:sqliteMultiplatform:sqlite-driver-unbundled:test \
21-
:sqliteMultiplatform:sqlite-driver-unbundled:connectedAndroidTest
17+
ANDROIDX_PROJECTS=KMP \
18+
./gradlew \
19+
:sqlite:sqlite-framework:allTests \
20+
:sqlite:sqlite-framework:connectedAndroidTest \
21+
:sqlite:sqlite-bundled:allTests \
22+
:sqlite:sqlite-bundled:connectedAndroidTest
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
// Baseline format: 1.0
22
AcronymName: androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory:
33
Acronyms should not be capitalized in class names: was `FrameworkSQLiteOpenHelperFactory`, should this be `FrameworkSqLiteOpenHelperFactory`?
4+
AcronymName: androidx.sqlite.driver.AndroidSQLiteDriver:
5+
Acronyms should not be capitalized in class names: was `AndroidSQLiteDriver`, should this be `AndroidSqLiteDriver`?

sqlite/sqlite-framework/api/current.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,12 @@ package androidx.sqlite.db.framework {
88

99
}
1010

11+
package androidx.sqlite.driver {
12+
13+
public final class AndroidSQLiteDriver implements androidx.sqlite.SQLiteDriver {
14+
ctor public AndroidSQLiteDriver(String filename);
15+
method public androidx.sqlite.SQLiteConnection open();
16+
}
17+
18+
}
19+

sqlite/sqlite-framework/api/restricted_current.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,12 @@ package androidx.sqlite.db.framework {
88

99
}
1010

11+
package androidx.sqlite.driver {
12+
13+
public final class AndroidSQLiteDriver implements androidx.sqlite.SQLiteDriver {
14+
ctor public AndroidSQLiteDriver(String filename);
15+
method public androidx.sqlite.SQLiteConnection open();
16+
}
17+
18+
}
19+

sqlite/sqlite-framework/build.gradle

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,62 @@
1515
*/
1616

1717

18+
import androidx.build.KmpPlatformsKt
1819
import androidx.build.PlatformIdentifier
1920
import androidx.build.Publish
21+
import androidx.build.SdkHelperKt
22+
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
23+
import org.jetbrains.kotlin.konan.target.KonanTarget
2024

2125
plugins {
2226
id("AndroidXPlugin")
2327
id("com.android.library")
2428
}
2529

30+
def nativeEnabled = KmpPlatformsKt.enableNative(project)
31+
32+
configurations {
33+
// Configuration for resolving shared archive file of androidx's SQLite compilation
34+
sqliteSharedArchive {
35+
canBeConsumed = false
36+
canBeResolved = true
37+
attributes {
38+
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.NATIVE_LINK))
39+
}
40+
}
41+
}
42+
2643
androidXMultiplatform {
2744
android()
2845
androidNative()
46+
ios() {
47+
// Link to sqlite3 available in iOS
48+
binaries.all {
49+
linkerOpts += ["-lsqlite3"]
50+
}
51+
}
2952
linux()
3053
mac()
31-
ios()
3254

3355
defaultPlatform(PlatformIdentifier.ANDROID)
3456

3557
sourceSets {
3658
commonMain {
3759
dependencies {
3860
implementation(libs.kotlinStdlib)
61+
api(project(":annotation:annotation"))
3962
api(project(":sqlite:sqlite"))
4063
}
4164
}
4265
commonTest {
4366
dependencies {
67+
implementation(project(":sqlite:integration-tests:driver-conformance-test"))
4468
implementation(libs.kotlinTest)
4569
implementation(project(":kruth:kruth"))
4670
}
4771
}
4872
androidMain {
4973
dependsOn(commonMain)
50-
dependencies {
51-
api("androidx.annotation:annotation:1.2.0")
52-
}
5374
}
5475
androidInstrumentedTest {
5576
dependsOn(commonTest)
@@ -59,17 +80,67 @@ androidXMultiplatform {
5980
implementation(libs.testCore)
6081
}
6182
}
83+
if (nativeEnabled) {
84+
nativeMain {
85+
dependsOn(commonMain)
86+
}
87+
nativeTest {
88+
dependsOn(commonTest)
89+
}
90+
}
91+
targets.all { target ->
92+
if (target.platformType == KotlinPlatformType.native) {
93+
def main = target.compilations["main"]
94+
main.defaultSourceSet {
95+
dependsOn(nativeMain)
96+
}
97+
// For usage of C interop APIs
98+
// See: https://kotlinlang.org/docs/whatsnew19.html#explicit-c-interoperability-stability-guarantees
99+
main.compilerOptions.options.optIn.add("kotlinx.cinterop.ExperimentalForeignApi")
100+
main.cinterops {
101+
sqlite3 {
102+
def externalSQLiteDir = new File(
103+
SdkHelperKt.getCheckoutRoot(project),
104+
"/external/sqlite/dist/orig/"
105+
)
106+
includeDirs(externalSQLiteDir)
107+
}
108+
}
109+
110+
def test = target.compilations["test"]
111+
test.defaultSourceSet {
112+
dependsOn(nativeTest)
113+
}
114+
if (target.konanTarget == KonanTarget.LINUX_X64.INSTANCE) {
115+
// For tests in Linux host, statically include androidx's compiled SQLite
116+
// via a generated C interop definition
117+
createCinteropFromArchiveConfiguration(test, configurations["sqliteSharedArchive"])
118+
} else if (
119+
target.konanTarget == KonanTarget.MACOS_X64.INSTANCE ||
120+
target.konanTarget == KonanTarget.MACOS_ARM64.INSTANCE
121+
) {
122+
// For tests in Mac host, link to shared SQLite library included in MacOS
123+
test.kotlinOptions.freeCompilerArgs += [
124+
"-linker-options", "-lsqlite3"
125+
]
126+
}
127+
}
128+
}
62129
}
63130
}
64131

132+
dependencies {
133+
sqliteSharedArchive(project(":sqlite:sqlite-bundled"))
134+
}
135+
65136
androidx {
66137
name = "SQLite Framework Integration"
67138
publish = Publish.SNAPSHOT_AND_RELEASE
68139
inceptionYear = "2017"
69-
description = "The implementation of Support SQLite library using the framework code."
140+
description = "The implementation of SQLite library using the framework code."
70141
metalavaK2UastEnabled = true
71142
}
72143

73144
android {
74-
namespace "androidx.sqlite.db.framework"
145+
namespace "androidx.sqlite.driver"
75146
}

sqliteMultiplatform/sqlite-driver/src/androidInstrumentedTest/kotlin/androidx/sqliteMultiplatform/driver/AndroidSQLiteDriverTest.kt renamed to sqlite/sqlite-framework/src/androidInstrumentedTest/kotlin/androidx/sqlite/driver/AndroidSQLiteDriverTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
package androidx.sqliteMultiplatform.driver
17+
package androidx.sqlite.driver
1818

19-
import androidx.sqliteMultiplatform.BaseConformanceTest
20-
import androidx.sqliteMultiplatform.SQLiteDriver
19+
import androidx.sqlite.SQLiteDriver
2120
import kotlin.test.Ignore
2221

2322
class AndroidSQLiteDriverTest : BaseConformanceTest() {

sqliteMultiplatform/sqlite-driver/src/androidMain/kotlin/androidx/sqliteMultiplatform/driver/AndroidSQLite.kt renamed to sqlite/sqlite-framework/src/androidMain/kotlin/androidx/sqlite/driver/AndroidSQLite.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
package androidx.sqliteMultiplatform.driver
17+
package androidx.sqlite.driver
1818

19-
import androidx.sqliteMultiplatform.SQLiteException
19+
import androidx.sqlite.SQLiteException
2020

2121
private typealias FrameworkSQLiteException = android.database.sqlite.SQLiteException
2222

sqliteMultiplatform/sqlite-driver/src/androidMain/kotlin/androidx/sqliteMultiplatform/driver/AndroidSQLiteConnection.kt renamed to sqlite/sqlite-framework/src/androidMain/kotlin/androidx/sqlite/driver/AndroidSQLiteConnection.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
package androidx.sqliteMultiplatform.driver
17+
package androidx.sqlite.driver
1818

1919
import android.database.sqlite.SQLiteDatabase
20-
import androidx.sqliteMultiplatform.SQLiteConnection
21-
import androidx.sqliteMultiplatform.SQLiteStatement
22-
import androidx.sqliteMultiplatform.driver.ResultCode.SQLITE_MISUSE
23-
import androidx.sqliteMultiplatform.throwSQLiteException
20+
import androidx.sqlite.SQLiteConnection
21+
import androidx.sqlite.SQLiteStatement
22+
import androidx.sqlite.driver.ResultCode.SQLITE_MISUSE
23+
import androidx.sqlite.throwSQLiteException
2424

2525
internal class AndroidSQLiteConnection(
2626
private val db: SQLiteDatabase

0 commit comments

Comments
 (0)