Skip to content

Commit

Permalink
Fix compilation of metadata
Browse files Browse the repository at this point in the history
For some reason, even though the code itself compiles and works,
metadata couldn't compile. This is fixed by more carefully
separating which code is compiled for each target, so unneeded
code doesn't get included in the Native Android implementation.
  • Loading branch information
dkhalanskyjb committed Feb 26, 2024
1 parent 8c0f726 commit bf09f25
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 81 deletions.
10 changes: 0 additions & 10 deletions core/androidNative/test/Util.kt

This file was deleted.

66 changes: 34 additions & 32 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,46 +37,48 @@ kotlin {
explicitApi()

infra {
common("nix") {
common("tzfile") {
// Tiers are in accordance with <https://kotlinlang.org/docs/native-target-support.html>
common("linux") {
// Tier 1
target("linuxX64")
// Tier 2
target("linuxArm64")
// Tier 4 (deprecated, but still in demand)
target("linuxArm32Hfp")
common("tzdbOnFilesystem") {
common("linux") {
// Tier 1
target("linuxX64")
// Tier 2
target("linuxArm64")
// Tier 4 (deprecated, but still in demand)
target("linuxArm32Hfp")
}
common("darwin") {
common("darwinDevices") {
// Tier 1
target("macosX64")
target("macosArm64")
// Tier 2
target("watchosX64")
target("watchosArm32")
target("watchosArm64")
target("tvosX64")
target("tvosArm64")
target("iosArm64")
// Tier 3
target("watchosDeviceArm64")
}
common("darwinSimulator") {
// Tier 1
target("iosSimulatorArm64")
target("iosX64")
// Tier 2
target("watchosSimulatorArm64")
target("tvosSimulatorArm64")
}
}
}
common("androidNative") {
target("androidNativeArm32")
target("androidNativeArm64")
target("androidNativeX86")
target("androidNativeX64")
}
common("darwin") {
common("darwinDevices") {
// Tier 1
target("macosX64")
target("macosArm64")
// Tier 2
target("watchosX64")
target("watchosArm32")
target("watchosArm64")
target("tvosX64")
target("tvosArm64")
target("iosArm64")
// Tier 3
target("watchosDeviceArm64")
}
common("darwinSimulator") {
// Tier 1
target("iosSimulatorArm64")
target("iosX64")
// Tier 2
target("watchosSimulatorArm64")
target("tvosSimulatorArm64")
}
}
}
// Tier 3
common("windows") {
Expand Down
File renamed without changes.
43 changes: 43 additions & 0 deletions core/tzdbOnFilesystem/src/internal/filesystem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2019-2023 JetBrains s.r.o. and contributors.
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
*/

@file:OptIn(ExperimentalForeignApi::class, UnsafeNumber::class)
package kotlinx.datetime.internal

import kotlinx.cinterop.*
import platform.posix.*

internal fun Path.chaseSymlinks(maxDepth: Int = 100): Path {
var realPath = this
var depth = maxDepth
while (true) {
realPath = realPath.readLink() ?: break
if (depth-- == 0) throw RuntimeException("Too many levels of symbolic links")
}
return realPath
}

internal fun Path.traverseDirectory(exclude: Set<String> = emptySet(), stripLeadingComponents: Int = this.components.size, actionOnFile: (Path) -> Unit) {
val handler = opendir(this.toString()) ?: return
try {
while (true) {
val entry = readdir(handler) ?: break
val name = entry.pointed.d_name.toKString()
if (name == "." || name == "..") continue
if (name in exclude) continue
val path = Path(isAbsolute, components + name)
val info = path.check() ?: continue // skip broken symlinks
if (info.isDirectory) {
if (!info.isSymlink) {
path.traverseDirectory(exclude, stripLeadingComponents, actionOnFile)
}
} else {
actionOnFile(Path(false, path.components.drop(stripLeadingComponents)))
}
}
} finally {
closedir(handler)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import kotlin.test.*
class TimeZoneRulesCompleteTest {
@OptIn(ExperimentalEncodingApi::class)
@Test
@NoAndroid
fun iterateOverAllTimezones() {
val root = Path.fromString("/usr/share/zoneinfo")
val tzdb = TzdbOnFilesystem(root)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 JetBrains s.r.o. and contributors.
* Copyright 2019-2024 JetBrains s.r.o. and contributors.
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
*/

Expand Down Expand Up @@ -53,45 +53,12 @@ internal class Path(val isAbsolute: Boolean, val components: List<String>) {
}
}

internal fun Path.chaseSymlinks(maxDepth: Int = 100): Path {
var realPath = this
var depth = maxDepth
while (true) {
realPath = realPath.readLink() ?: break
if (depth-- == 0) throw RuntimeException("Too many levels of symbolic links")
}
return realPath
}

// `stat(2)` lists the other available fields
internal interface PathInfo {
val isDirectory: Boolean
val isSymlink: Boolean
}

internal fun Path.traverseDirectory(exclude: Set<String> = emptySet(), stripLeadingComponents: Int = this.components.size, actionOnFile: (Path) -> Unit) {
val handler = opendir(this.toString()) ?: return
try {
while (true) {
val entry = readdir(handler) ?: break
val name = entry.pointed.d_name.toKString()
if (name == "." || name == "..") continue
if (name in exclude) continue
val path = Path(isAbsolute, components + name)
val info = path.check() ?: continue // skip broken symlinks
if (info.isDirectory) {
if (!info.isSymlink) {
path.traverseDirectory(exclude, stripLeadingComponents, actionOnFile)
}
} else {
actionOnFile(Path(false, path.components.drop(stripLeadingComponents)))
}
}
} finally {
closedir(handler)
}
}

internal fun Path.readBytes(): ByteArray {
val handler = fopen(this.toString(), "rb") ?: throw RuntimeException("Cannot open file $this")
try {
Expand Down
File renamed without changes.
4 changes: 0 additions & 4 deletions core/nix/test/Util.kt → core/tzfile/test/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@

package kotlinx.datetime.test

@OptIn(ExperimentalMultiplatform::class)
@OptionalExpectation
expect annotation class NoAndroid()

// od --format=x1 --output-duplicates --address-radix=n --width=16 /usr/share/zoneinfo/Europe/Berlin |
// sed -e 's/\b\(\w\)/0x\1/g' -e 's/\(\w\)\b/\1,/g'
// Do not remove the type annotation, otherwise the compiler slows down to a crawl for this file even more.
Expand Down

0 comments on commit bf09f25

Please sign in to comment.