Skip to content

Commit

Permalink
Adding sqlite-open-helper (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
illarionov authored Mar 12, 2024
1 parent 95af440 commit 28d6a8e
Show file tree
Hide file tree
Showing 72 changed files with 14,652 additions and 10 deletions.
20 changes: 20 additions & 0 deletions build-logic/project/multiplatform/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2024, the wasm-sqlite-open-helper project authors and contributors. Please see the AUTHORS file
* for details. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
* SPDX-License-Identifier: Apache-2.0
*/

plugins {
`kotlin-dsl`
}

group = "ru.pixnews.sqlite.open.helper.gradle.multiplatform"

dependencies {
implementation(project(":lint"))
implementation(libs.agp.plugin.api)
implementation(libs.kotlin.gradle.plugin)
implementation(libs.gradle.maven.publish.plugin)
implementation(libs.dokka.plugin)
runtimeOnly(libs.agp.plugin)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2024, the wasm-sqlite-open-helper project authors and contributors. Please see the AUTHORS file
* for details. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
* SPDX-License-Identifier: Apache-2.0
*/

import com.android.build.api.dsl.LibraryExtension

/*
* Convention plugin that configures Android target in projects with the Kotlin Multiplatform plugin
*/
plugins {
id("org.jetbrains.kotlin.multiplatform")
id("ru.pixnews.sqlite.open.helper.gradle.multiplatform.kotlin")
id("ru.pixnews.sqlite.open.helper.gradle.lint.android-lint")
id("com.android.library")
}

kotlin {
androidTarget {
publishLibraryVariants = listOf("release")
}
}

extensions.configure<LibraryExtension>("android") {
compileSdk = versionCatalogs.named("libs").findVersion("androidCompileSdk").get().displayName.toInt()
defaultConfig {
minSdk = versionCatalogs.named("libs").findVersion("androidMinSdk").get().displayName.toInt()
}
compileOptions {
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_17
isCoreLibraryDesugaringEnabled = false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2024, the pixnews-debuglayout project authors and contributors.
* Please see the AUTHORS file for details.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/

import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile

/*
* Convention plugin that configures Kotlin in projects with the Kotlin Multiplatform plugin
*/
plugins {
id("org.jetbrains.kotlin.multiplatform")
}

kotlin {
explicitApi = ExplicitApiMode.Warning

sourceSets {
all {
languageSettings {
languageVersion = "1.9"
apiVersion = "1.9"
listOf(
"kotlin.RequiresOptIn",
"ru.pixnews.sqlite.open.helper.common.api.InternalWasmSqliteHelperApi",
).forEach(::optIn)
}
}
}
}

tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
freeCompilerArgs.addAll(
"-Xjvm-default=all",
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (c) 2024, the pixnews-debuglayout project authors and contributors.
* Please see the AUTHORS file for details.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/

import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.KotlinMultiplatform
import org.jetbrains.dokka.gradle.DokkaTask

/*
* Convention plugin with publishing defaults
*/
plugins {
id("org.jetbrains.kotlin.multiplatform")
id("com.vanniktech.maven.publish.base")
id("org.jetbrains.dokka")
}

tasks.withType<AbstractArchiveTask>().configureEach {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}

mavenPublishing {
publishing {
repositories {
maven {
name = "test"
setUrl(project.rootProject.layout.buildDirectory.dir("localMaven"))
}
maven {
name = "PixnewsS3"
setUrl("s3://maven.pixnews.ru/")
credentials(AwsCredentials::class) {
accessKey = providers.environmentVariable("YANDEX_S3_ACCESS_KEY_ID").getOrElse("")
secretKey = providers.environmentVariable("YANDEX_S3_SECRET_ACCESS_KEY").getOrElse("")
}
}
}
}

signAllPublications()

configure(
KotlinMultiplatform(javadocJar = JavadocJar.Dokka("dokkaHtml")),
)

pom {
name.set(project.name)
description.set("mplementation of SupportSQLiteOpenHelper based on SQLite compiled for WASM")
url.set("https://github.com/illarionov/wasm-sqlite-open-helper")

licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("illarionov")
name.set("Alexey Illarionov")
email.set("[email protected]")
}
}
scm {
connection.set("scm:git:git://github.com/illarionov/wasm-sqlite-open-helper.git")
developerConnection.set("scm:git:ssh://github.com:illarionov/wasm-sqlite-open-helper.git")
url.set("https://github.com/illarionov/wasm-sqlite-open-helper")
}
}
}

tasks.withType<DokkaTask> {
notCompatibleWithConfigurationCache("https://github.com/Kotlin/dokka/issues/2231")
dokkaSourceSets.configureEach {
skipDeprecated.set(true)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2024, the pixnews-debuglayout project authors and contributors.
* Please see the AUTHORS file for details.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/

import org.gradle.api.tasks.testing.Test
import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED
import org.gradle.kotlin.dsl.withType

/*
* Convention plugin that configures unit tests in projects with the Kotlin Multiplatform plugin
*/
tasks.withType<Test> {
useJUnitPlatform()
maxHeapSize = "2G"
testLogging {
events = mutableSetOf(
FAILED,
)
}
}
5 changes: 0 additions & 5 deletions build-logic/settings/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ buildscript {

dependencyResolutionManagement {
repositories.gradlePluginPortal()
versionCatalogs {
create("libs") {
from(files("../../gradle/libs.versions.toml"))
}
}
}

rootProject.name = "sqlite-helper-gradle-settings-plugins"
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pluginManagement {

dependencyResolutionManagement {
repositories {
google()
mavenCentral()
googleFiltered()
}
Expand Down
30 changes: 30 additions & 0 deletions common-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2024, the wasm-sqlite-open-helper project authors and contributors. Please see the AUTHORS file
* for details. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
* SPDX-License-Identifier: Apache-2.0
*/

plugins {
id("ru.pixnews.sqlite.open.helper.gradle.multiplatform.kotlin")
}

group = "ru.pixnews.sqlite.open.helper.common.api"

dependencies {
}

kotlin {
jvm()
js(IR) {
nodejs()
}
linuxX64()
mingwX64()

sourceSets {
commonTest.dependencies {
implementation(kotlin("test"))
implementation(libs.assertk)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2024, the wasm-sqlite-open-helper project authors and contributors. Please see the AUTHORS file
* for details. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
* SPDX-License-Identifier: Apache-2.0
*/

package ru.pixnews.sqlite.open.helper.common.api

@RequiresOptIn(
level = RequiresOptIn.Level.ERROR,
message = "This API is internal in wasm-sqlite-open-helper and should not be used. " +
"It could be removed or changed without notice.",
)
@Target(
AnnotationTarget.CLASS,
AnnotationTarget.TYPEALIAS,
AnnotationTarget.FUNCTION,
AnnotationTarget.PROPERTY,
AnnotationTarget.FIELD,
AnnotationTarget.CONSTRUCTOR,
AnnotationTarget.PROPERTY_SETTER,
AnnotationTarget.PROPERTY_SETTER,
)
@Retention(AnnotationRetention.BINARY)
public annotation class InternalWasmSqliteHelperApi
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2024, the wasm-sqlite-open-helper project authors and contributors. Please see the AUTHORS file
* for details. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
* SPDX-License-Identifier: Apache-2.0
*/

@file:Suppress("NOTHING_TO_INLINE")

package ru.pixnews.sqlite.open.helper.common.api

public interface SqliteUintBitMask<T : SqliteUintBitMask<T>> {
public val newInstance: (UInt) -> T
public val mask: UInt
}

public inline fun SqliteUintBitMask<*>.contains(flags: SqliteUintBitMask<*>): Boolean {
return this.mask and flags.mask == flags.mask
}

public inline infix fun <T : SqliteUintBitMask<T>> SqliteUintBitMask<T>.and(flags: SqliteUintBitMask<*>): T {
return newInstance(mask and flags.mask)
}

public inline infix fun <T : SqliteUintBitMask<T>> SqliteUintBitMask<T>.or(flags: SqliteUintBitMask<*>): T {
return newInstance(mask or flags.mask)
}

public inline infix fun <T : SqliteUintBitMask<T>> SqliteUintBitMask<T>.xor(flags: SqliteUintBitMask<*>): T {
return newInstance(mask xor flags.mask)
}

public inline infix fun <T : SqliteUintBitMask<T>> SqliteUintBitMask<T>.clear(flags: SqliteUintBitMask<*>): T {
return newInstance(mask and flags.mask.inv())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2024, the wasm-sqlite-open-helper project authors and contributors. Please see the AUTHORS file
* for details. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
* SPDX-License-Identifier: Apache-2.0
*/

package ru.pixnews.sqlite.open.helper.common.api

import ru.pixnews.sqlite.open.helper.common.api.WasmPtr.Companion
import kotlin.jvm.JvmInline

@InternalWasmSqliteHelperApi
@JvmInline
public value class WasmPtr<out P : Any?>(
public val addr: Int,
) {
@Suppress("MagicNumber")
override fun toString(): String = "0x${addr.toString(16)}"

@Suppress("UNCHECKED_CAST")
@InternalWasmSqliteHelperApi
public companion object {
public const val WASM_SIZEOF_PTR: UInt = 4U
public val SQLITE3_NULL: WasmPtr<*> = WasmPtr<Unit>(0)
public fun <P> sqlite3Null(): WasmPtr<P> = SQLITE3_NULL as WasmPtr<P>
}
}

@InternalWasmSqliteHelperApi
public fun WasmPtr<*>.isSqlite3Null(): Boolean = this == Companion.SQLITE3_NULL

@InternalWasmSqliteHelperApi
public operator fun <P> WasmPtr<P>.plus(bytes: Int): WasmPtr<P> = WasmPtr(addr + bytes)
7 changes: 7 additions & 0 deletions config/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ comments:
complexity:
active: true
LongParameterList:
active: false # Original implementation of SQLiteOpenHelper has a large number of such functions
functionThreshold: 10
ignoreDefaultParameters: true
LongMethod:
active: true
ignoreAnnotated: ['Test']
NestedBlockDepth:
threshold: 5
TooManyFunctions:
active: false # Original implementation of SQLiteOpenHelper has classes with a huge number of functions

coroutines:
active: true
Expand Down Expand Up @@ -68,6 +73,8 @@ potential-bugs:
style:
active: true

ForbiddenComment:
active: false # disabled for a while until everything is done
ForbiddenMethodCall:
active: true
methods:
Expand Down
Loading

0 comments on commit 28d6a8e

Please sign in to comment.