Skip to content

Commit 93f8268

Browse files
committed
Make Android Native a child of Linux.
and workaround `platform.posix.DIR` not being available there.
1 parent 68d0c8f commit 93f8268

8 files changed

Lines changed: 32 additions & 94 deletions

File tree

okio/build.gradle.kts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ plugins {
2828
* | |-- mingw
2929
* | | '-- mingwX64
3030
* | '-- unix
31-
* | |-- androidNative
32-
* | | |-- androidNativeArm64
33-
* | | |-- androidNativeArm32
34-
* | | |-- androidNativeX64
35-
* | | |-- androidNativeX86
3631
* | |-- apple
3732
* | | |-- iosArm64
3833
* | | |-- iosX64
@@ -43,7 +38,12 @@ plugins {
4338
* | | |-- watchosArm64
4439
* | '-- linux
4540
* | |-- linuxX64
46-
* | '-- linuxArm64
41+
* | |-- linuxArm64
42+
* | '-- androidNative
43+
* | |-- androidNativeArm64
44+
* | |-- androidNativeArm32
45+
* | |-- androidNativeX64
46+
* | |-- androidNativeX86
4747
* '-- wasm
4848
* '-- wasmJs
4949
* '-- wasmWasi
@@ -168,19 +168,13 @@ kotlin {
168168
createSourceSet("unixMain", parent = nativeMain)
169169
.also { unixMain ->
170170
unixMain.dependsOn(nonJsMain)
171-
createSourceSet(
172-
"androidNativeMain",
173-
parent = unixMain,
174-
children = androidNativeTargets,
175-
).also { androidNative ->
176-
androidNative.dependsOn(nonAppleMain)
177-
}
178171
createSourceSet(
179172
"linuxMain",
180173
parent = unixMain,
181174
children = linuxTargets,
182175
).also { linuxMain ->
183176
linuxMain.dependsOn(nonAppleMain)
177+
createSourceSet("androidNativeMain", parent = linuxMain, children = androidNativeTargets)
184178
}
185179
createSourceSet("appleMain", parent = unixMain, children = appleTargets)
186180
}

okio/src/androidNativeMain/kotlin/okio/AndroidNativePosixVariant.kt

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (C) 2026 Square, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package platform.posix
17+
18+
/**
19+
* Workaround `platform.posix.DIR` not being available on Android Native.
20+
*/
21+
internal typealias DIR = cnames.structs.DIR

okio/src/appleMain/kotlin/okio/ApplePosixVariant.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package okio
1717

18-
import kotlinx.cinterop.CValuesRef
1918
import kotlinx.cinterop.alloc
2019
import kotlinx.cinterop.memScoped
2120
import kotlinx.cinterop.ptr
@@ -45,9 +44,3 @@ internal actual fun PosixFileSystem.variantMetadataOrNull(path: Path): FileMetad
4544
)
4645
}
4746
}
48-
49-
internal actual val DEFFILEMODE: Int get() = platform.posix.DEFFILEMODE
50-
internal actual typealias DIR = platform.posix.DIR
51-
internal actual fun opendir(path: String) = platform.posix.opendir(path)
52-
internal actual fun readdir(dir: CValuesRef<DIR>) = platform.posix.readdir(dir)
53-
internal actual fun closedir(dir: CValuesRef<DIR>) = platform.posix.closedir(dir)

okio/src/linuxMain/kotlin/okio/LinuxPosixVariant.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package okio
1717

18-
import kotlinx.cinterop.CValuesRef
1918
import kotlinx.cinterop.alloc
2019
import kotlinx.cinterop.memScoped
2120
import kotlinx.cinterop.ptr
@@ -45,9 +44,3 @@ internal actual fun PosixFileSystem.variantMetadataOrNull(path: Path): FileMetad
4544
)
4645
}
4746
}
48-
49-
internal actual val DEFFILEMODE: Int get() = platform.posix.DEFFILEMODE
50-
internal actual typealias DIR = cnames.structs.__dirstream
51-
internal actual fun opendir(path: String) = platform.posix.opendir(path)
52-
internal actual fun readdir(dir: CValuesRef<DIR>) = platform.posix.readdir(dir)
53-
internal actual fun closedir(dir: CValuesRef<DIR>) = platform.posix.closedir(dir)

okio/src/mingwX64Main/kotlin/okio/WindowsPosixVariant.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package okio
1717

1818
import kotlinx.cinterop.CPointer
19-
import kotlinx.cinterop.CValuesRef
2019
import kotlinx.cinterop.alloc
2120
import kotlinx.cinterop.memScoped
2221
import kotlinx.cinterop.ptr
@@ -205,8 +204,3 @@ internal actual fun PosixFileSystem.variantOpenReadWrite(
205204
internal actual fun PosixFileSystem.variantCreateSymlink(source: Path, target: Path) {
206205
throw IOException("Not supported")
207206
}
208-
209-
internal actual typealias DIR = platform.posix.DIR
210-
internal actual fun opendir(path: String) = platform.posix.opendir(path)
211-
internal actual fun readdir(dir: CValuesRef<DIR>) = platform.posix.readdir(dir)
212-
internal actual fun closedir(dir: CValuesRef<DIR>) = platform.posix.closedir(dir)

okio/src/nativeMain/kotlin/okio/PosixFileSystem.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515
*/
1616
package okio
1717

18-
import kotlinx.cinterop.CPointed
1918
import kotlinx.cinterop.CPointer
20-
import kotlinx.cinterop.CValuesRef
2119
import kotlinx.cinterop.get
2220
import okio.Path.Companion.toPath
2321
import okio.internal.toPath
2422
import platform.posix.EEXIST
23+
import platform.posix.closedir
2524
import platform.posix.dirent
2625
import platform.posix.errno
26+
import platform.posix.opendir
27+
import platform.posix.readdir
2728
import platform.posix.set_posix_errno
2829

2930
internal object PosixFileSystem : FileSystem() {
@@ -116,8 +117,3 @@ internal object PosixFileSystem : FileSystem() {
116117

117118
override fun toString() = "PosixSystemFileSystem"
118119
}
119-
120-
internal expect class DIR : CPointed
121-
internal expect fun opendir(path: String): CPointer<DIR>?
122-
internal expect fun readdir(dir: CValuesRef<DIR>): CPointer<dirent>?
123-
internal expect fun closedir(dir: CValuesRef<DIR>): Int

okio/src/unixMain/kotlin/okio/UnixPosixVariant.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ internal actual fun PosixFileSystem.variantOpenReadOnly(file: Path): FileHandle
129129
return UnixFileHandle(false, openFile)
130130
}
131131

132-
internal expect val DEFFILEMODE: Int
132+
internal const val DEFFILEMODE = 0b110110110 /* octal 666 */
133133

134134
internal actual fun PosixFileSystem.variantOpenReadWrite(
135135
file: Path,

0 commit comments

Comments
 (0)