Skip to content

Commit

Permalink
Fix compiler plugin not being applied
Browse files Browse the repository at this point in the history
  • Loading branch information
clementetb committed Oct 1, 2024
1 parent 8c45033 commit 3a0e812
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 93 deletions.
63 changes: 31 additions & 32 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## 3.0.0-SNAPSHOT (YYYY-MM-DD)

### Breaking Changes
* [Sync] All sync functionality has been removed.
* [Sync] Atlas Device Sync related functionality has been removed from the project.

### Enhancements
* None.
Expand Down Expand Up @@ -34,6 +34,36 @@
### Breaking Changes
* None.

### Enhancements
* None.

### Fixed
* Via https://github.com/realm/realm-kotlin/pull/1826. Fix compiler crash caused by a change in Kotlin 2.0.20. (Issue [#1825](https://github.com/realm/realm-kotlin/issues/1825)). Thanks @KitsuneAlex.

### Compatibility
* File format: Generates Realms with file format v24 (reads and upgrades file format v10 or later).
* Realm Studio 15.0.0 or above is required to open Realms created by this version.
* This release is compatible with the following Kotlin releases:
* Kotlin 2.0.20 and above. Support for experimental K2-compilation with `kotlin.experimental.tryK2=true`.
* Ktor 2.1.2 and above.
* Coroutines 1.7.0 and above.
* AtomicFu 0.18.3 and above.
* The new memory model only. See https://github.com/realm/realm-kotlin#kotlin-memory-model-and-coroutine-compatibility
* Minimum Kbson 0.4.0.
* Minimum Gradle version: 7.2.
* Minimum Android Gradle Plugin version: 7.1.3.
* Minimum Android SDK: 16.
* Minimum R8: 8.0.34.

### Internal
* None.


## 2.2.0 (2024-09-13)

### Breaking Changes
* None.

