8000 Make `paging-testing` multiplatform by moving everything to `common*` by veyndan · Pull Request #609 · androidx/androidx · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations 8000
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add Atomic shims to paging-testing
  • Loading branch information
veyndan committed Sep 11, 2023
commit 9bbb49472586b5eb0c96429d74cfcdc20a913ea0
47 changes: 46 additions & 1 deletion paging/paging-testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@
*/

import androidx.build.LibraryType
import androidx.build.KmpPlatformsKt
import androidx.build.PlatformIdentifier
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import androidx.build.Publish
import org.jetbrains.kotlin.konan.target.Family

plugins {
id("AndroidXPlugin")
id("com.android.library")
}

def macEnabled = KmpPlatformsKt.enableMac(project)
def linuxEnabled = KmpPlatformsKt.enableLinux(project)

androidXMultiplatform {
jvm()
mac()
Expand All @@ -33,12 +39,17 @@ androidXMultiplatform {
defaultPlatform(PlatformIdentifier.ANDROID)

sourceSets {
androidMain {
commonMain {
dependencies {
api(libs.kotlinStdlib)
implementation(project(":paging:paging-common"))
}
}

androidMain {
dependsOn(jvmMain)
}

androidUnitTest {
dependencies {
implementation(libs.junit)
Expand All @@ -49,6 +60,40 @@ androidXMultiplatform {
implementation(libs.truth)
}
}

if (macEnabled || linuxEnabled) {
nativeMain {
dependsOn(commonMain)
dependencies {
implementation(libs.atomicFu)
}
}
}
if (macEnabled) {
darwinMain {
dependsOn(nativeMain)
}
}
if (linuxEnabled) {
linuxMain {
dependsOn(nativeMain)
}
}

targets.all { target ->
if (target.platformType == KotlinPlatformType.native) {
target.compilations["main"].defaultSourceSet {
def konanTargetFamily = target.konanTarget.family
if (konanTargetFamily == Family.OSX || konanTargetFamily == Family.IOS) {
dependsOn(darwinMain)
} else if (konanTargetFamily == Family.LINUX) {
dependsOn(linuxMain)
} else {
throw new GradleException("unknown native target ${target}")
}
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2023 The Android Open Source Project
*
* 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 androidx.paging.testing.internal

internal expect class AtomicInt(initialValue: Int) {
fun get(): Int
fun set(value: Int)
}

internal expect class AtomicBoolean(initialValue: Boolean) {
fun get(): Boolean
fun set(value: Boolean)
fun compareAndSet(expect: Boolean, update: Boolean): Boolean
}

internal expect class AtomicRef<T>(initialValue: T) {
fun get(): T
fun set(value: T)
fun getAndSet(value: T): T
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2023 The Android Open Source Project
*
* 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.
*/
@file:Suppress("ACTUAL_WITHOUT_EXPECT") // https://youtrack.jetbrains.com/issue/KT-37316
package androidx.paging.testing.internal

internal actual typealias AtomicInt = java.util.concurrent.atomic.AtomicInteger

internal actual typealias AtomicBoolean = java.util.concurrent.atomic.AtomicBoolean

internal actual typealias AtomicRef<T> = java.util.concurrent.atomic.AtomicReference<T>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2023 The Android Open Source Project
*
* 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.
*/

@file:OptIn(ExperimentalForeignApi::class)

package androidx.paging.testing.internal

import kotlinx.atomicfu.AtomicBoolean as AtomicFuAtomicBoolean
import kotlinx.atomicfu.AtomicInt as AtomicFuAtomicInt
import kotlinx.atomicfu.AtomicRef as AtomicFuAtomicRef
import kotlinx.atomicfu.atomic
import kotlinx.cinterop.ExperimentalForeignApi

internal actual class AtomicInt actual constructor(initialValue: Int) {
private var delegate: AtomicFuAtomicInt = atomic(initialValue)
private var property by delegate

actual fun get(): Int = property

actual fun set(value: Int) {
property = value
}
}

internal actual class AtomicBoolean actual constructor(initialValue: Boolean) {
private var delegate: AtomicFuAtomicBoolean = atomic(initialValue)
private var property by delegate

actual fun get(): Boolean = property

actual fun set(value: Boolean) {
property = value
}

actual fun compareAndSet(expect: Boolean, update: Boolean): Boolean {
return delegate.compareAndSet(expect, update)
}
}

internal actual class AtomicRef<T> actual constructor(initialValue: T) {
private var delegate: AtomicFuAtomicRef<T> = atomic(initialValue)
private var property by delegate

actual fun get(): T = property

actual fun set(value: T) {
property = value
}

actual fun getAndSet(value: T): T {
return delegate.getAndSet(value)
}
}
0