Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create an iOS runtime stub #946

Merged
merged 1 commit into from
Sep 20, 2018
Merged
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
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ buildscript {
google()
jcenter()
gradlePluginPortal()
maven {
url 'http://dl.bintray.com/kotlin/kotlin-eap'
}
maven {
url 'https://jitpack.io'
}
Expand All @@ -31,6 +34,9 @@ allprojects {
mavenCentral()
google()
jcenter()
maven {
url 'http://dl.bintray.com/kotlin/kotlin-eap'
}
}

tasks.withType(Test) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ext.versions = [
kotlin: '1.2.70',
kotlin: '1.3.0-rc-57',
compileSdk: 28,
idea: '2018.1',
dokka: '0.9.15',
Expand Down
28 changes: 20 additions & 8 deletions runtime/sqldelight-runtime/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,22 @@ kotlin {
implementation deps.kotlin.test.js
}
}
nativeMain {
}
nativeTest {
}
}

targets {
fromPreset(presets.jvm, 'jvm')
fromPreset(presets.js, 'js')
fromPreset(presets.iosX64, 'iosX64')
fromPreset(presets.iosArm64, 'iosArm64')
}

configure([targets.iosX64, targets.iosArm64]) {
compilations.main.source(sourceSets.nativeMain)
compilations.test.source(sourceSets.nativeTest)
}
}

Expand Down Expand Up @@ -76,7 +88,7 @@ signing {

publishing {
afterEvaluate {
publications.getByName('kotlin') {
publications.getByName('kotlinMultiplatform') {
artifactId = POM_ARTIFACT_ID

pom.withXml {
Expand Down Expand Up @@ -128,12 +140,12 @@ publishing {

afterEvaluate {
// TODO https://youtrack.jetbrains.com/issue/KT-26920
tasks.getByName('publishKotlinPublicationToMavenLocal').dependsOn('assemble')
tasks.getByName('publishKotlinPublicationToMavenRepository').dependsOn('assemble')
tasks.getByName('publishKotlinPublicationToTestRepository').dependsOn('assemble')
tasks.getByName('publishKotlinMultiplatformPublicationToMavenLocal').dependsOn('assemble')
tasks.getByName('publishKotlinMultiplatformPublicationToMavenRepository').dependsOn('assemble')
tasks.getByName('publishKotlinMultiplatformPublicationToTestRepository').dependsOn('assemble')

// Alias the task names we use elsewhere to the new task names.
tasks.create('install').dependsOn('publishKotlinPublicationToMavenLocal')
tasks.create('installLocally').dependsOn('publishKotlinPublicationToTestRepository')
tasks.create('uploadArchives').dependsOn('publishKotlinPublicationToMavenRepository')
}
tasks.create('install').dependsOn('publishKotlinMultiplatformPublicationToMavenLocal')
tasks.create('installLocally').dependsOn('publishKotlinMultiplatformPublicationToTestRepository')
tasks.create('uploadArchives').dependsOn('publishKotlinMultiplatformPublicationToMavenRepository')
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.squareup.sqldelight.db.SqlPreparedStatement.Type.SELECT
import com.squareup.sqldelight.db.SqlResultSet
import com.squareup.sqldelight.db.use
import com.squareup.sqldelight.internal.QueryList
import com.squareup.sqldelight.internal.sync

fun <RowType : Any> Query(
queries: QueryList,
Expand Down Expand Up @@ -63,7 +64,7 @@ abstract class Query<out RowType : Any>(
* some false positives but never misses a true positive.
*/
fun notifyResultSetChanged() {
synchronized(listeners) {
sync(listeners) {
listeners.forEach(Listener::queryResultsChanged)
}
}
Expand All @@ -72,14 +73,14 @@ abstract class Query<out RowType : Any>(
* Register a listener to be notified of future changes in the result set.
*/
fun addListener(listener: Listener) {
synchronized(listeners) {
sync(listeners) {
if (listeners.isEmpty()) queries.addQuery(this)
listeners.add(listener)
}
}

fun removeListener(listener: Listener) {
synchronized(listeners) {
sync(listeners) {
listeners.remove(listener)
if (listeners.isEmpty()) queries.removeQuery(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class QueryList {
internal var queries: List<Query<*>> = emptyList()

fun addQuery(query: Query<*>) {
synchronized(queries) {
sync(queries) {
queries += query
}
}

fun removeQuery(query: Query<*>) {
synchronized(queries) {
sync(queries) {
queries -= query
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.squareup.sqldelight.internal

internal expect inline fun <R> sync(lock: Any, body: () -> R): R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.squareup.sqldelight.internal

internal actual inline fun <R> sync(lock: Any, body: () -> R): R = body()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.squareup.sqldelight.internal

internal actual inline fun <R> sync(lock: Any, body: () -> R): R = synchronized(lock, body)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.squareup.sqldelight.db

actual interface Closeable {
actual fun close()
}

actual inline fun <T : Closeable?, R> T.use(body: (T) -> R): R {
var exception: Throwable? = null
try {
return body(this)
} catch (e: Throwable) {
exception = e
throw e
} finally {
when {
this == null -> {}
exception == null -> close()
else ->
try {
close()
} catch (closeException: Throwable) {
// Nothing to do...
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.squareup.sqldelight.internal

internal actual inline fun <R> sync(lock: Any, body: () -> R): R = body()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.squareup.sqldelight

import com.squareup.sqldelight.db.SqlDatabase

actual fun createSqlDatabase(): SqlDatabase {
TODO("Create a native sqlite driver")
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class SelectQueryGenerator(private val query: NamedQuery) : QueryGenerator(query

// The custom return type variable:
// <out T>
val returnType = TypeVariableName("T", bounds = ANY, variance = OUT)
val returnType = TypeVariableName("T", bounds = *arrayOf(ANY), variance = OUT)
queryType.addTypeVariable(returnType)

// The superclass:
Expand Down Expand Up @@ -213,7 +213,7 @@ class SelectQueryGenerator(private val query: NamedQuery) : QueryGenerator(query

// Add the mapper constructor parameter and pass to the super constructor
constructor.addParameter(MAPPER_NAME, LambdaTypeName.get(
parameters = RESULT_SET_TYPE,
parameters = *arrayOf(RESULT_SET_TYPE),
returnType = returnType
))
queryType.addSuperclassConstructorParameter(MAPPER_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ repositories {
}
mavenCentral()
google()
maven {
url 'http://dl.bintray.com/kotlin/kotlin-eap'
}
}

dependencies {
Expand Down
3 changes: 3 additions & 0 deletions sqldelight-gradle-plugin/src/test/integration/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ repositories {
url "file://${projectDir.absolutePath}/../../../../build/localMaven"
}
mavenCentral()
maven {
url 'http://dl.bintray.com/kotlin/kotlin-eap'
}
}

sqldelight {
Expand Down
3 changes: 3 additions & 0 deletions sqldelight-gradle-plugin/src/test/variants/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ repositories {
url "file://${projectDir.absolutePath}/../../../../build/localMaven"
}
mavenCentral()
maven {
url 'http://dl.bintray.com/kotlin/kotlin-eap'
}
}

android {
Expand Down
2 changes: 1 addition & 1 deletion sqldelight-idea-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ intellij {
version "IC-${versions.idea}"
pluginName = 'SQLDelight'
plugins = [
"org.jetbrains.kotlin:${versions.kotlin}-release-IJ${versions.idea}-1",
"org.jetbrains.kotlin:${versions.kotlin}-IJ${versions.idea}-1@EAP-NEXT",
"gradle",
"Groovy",
"properties",
Expand Down