From 96aee074088d19392b74204e4c0bc1899d70c62a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus=20R=C3=B8rbech?= Date: Wed, 21 Dec 2022 14:06:23 +0100 Subject: [PATCH 1/6] Add test stage running on obfuscated builds --- CHANGELOG.md | 2 +- Jenkinsfile | 15 ++++++ packages/gradle.properties | 2 + .../proguard-rules-consumer-common.pro | 46 +++++++++++-------- packages/test-base/build.gradle.kts | 25 ++++++---- packages/test-base/proguard-rules-test.pro | 18 ++++++++ packages/test-sync/build.gradle.kts | 18 ++++---- packages/test-sync/proguard-rules-test.pro | 23 ++++++++++ 8 files changed, 113 insertions(+), 36 deletions(-) create mode 100644 packages/test-base/proguard-rules-test.pro create mode 100644 packages/test-sync/proguard-rules-test.pro diff --git a/CHANGELOG.md b/CHANGELOG.md index edbc7aec24..bc327a3acf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ * None. ### Fixed -* Added proguard consumer files to Android debug artifacts. (Issue [#1150](https://github.com/realm/realm-kotlin/issues/1150)) +* Fixed various proguard issues. (Issue [#1150](https://github.com/realm/realm-kotlin/issues/1150)) ### Compatibility * This release is compatible with the following Kotlin releases: diff --git a/Jenkinsfile b/Jenkinsfile index 3251085102..8ea6a30ae8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -223,6 +223,21 @@ pipeline { ]) } } + stage('Minified Sync Tests - Android') { + when { expression { runTests } } + steps { + testWithServer([ + { + testAndCollect("packages", 'cleanAllTests :test-sync:connectedAndroidtest -PincludeSdkModules=false -PtestBuildType=debugMinified') + } + ]) + zip([ + 'zipFile': 'mapping.zip', + 'archive': true, + 'glob': 'test-sync/build/outputs/mapping/debugMinified/mapping.txt' + ]) + } + } stage('Gradle Plugin Integration Tests') { when { expression { runTests } } steps { diff --git a/packages/gradle.properties b/packages/gradle.properties index b28d849e53..1054d36ade 100644 --- a/packages/gradle.properties +++ b/packages/gradle.properties @@ -33,3 +33,5 @@ kotlin.android.buildTypeAttribute.keep=false # includeSdkModules=true # includeTestModules=true testRepository=build/m2-buildrepo/ +# debug/debugMinified +testBuildType=debug diff --git a/packages/library-base/proguard-rules-consumer-common.pro b/packages/library-base/proguard-rules-consumer-common.pro index b51c2a7dd4..5407efc5fc 100644 --- a/packages/library-base/proguard-rules-consumer-common.pro +++ b/packages/library-base/proguard-rules-consumer-common.pro @@ -1,35 +1,43 @@ -# Keep all classes implemeting the RealmObject interface --keep class io.realm.kotlin.types.RealmObject --keep class * implements io.realm.kotlin.types.RealmObject { *; } - -# Keep all classes implemeting the EmbeddedRealmObject interface --keep class io.realm.kotlin.types.EmbeddedRealmObject --keep class * implements io.realm.kotlin.types.EmbeddedRealmObject { *; } +## Keep Companion classes and class.Companion member of all classes that can be used in our API to +# allow calling realmObjectCompanionOrThrow and realmObjectCompanionOrNull on the classes +-keep class io.realm.kotlin.types.ObjectId$Companion +-keepclassmembers class io.realm.kotlin.types.ObjectId { + io.realm.kotlin.types.ObjectId$Companion Companion; +} +-keep class io.realm.kotlin.types.RealmInstant$Companion +-keepclassmembers class io.realm.kotlin.types.RealmInstant { + io.realm.kotlin.types.RealmInstant$Companion Companion; +} +-keep class org.mongodb.kbson.BsonObjectId$Companion +-keepclassmembers class org.mongodb.kbson.BsonObjectId { + org.mongodb.kbson.BsonObjectId$Companion Companion; +} +-keep class io.realm.kotlin.dynamic.DynamicRealmObject$Companion, io.realm.kotlin.dynamic.DynamicMutableRealmObject$Companion +-keepclassmembers class io.realm.kotlin.dynamic.DynamicRealmObject, io.realm.kotlin.dynamic.DynamicMutableRealmObject { + **$Companion Companion; +} +-keep class ** implements io.realm.kotlin.internal.RealmObjectCompanion +-keepclassmembers class ** implements io.realm.kotlin.types.BaseRealmObject { + **$Companion Companion; +} -# Preserve all native method names and the names of their classes. +## Preserve all native method names and the names of their classes. -keepclasseswithmembernames,includedescriptorclasses class * { native ; } +## Preserve all classes that are looked up from native code # Notification callback -keep class io.realm.kotlin.internal.interop.NotificationCallback { *; } - # Utils to convert core errors into Kotlin exceptions -keep class io.realm.kotlin.internal.interop.CoreErrorUtils { *; } - -keep class io.realm.kotlin.internal.interop.JVMScheduler { *; } - -# Prevent all RealmObjects from having their companions stripped --keep class ** implements io.realm.kotlin.internal.RealmObjectCompanion { - *; -} - # Interop, sync-specific classes -keep class io.realm.kotlin.internal.interop.sync.NetworkTransport { # TODO OPTIMIZE Only keep actually required symbols @@ -43,7 +51,6 @@ # TODO OPTIMIZE Only keep actually required symbols *; } - -keep class io.realm.kotlin.internal.interop.sync.AppError { # TODO OPTIMIZE Only keep actually required symbols *; @@ -96,12 +103,13 @@ -keep class io.realm.kotlin.internal.interop.NativePointer { *; } - +-keep class io.realm.kotlin.internal.interop.sync.ApiKeyWrapper { + *; +} # Preserve Function methods as they back various functional interfaces called from JNI -keep class kotlin.jvm.functions.Function* { *; } - -keep class kotlin.Unit { *; } diff --git a/packages/test-base/build.gradle.kts b/packages/test-base/build.gradle.kts index 2a1d6f0e2f..b03f6bdb6d 100644 --- a/packages/test-base/build.gradle.kts +++ b/packages/test-base/build.gradle.kts @@ -111,10 +111,22 @@ android { } buildTypes { - getByName("release") { - isMinifyEnabled = false - proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") - } + // LibraryBuildType is not minifiable, but the current dependency from test-sync doesn't + // allow test-base to be configured as a library. To test test-base with minification + // change the AGP plugin to + // id("com.android.application") + // and uncomment the below buildType then you can run the full test suite with + // ./gradlew test-base:clean test-base:connAT -PtestBuildType=debugMinified + // Note that we cannot get memory consumption for non-debuggable build types so MemoryTests + // will fail + // testBuildType = (properties["testBuildType"] ?: "debug") as String + // create("debugMinified") { + // initWith(getByName("debug")) + // matchingFallbacks.add("debug") + // isMinifyEnabled = true + // isDebuggable = false + // proguardFiles("proguard-rules-test.pro") + // } } compileOptions { @@ -131,9 +143,7 @@ android { } kotlin { - android("android") { - publishLibraryVariants("release") - } + android("android") sourceSets { val androidMain by getting { dependencies { @@ -150,7 +160,6 @@ kotlin { implementation("androidx.test:runner:${Versions.androidxTest}") implementation("androidx.test:rules:${Versions.androidxTest}") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.coroutines}") - implementation("androidx.multidex:multidex:${Versions.multidex}") } } } diff --git a/packages/test-base/proguard-rules-test.pro b/packages/test-base/proguard-rules-test.pro new file mode 100644 index 0000000000..9b66333b32 --- /dev/null +++ b/packages/test-base/proguard-rules-test.pro @@ -0,0 +1,18 @@ +# We cannot discard unused symbols for the non-test configurations as it might all symbols not used +-dontoptimize +-dontshrink + +## Required to make assertions on incorrect type messages in dynamic realm object tests pass +-keep class io.realm.kotlin.types.BaseRealmObject +-keep class io.realm.kotlin.types.RealmUUID + +## Required to make introspection by reflection in NullabilityTests work +-keep class io.realm.kotlin.types.MutableRealmInt +-keep class io.realm.kotlin.entities.Nullability { + *; +} + +## Required to make introspection by reflection in PrimaryKeyTests work +-keepclassmembers class io.realm.kotlin.entities.primarykey.* { + *; +} diff --git a/packages/test-sync/build.gradle.kts b/packages/test-sync/build.gradle.kts index 0668b3a625..888bae8d79 100644 --- a/packages/test-sync/build.gradle.kts +++ b/packages/test-sync/build.gradle.kts @@ -19,7 +19,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithSimulatorTes plugins { id("org.jetbrains.kotlin.multiplatform") - id("com.android.library") + id("com.android.application") kotlin("plugin.serialization") version Versions.kotlin // Test relies on the compiler plugin, but we cannot apply our full plugin from within the same // gradle run, so we just apply the compiler plugin directly as a dependency below instead @@ -106,6 +106,8 @@ android { compileSdkVersion(Versions.Android.compileSdkVersion) buildToolsVersion = Versions.Android.buildToolsVersion + testBuildType = (properties["testBuildType"] ?: "debug") as String + defaultConfig { minSdkVersion(Versions.Android.minSdk) targetSdkVersion(Versions.Android.targetSdk) @@ -123,9 +125,12 @@ android { } buildTypes { - getByName("release") { - isMinifyEnabled = false - proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + create("debugMinified") { + initWith(getByName("debug")) + matchingFallbacks.add("debug") + isMinifyEnabled = true + isDebuggable = false + proguardFiles("proguard-rules-test.pro") } } @@ -143,9 +148,7 @@ android { } kotlin { - android("android") { - publishLibraryVariants("release") - } + android("android") sourceSets { val androidMain by getting { dependencies { @@ -162,7 +165,6 @@ kotlin { implementation("androidx.test:runner:${Versions.androidxTest}") implementation("androidx.test:rules:${Versions.androidxTest}") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.coroutines}") - implementation("androidx.multidex:multidex:${Versions.multidex}") } } } diff --git a/packages/test-sync/proguard-rules-test.pro b/packages/test-sync/proguard-rules-test.pro new file mode 100644 index 0000000000..27031cbff0 --- /dev/null +++ b/packages/test-sync/proguard-rules-test.pro @@ -0,0 +1,23 @@ +## We cannot discard unused symbols for the non-test configurations as it might all symbols not used +-dontoptimize +-dontshrink + +# io.realm.kotlin.test.mongodb.shared.FlexibleSyncConfigurationTests.toString_nonEmpty, +# SyncConfigTests.unsupportedSchemaTypesThrowException_flexibleSync and +# SyncConfigTests.unsupportedSchemaTypesThrowException_partitionBasedSync verifies exception +# messages with explicit class names in them +-keep class io.realm.kotlin.mongodb.internal.SyncConfigurationImpl +-keep class io.realm.kotlin.dynamic.DynamicRealmObject + +## Serialization related rules +-keepclasseswithmembers class **.*$Companion { + kotlinx.serialization.KSerializer serializer(...); +} +# If a companion has the serializer function, keep the companion field on the original type so that +# the reflective lookup succeeds. +-if class **.*$Companion { + kotlinx.serialization.KSerializer serializer(...); +} +-keepclassmembers class <1>.<2> { + <1>.<2>$Companion Companion; +} From bd747d5f13c0914afbc9b51ee4e7d57e76a08bf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus=20R=C3=B8rbech?= Date: Thu, 22 Dec 2022 19:43:24 +0100 Subject: [PATCH 2/6] Add missing minification rule --- packages/library-base/proguard-rules-consumer-common.pro | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/library-base/proguard-rules-consumer-common.pro b/packages/library-base/proguard-rules-consumer-common.pro index 5407efc5fc..e17818fd76 100644 --- a/packages/library-base/proguard-rules-consumer-common.pro +++ b/packages/library-base/proguard-rules-consumer-common.pro @@ -16,6 +16,7 @@ -keepclassmembers class io.realm.kotlin.dynamic.DynamicRealmObject, io.realm.kotlin.dynamic.DynamicMutableRealmObject { **$Companion Companion; } +-keep,allowobfuscation class ** implements io.realm.kotlin.types.BaseRealmObject -keep class ** implements io.realm.kotlin.internal.RealmObjectCompanion -keepclassmembers class ** implements io.realm.kotlin.types.BaseRealmObject { **$Companion Companion; From 583e37d717028841d0fe6881b6e3874524ceb997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus=20R=C3=B8rbech?= Date: Thu, 22 Dec 2022 22:52:37 +0100 Subject: [PATCH 3/6] Fix minification test stage --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8ea6a30ae8..0b4feaf1c2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -231,10 +231,11 @@ pipeline { testAndCollect("packages", 'cleanAllTests :test-sync:connectedAndroidtest -PincludeSdkModules=false -PtestBuildType=debugMinified') } ]) + sh 'rm mapping.zip || true' zip([ 'zipFile': 'mapping.zip', 'archive': true, - 'glob': 'test-sync/build/outputs/mapping/debugMinified/mapping.txt' + 'glob': 'packages/test-sync/build/outputs/mapping/debugMinified/mapping.txt' ]) } } From 78389380db67ae78ec41dfa651f768f4dddadaf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus=20R=C3=B8rbech?= Date: Fri, 6 Jan 2023 14:23:30 +0100 Subject: [PATCH 4/6] Cut dependency between test-sync and test-base --- packages/test-base/build.gradle.kts | 26 ++++++++----------- packages/test-sync/build.gradle.kts | 6 ++++- .../test/mongodb/sync/SyncDispatcher.kt | 23 ---------------- .../test/mongodb/sync/SyncDispatcher.kt | 21 --------------- .../test/mongodb/sync/SyncDispatcher.kt | 23 ---------------- .../test/mongodb/sync/SyncDispatcher.kt | 22 ---------------- 6 files changed, 16 insertions(+), 105 deletions(-) delete mode 100644 packages/test-sync/src/androidMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt delete mode 100644 packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt delete mode 100644 packages/test-sync/src/jvmMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt delete mode 100644 packages/test-sync/src/nativeDarwin/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt diff --git a/packages/test-base/build.gradle.kts b/packages/test-base/build.gradle.kts index b03f6bdb6d..d353d99799 100644 --- a/packages/test-base/build.gradle.kts +++ b/packages/test-base/build.gradle.kts @@ -19,7 +19,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithSimulatorTes plugins { id("org.jetbrains.kotlin.multiplatform") - id("com.android.library") + id("com.android.application") // Test relies on the compiler plugin, but we cannot apply our full plugin from within the same // gradle run, so we just apply the compiler plugin directly as a dependency below instead // id("io.realm.kotlin") @@ -111,22 +111,18 @@ android { } buildTypes { - // LibraryBuildType is not minifiable, but the current dependency from test-sync doesn't - // allow test-base to be configured as a library. To test test-base with minification - // change the AGP plugin to - // id("com.android.application") - // and uncomment the below buildType then you can run the full test suite with + // Can be tested with // ./gradlew test-base:clean test-base:connAT -PtestBuildType=debugMinified // Note that we cannot get memory consumption for non-debuggable build types so MemoryTests - // will fail - // testBuildType = (properties["testBuildType"] ?: "debug") as String - // create("debugMinified") { - // initWith(getByName("debug")) - // matchingFallbacks.add("debug") - // isMinifyEnabled = true - // isDebuggable = false - // proguardFiles("proguard-rules-test.pro") - // } + // will fail. + testBuildType = (properties["testBuildType"] ?: "debug") as String + create("debugMinified") { + initWith(getByName("debug")) + matchingFallbacks.add("debug") + isMinifyEnabled = true + isDebuggable = false + proguardFiles("proguard-rules-test.pro") + } } compileOptions { diff --git a/packages/test-sync/build.gradle.kts b/packages/test-sync/build.gradle.kts index 888bae8d79..aa9dbcfbc6 100644 --- a/packages/test-sync/build.gradle.kts +++ b/packages/test-sync/build.gradle.kts @@ -54,12 +54,12 @@ configurations.all { kotlin { sourceSets { val commonMain by getting { + kotlin.srcDir("$projectDir/../test-base/src/commonMain") dependencies { implementation(kotlin("stdlib-common")) implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.coroutines}") // FIXME AUTO-SETUP Removed automatic dependency injection to ensure observability of // requirements for now - implementation(project(":test-base")) // IDE Doesn't resolve library-base symbols if not adding it as an explicit // dependency. Probably due to our own custom dependency substitution above, but // shouldn't be an issue as it is already a transitive dependency of library-sync. @@ -80,6 +80,7 @@ kotlin { implementation("io.ktor:ktor-client-content-negotiation:${Versions.ktor}") implementation("com.squareup.okio:okio:${Versions.okio}") + implementation("org.jetbrains.kotlinx:kotlinx-datetime:${Versions.datetime}") } } @@ -151,6 +152,7 @@ kotlin { android("android") sourceSets { val androidMain by getting { + kotlin.srcDir("$projectDir/../test-base/src/androidMain") dependencies { implementation(kotlin("stdlib")) implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:${Versions.coroutines}") @@ -174,6 +176,7 @@ kotlin { jvm() sourceSets { val jvmMain by getting { + kotlin.srcDir("$projectDir/../test-base/src/jvmMain") dependencies { implementation("org.jetbrains.kotlin:kotlin-compiler-embeddable:${Versions.kotlin}") implementation("io.realm.kotlin:plugin-compiler:${Realm.version}") @@ -207,6 +210,7 @@ kotlin { val commonTest by getting val nativeDarwin by creating { dependsOn(commonMain) + kotlin.srcDir("$projectDir/../test-base/src/nativeDarwin") } val nativeDarwinTest by creating { dependsOn(commonTest) diff --git a/packages/test-sync/src/androidMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt b/packages/test-sync/src/androidMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt deleted file mode 100644 index f6147403d4..0000000000 --- a/packages/test-sync/src/androidMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2021 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.test.mongodb.sync - -import kotlinx.coroutines.CoroutineDispatcher -import kotlinx.coroutines.Dispatchers - -actual fun getDispatcher(): CoroutineDispatcher = Dispatchers.IO diff --git a/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt b/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt deleted file mode 100644 index a3a9054fa3..0000000000 --- a/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2021 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.test.mongodb.sync - -import kotlinx.coroutines.CoroutineDispatcher - -expect fun getDispatcher(): CoroutineDispatcher diff --git a/packages/test-sync/src/jvmMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt b/packages/test-sync/src/jvmMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt deleted file mode 100644 index f6147403d4..0000000000 --- a/packages/test-sync/src/jvmMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2021 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.test.mongodb.sync - -import kotlinx.coroutines.CoroutineDispatcher -import kotlinx.coroutines.Dispatchers - -actual fun getDispatcher(): CoroutineDispatcher = Dispatchers.IO diff --git a/packages/test-sync/src/nativeDarwin/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt b/packages/test-sync/src/nativeDarwin/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt deleted file mode 100644 index 7008f3e4b1..0000000000 --- a/packages/test-sync/src/nativeDarwin/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2021 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.test.mongodb.sync - -import io.realm.kotlin.internal.platform.singleThreadDispatcher -import kotlinx.coroutines.CoroutineDispatcher - -actual fun getDispatcher(): CoroutineDispatcher = singleThreadDispatcher("Sync Dispatcher") From 2c6c48488b66da590c566c857837bdc3441ce0db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus=20R=C3=B8rbech?= Date: Mon, 9 Jan 2023 11:44:40 +0100 Subject: [PATCH 5/6] Revert "Cut dependency between test-sync and test-base" This reverts commit 78389380db67ae78ec41dfa651f768f4dddadaf2. --- packages/test-base/build.gradle.kts | 26 +++++++++++-------- packages/test-sync/build.gradle.kts | 6 +---- .../test/mongodb/sync/SyncDispatcher.kt | 23 ++++++++++++++++ .../test/mongodb/sync/SyncDispatcher.kt | 21 +++++++++++++++ .../test/mongodb/sync/SyncDispatcher.kt | 23 ++++++++++++++++ .../test/mongodb/sync/SyncDispatcher.kt | 22 ++++++++++++++++ 6 files changed, 105 insertions(+), 16 deletions(-) create mode 100644 packages/test-sync/src/androidMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt create mode 100644 packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt create mode 100644 packages/test-sync/src/jvmMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt create mode 100644 packages/test-sync/src/nativeDarwin/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt diff --git a/packages/test-base/build.gradle.kts b/packages/test-base/build.gradle.kts index d353d99799..b03f6bdb6d 100644 --- a/packages/test-base/build.gradle.kts +++ b/packages/test-base/build.gradle.kts @@ -19,7 +19,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithSimulatorTes plugins { id("org.jetbrains.kotlin.multiplatform") - id("com.android.application") + id("com.android.library") // Test relies on the compiler plugin, but we cannot apply our full plugin from within the same // gradle run, so we just apply the compiler plugin directly as a dependency below instead // id("io.realm.kotlin") @@ -111,18 +111,22 @@ android { } buildTypes { - // Can be tested with + // LibraryBuildType is not minifiable, but the current dependency from test-sync doesn't + // allow test-base to be configured as a library. To test test-base with minification + // change the AGP plugin to + // id("com.android.application") + // and uncomment the below buildType then you can run the full test suite with // ./gradlew test-base:clean test-base:connAT -PtestBuildType=debugMinified // Note that we cannot get memory consumption for non-debuggable build types so MemoryTests - // will fail. - testBuildType = (properties["testBuildType"] ?: "debug") as String - create("debugMinified") { - initWith(getByName("debug")) - matchingFallbacks.add("debug") - isMinifyEnabled = true - isDebuggable = false - proguardFiles("proguard-rules-test.pro") - } + // will fail + // testBuildType = (properties["testBuildType"] ?: "debug") as String + // create("debugMinified") { + // initWith(getByName("debug")) + // matchingFallbacks.add("debug") + // isMinifyEnabled = true + // isDebuggable = false + // proguardFiles("proguard-rules-test.pro") + // } } compileOptions { diff --git a/packages/test-sync/build.gradle.kts b/packages/test-sync/build.gradle.kts index aa9dbcfbc6..888bae8d79 100644 --- a/packages/test-sync/build.gradle.kts +++ b/packages/test-sync/build.gradle.kts @@ -54,12 +54,12 @@ configurations.all { kotlin { sourceSets { val commonMain by getting { - kotlin.srcDir("$projectDir/../test-base/src/commonMain") dependencies { implementation(kotlin("stdlib-common")) implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.coroutines}") // FIXME AUTO-SETUP Removed automatic dependency injection to ensure observability of // requirements for now + implementation(project(":test-base")) // IDE Doesn't resolve library-base symbols if not adding it as an explicit // dependency. Probably due to our own custom dependency substitution above, but // shouldn't be an issue as it is already a transitive dependency of library-sync. @@ -80,7 +80,6 @@ kotlin { implementation("io.ktor:ktor-client-content-negotiation:${Versions.ktor}") implementation("com.squareup.okio:okio:${Versions.okio}") - implementation("org.jetbrains.kotlinx:kotlinx-datetime:${Versions.datetime}") } } @@ -152,7 +151,6 @@ kotlin { android("android") sourceSets { val androidMain by getting { - kotlin.srcDir("$projectDir/../test-base/src/androidMain") dependencies { implementation(kotlin("stdlib")) implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:${Versions.coroutines}") @@ -176,7 +174,6 @@ kotlin { jvm() sourceSets { val jvmMain by getting { - kotlin.srcDir("$projectDir/../test-base/src/jvmMain") dependencies { implementation("org.jetbrains.kotlin:kotlin-compiler-embeddable:${Versions.kotlin}") implementation("io.realm.kotlin:plugin-compiler:${Realm.version}") @@ -210,7 +207,6 @@ kotlin { val commonTest by getting val nativeDarwin by creating { dependsOn(commonMain) - kotlin.srcDir("$projectDir/../test-base/src/nativeDarwin") } val nativeDarwinTest by creating { dependsOn(commonTest) diff --git a/packages/test-sync/src/androidMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt b/packages/test-sync/src/androidMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt new file mode 100644 index 0000000000..f6147403d4 --- /dev/null +++ b/packages/test-sync/src/androidMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2021 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.test.mongodb.sync + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Dispatchers + +actual fun getDispatcher(): CoroutineDispatcher = Dispatchers.IO diff --git a/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt b/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt new file mode 100644 index 0000000000..a3a9054fa3 --- /dev/null +++ b/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2021 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.test.mongodb.sync + +import kotlinx.coroutines.CoroutineDispatcher + +expect fun getDispatcher(): CoroutineDispatcher diff --git a/packages/test-sync/src/jvmMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt b/packages/test-sync/src/jvmMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt new file mode 100644 index 0000000000..f6147403d4 --- /dev/null +++ b/packages/test-sync/src/jvmMain/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2021 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.test.mongodb.sync + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Dispatchers + +actual fun getDispatcher(): CoroutineDispatcher = Dispatchers.IO diff --git a/packages/test-sync/src/nativeDarwin/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt b/packages/test-sync/src/nativeDarwin/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt new file mode 100644 index 0000000000..7008f3e4b1 --- /dev/null +++ b/packages/test-sync/src/nativeDarwin/kotlin/io/realm/kotlin/test/mongodb/sync/SyncDispatcher.kt @@ -0,0 +1,22 @@ +/* + * Copyright 2021 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.test.mongodb.sync + +import io.realm.kotlin.internal.platform.singleThreadDispatcher +import kotlinx.coroutines.CoroutineDispatcher + +actual fun getDispatcher(): CoroutineDispatcher = singleThreadDispatcher("Sync Dispatcher") From 7d8e1e5e9c582ead99adb8bf9bd6c3aeafb4f5d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus=20R=C3=B8rbech?= Date: Mon, 9 Jan 2023 18:44:27 +0100 Subject: [PATCH 6/6] Update packages/gradle.properties Co-authored-by: Christian Melchior --- packages/gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gradle.properties b/packages/gradle.properties index 1054d36ade..75eb10e73c 100644 --- a/packages/gradle.properties +++ b/packages/gradle.properties @@ -33,5 +33,5 @@ kotlin.android.buildTypeAttribute.keep=false # includeSdkModules=true # includeTestModules=true testRepository=build/m2-buildrepo/ -# debug/debugMinified +# Must either be `debug` or `debugMinified` testBuildType=debug