### Enhancements
* Support Android 15 page size 16 KB. (Issue [#1787](https://github.com/realm/realm-kotlin/issues/1787) [JIRA](https://jira.mongodb.org/browse/RKOTLIN-1105)).
* Reduce the size of the local transaction log produced by creating objects, improving the performance of insertion-heavy transactions (Core issue [realm/realm-core#7734](https://github.com/realm/realm-core/pull/7734)).
Expand All @@ -50,7 +80,6 @@
* [Sync] Client reset cycle detection now checks if the previous recovery attempt was made by the same core version, and if not attempts recovery again (Core issue [realm/realm-core#7944](https://github.com/realm/realm-core/pull/7944)).

### Fixed
* Via https://github.com/realm/realm-kotlin/pull/1826. Fix compiler crash caused by a change in Kotlin 2.0.20. (Issue [#1825](https://github.com/realm/realm-kotlin/issues/1825)). Thanks @KitsuneAlex.
* Comparing a numeric property with an argument list containing a string would throw. (Core issue [realm/realm-core#7714](https://github.com/realm/realm-core/issues/7714), since v2.0.0).
* After compacting, a file upgrade would be triggered. This could cause loss of data if schema mode is SoftResetFile (Core issue [realm/realm-core#7747](https://github.com/realm/realm-core/issues/7747), since v1.15.0).
* Encrypted files on Windows had a maximum size of 2GB even on x64 due to internal usage of `off_t`, which is a 32-bit type on 64-bit Windows (Core issue [realm/realm-core#7698](https://github.com/realm/realm-core/pull/7698)).
Expand Down Expand Up @@ -94,36 +123,6 @@
* Updated to Sync protocol version 14 to support server intiated bootstraps and role change updates without a client reset. (Core issue [realm/realm-core#7440](https://github.com/realm/realm-core/pull/7440)).


## 2.1.1-SNAPSHOT (YYYY-MM-DD)

### Breaking Changes
* None.

### Enhancements
* None.

### Fixed
* None.

### Compatibility
* File format: Generates Realms with file format v24 (reads and upgrades file format v10 or later).
* Realm Studio 15.0.0 or above is required to open Realms created by this version.
* This release is compatible with the following Kotlin releases:
* Kotlin 2.0.0 and above. Support for experimental K2-compilation with `kotlin.experimental.tryK2=true`.
* Ktor 2.1.2 and above.
* Coroutines 1.7.0 and above.
* AtomicFu 0.18.3 and above.
* The new memory model only. See https://github.com/realm/realm-kotlin#kotlin-memory-model-and-coroutine-compatibility
* Minimum Kbson 0.4.0.
* Minimum Gradle version: 7.2.
* Minimum Android Gradle Plugin version: 7.1.3.
* Minimum Android SDK: 16.
* Minimum R8: 8.0.34.

### Internal
* None.


## 2.1.0 (2024-07-12)

### Breaking Changes
Expand Down
10 changes: 3 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ platforms with:
cd packages
./gradlew :test-base:jvmTest :test-base:connectedAndroidTest :test-base:macosTest :test-base:iosTest

# Note that running the test-sync suite requires running a local server
# (see `tools/sync_test_server/start_local_server.sh` and `tools/sync_test_server/stop_local_server.sh`)

./gradlew :test-sync:jvmTest :test-sync:connectedAndroidTest :test-sync:macosTest :test-sync:iosTest
```
You can also the test across all modules on the various platforms with
```sh
Expand Down Expand Up @@ -230,9 +226,9 @@ All platform differentiated implementations are kept in `platform`-packages with

Inside the various `packages/test-X/` modules there are 3 locations the files can be placed in:

* `packages/test-<base/sync>/src/commonTest`
* `package/test-<base/sync>/src/androidAndroidTest`
* `package/test-<base/sync>/src/nativeDarwinTest` (macOS)
* `packages/test-base/src/commonTest`
* `package/test-base/src/androidAndroidTest`
* `package/test-base/src/nativeDarwinTest` (macOS)

Ideally all shared tests should be in `commonTest` with specific platform tests in `androidAndroidTest`/`nativeDarwinTest`. However IntelliJ does [not yet allow you to run common tests on Android from within the IDE](https://youtrack.jetbrains.com/issue/KT-46452), so we
are using the following work-around:
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ This repository holds the source code for the Kotlin SDK for Realm, which runs o
* **Intuitive to Developers:** Realm’s object-oriented data model is simple to learn, doesn’t need an ORM, and lets you write less code.
* **Built for Mobile:** Realm is fully-featured, lightweight, and efficiently uses memory, disk space, and battery life.
* **Designed for Offline Use:** Realm’s local database persists data on-disk, so apps work as well offline as they do online.
* **[Atlas Device Sync](https://www.mongodb.com/docs/atlas/app-services/sync/)**: Makes it simple to keep data in sync across users, devices, and your backend in real-time. Get started for free with [a template application](https://github.com/mongodb/template-app-kotlin-todo) and [create the cloud backend](http://mongodb.com/realm/register?utm_medium=github_atlas_CTA&utm_source=realm_kotlin_github).

# General Availability

Expand All @@ -37,7 +36,7 @@ If you are migrating from [Realm Java](https://github.com/realm/realm-java), ple

## Installation

Installation differs slightly depending on the type of project and whether or not you are using Device Sync. See the details in the documentation:
Installation differs slightly depending on the type of project. See the details in the documentation:

* [Android](https://www.mongodb.com/docs/atlas/device-sdks/sdk/kotlin/install/#std-label-kotlin-install-android)
* [Kotlin Multiplatform](https://www.mongodb.com/docs/atlas/device-sdks/sdk/kotlin/install/#std-label-kotlin-install-kotlin-multiplatform)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,46 +81,6 @@ typealias RealmChangesPointer = NativePointer<RealmChangesT>
typealias RealmSchedulerPointer = NativePointer<RealmSchedulerT>
typealias RealmKeyPathArrayPointer = NativePointer<RealmKeyPathArrayT>

/**
* Class for grouping and normalizing values we want to send as part of
* logging in Sync Users.
*/
@Suppress("LongParameterList")
class SyncConnectionParams(
sdkVersion: String,
bundleId: String,
platformVersion: String,
device: String,
deviceVersion: String,
framework: Runtime,
frameworkVersion: String
) {
val sdkName = "Kotlin"
val bundleId: String
val sdkVersion: String
val platformVersion: String
val device: String
val deviceVersion: String
val framework: String
val frameworkVersion: String

enum class Runtime(public val description: String) {
JVM("JVM"),
ANDROID("Android"),
NATIVE("Native")
}

init {
this.sdkVersion = sdkVersion
this.bundleId = bundleId
this.platformVersion = platformVersion
this.device = device
this.deviceVersion = deviceVersion
this.framework = framework.description
this.frameworkVersion = frameworkVersion
}
}

@Suppress("FunctionNaming", "LongParameterList")
expect object RealmInterop {
fun realm_value_get(value: RealmValue): Any?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2020 Realm Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.realm.kotlin.gradle

import org.gradle.api.provider.Provider
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerPluginSupportPlugin
import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption

class RealmCompilerSubplugin : KotlinCompilerPluginSupportPlugin {

companion object {
// TODO LATER Consider embedding these from the build.gradle's versionConstants task just
// as with the version. But leave it for now as they should be quite stable.
// Modules has to match ${project.group}:${project.name} to make composite build work
const val groupId = "io.realm.kotlin"
const val artifactId = "plugin-compiler"
const val version = PLUGIN_VERSION

// The id used for passing compiler options from command line
const val compilerPluginId = "io.realm.kotlin"
}

override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean {
return kotlinCompilation.target.project.plugins.findPlugin(RealmCompilerSubplugin::class.java) != null
}

override fun getCompilerPluginId(): String {
return compilerPluginId
}

override fun getPluginArtifact(): SubpluginArtifact {
// Modules has to match ${project.group}:${project.name} to make composite build work
return SubpluginArtifact(groupId, artifactId, version)
}

override fun getPluginArtifactForNative(): SubpluginArtifact {
return SubpluginArtifact(groupId, artifactId, version)
}

override fun applyToCompilation(kotlinCompilation: KotlinCompilation<*>): Provider<List<SubpluginOption>> {
val project = kotlinCompilation.target.project

return project.provider { emptyList() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ open class RealmPlugin : Plugin<Project> {
private val logger: Logger = Logging.getLogger("realm-plugin")

override fun apply(project: Project) {
project.pluginManager.apply(RealmCompilerSubplugin::class.java)
project.configurations.all { conf: Configuration ->
// Ensure that android unit tests uses the Realm JVM variant rather than Android.
// This is a bit britle. See https://github.com/realm/realm-kotlin/issues/1404 for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,14 @@ import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.CompilerConfigurationKey

// Must match io.realm.kotlin.gradle.RealmCompilerSubplugin.bundleId
const val BUNDLE_ID_KEY = "bundleId"
const val FEATURE_LIST_PATH_KEY = "featureListPath"
val bundleIdConfigurationKey: CompilerConfigurationKey<String> = CompilerConfigurationKey<String>("io.realm.kotlin.bundleId")
val featureListPathConfigurationKey: CompilerConfigurationKey<String> = CompilerConfigurationKey<String>("io.realm.kotlin.featureListPath")

@OptIn(ExperimentalCompilerApi::class)
@AutoService(CommandLineProcessor::class)
class RealmCommandLineProcessor : CommandLineProcessor {
override val pluginId: String = "io.realm.kotlin"
override val pluginOptions: Collection<CliOption> = listOf(
CliOption(
optionName = "bundleId",
description = "Anonymized Bundle Id",
valueDescription = "Anonymized Bundle Id",
required = false,
allowMultipleOccurrences = false
),
CliOption(
optionName = "featureListPath",
description = "Feature List Path",
Expand All @@ -57,8 +47,6 @@ class RealmCommandLineProcessor : CommandLineProcessor {
configuration: CompilerConfiguration
) {
when (option.optionName) {
BUNDLE_ID_KEY ->
configuration.put(bundleIdConfigurationKey, value)
FEATURE_LIST_PATH_KEY ->
configuration.put(featureListPathConfigurationKey, value)
else -> super.processOption(option, value, configuration)
Expand Down

0 comments on commit 3a0e812

Please sign in to comment.