Skip to content

Commit bf09f25

Browse files
committed
Fix compilation of metadata
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.
1 parent 8c0f726 commit bf09f25

File tree

9 files changed

+78
-81
lines changed

9 files changed

+78
-81
lines changed

core/androidNative/test/Util.kt

Lines changed: 0 additions & 10 deletions
This file was deleted.

core/build.gradle.kts

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,46 +37,48 @@ kotlin {
3737
explicitApi()
3838

3939
infra {
40-
common("nix") {
40+
common("tzfile") {
4141
// Tiers are in accordance with <https://kotlinlang.org/docs/native-target-support.html>
42-
common("linux") {
43-
// Tier 1
44-
target("linuxX64")
45-
// Tier 2
46-
target("linuxArm64")
47-
// Tier 4 (deprecated, but still in demand)
48-
target("linuxArm32Hfp")
42+
common("tzdbOnFilesystem") {
43+
common("linux") {
44+
// Tier 1
45+
target("linuxX64")
46+
// Tier 2
47+
target("linuxArm64")
48+
// Tier 4 (deprecated, but still in demand)
49+
target("linuxArm32Hfp")
50+
}
51+
common("darwin") {
52+
common("darwinDevices") {
53+
// Tier 1
54+
target("macosX64")
55+
target("macosArm64")
56+
// Tier 2
57+
target("watchosX64")
58+
target("watchosArm32")
59+
target("watchosArm64")
60+
target("tvosX64")
61+
target("tvosArm64")
62+
target("iosArm64")
63+
// Tier 3
64+
target("watchosDeviceArm64")
65+
}
66+
common("darwinSimulator") {
67+
// Tier 1
68+
target("iosSimulatorArm64")
69+
target("iosX64")
70+
// Tier 2
71+
target("watchosSimulatorArm64")
72+
target("tvosSimulatorArm64")
73+
}
74+
}
4975
}
5076
common("androidNative") {
5177
target("androidNativeArm32")
5278
target("androidNativeArm64")
5379
target("androidNativeX86")
5480
target("androidNativeX64")
5581
}
56-
common("darwin") {
57-
common("darwinDevices") {
58-
// Tier 1
59-
target("macosX64")
60-
target("macosArm64")
61-
// Tier 2
62-
target("watchosX64")
63-
target("watchosArm32")
64-
target("watchosArm64")
65-
target("tvosX64")
66-
target("tvosArm64")
67-
target("iosArm64")
68-
// Tier 3
69-
target("watchosDeviceArm64")
70-
}
71-
common("darwinSimulator") {
72-
// Tier 1
73-
target("iosSimulatorArm64")
74-
target("iosX64")
75-
// Tier 2
76-
target("watchosSimulatorArm64")
77-
target("tvosSimulatorArm64")
78-
}
79-
}
8082
}
8183
// Tier 3
8284
common("windows") {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2019-2023 JetBrains s.r.o. and contributors.
3+
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4+
*/
5+
6+
@file:OptIn(ExperimentalForeignApi::class, UnsafeNumber::class)
7+
package kotlinx.datetime.internal
8+
9+
import kotlinx.cinterop.*
10+
import platform.posix.*
11+
12+
internal fun Path.chaseSymlinks(maxDepth: Int = 100): Path {
13+
var realPath = this
14+
var depth = maxDepth
15+
while (true) {
16+
realPath = realPath.readLink() ?: break
17+
if (depth-- == 0) throw RuntimeException("Too many levels of symbolic links")
18+
}
19+
return realPath
20+
}
21+
22+
internal fun Path.traverseDirectory(exclude: Set<String> = emptySet(), stripLeadingComponents: Int = this.components.size, actionOnFile: (Path) -> Unit) {
23+
val handler = opendir(this.toString()) ?: return
24+
try {
25+
while (true) {
26+
val entry = readdir(handler) ?: break
27+
val name = entry.pointed.d_name.toKString()
28+
if (name == "." || name == "..") continue
29+
if (name in exclude) continue
30+
val path = Path(isAbsolute, components + name)
31+
val info = path.check() ?: continue // skip broken symlinks
32+
if (info.isDirectory) {
33+
if (!info.isSymlink) {
34+
path.traverseDirectory(exclude, stripLeadingComponents, actionOnFile)
35+
}
36+
} else {
37+
actionOnFile(Path(false, path.components.drop(stripLeadingComponents)))
38+
}
39+
}
40+
} finally {
41+
closedir(handler)
42+
}
43+
}

core/nix/test/TimeZoneRulesCompleteTest.kt renamed to core/tzdbOnFilesystem/test/TimeZoneRulesCompleteTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import kotlin.test.*
1515
class TimeZoneRulesCompleteTest {
1616
@OptIn(ExperimentalEncodingApi::class)
1717
@Test
18-
@NoAndroid
1918
fun iterateOverAllTimezones() {
2019
val root = Path.fromString("/usr/share/zoneinfo")
2120
val tzdb = TzdbOnFilesystem(root)
File renamed without changes.

core/nix/src/internal/filesystem.kt renamed to core/tzfile/src/internal/filesystem.kt

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 JetBrains s.r.o. and contributors.
2+
* Copyright 2019-2024 JetBrains s.r.o. and contributors.
33
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
44
*/
55

@@ -53,45 +53,12 @@ internal class Path(val isAbsolute: Boolean, val components: List<String>) {
5353
}
5454
}
5555

56-
internal fun Path.chaseSymlinks(maxDepth: Int = 100): Path {
57-
var realPath = this
58-
var depth = maxDepth
59-
while (true) {
60-
realPath = realPath.readLink() ?: break
61-
if (depth-- == 0) throw RuntimeException("Too many levels of symbolic links")
62-
}
63-
return realPath
64-
}
65-
6656
// `stat(2)` lists the other available fields
6757
internal interface PathInfo {
6858
val isDirectory: Boolean
6959
val isSymlink: Boolean
7060
}
7161

72-
internal fun Path.traverseDirectory(exclude: Set<String> = emptySet(), stripLeadingComponents: Int = this.components.size, actionOnFile: (Path) -> Unit) {
73-
val handler = opendir(this.toString()) ?: return
74-
try {
75-
while (true) {
76-
val entry = readdir(handler) ?: break
77-
val name = entry.pointed.d_name.toKString()
78-
if (name == "." || name == "..") continue
79-
if (name in exclude) continue
80-
val path = Path(isAbsolute, components + name)
81-
val info = path.check() ?: continue // skip broken symlinks
82-
if (info.isDirectory) {
83-
if (!info.isSymlink) {
84-
path.traverseDirectory(exclude, stripLeadingComponents, actionOnFile)
85-
}
86-
} else {
87-
actionOnFile(Path(false, path.components.drop(stripLeadingComponents)))
88-
}
89-
}
90-
} finally {
91-
closedir(handler)
92-
}
93-
}
94-
9562
internal fun Path.readBytes(): ByteArray {
9663
val handler = fopen(this.toString(), "rb") ?: throw RuntimeException("Cannot open file $this")
9764
try {

core/nix/test/Util.kt renamed to core/tzfile/test/Util.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55

66
package kotlinx.datetime.test
77

8-
@OptIn(ExperimentalMultiplatform::class)
9-
@OptionalExpectation
10-
expect annotation class NoAndroid()
11-
128
// od --format=x1 --output-duplicates --address-radix=n --width=16 /usr/share/zoneinfo/Europe/Berlin |
139
// sed -e 's/\b\(\w\)/0x\1/g' -e 's/\(\w\)\b/\1,/g'
1410
// Do not remove the type annotation, otherwise the compiler slows down to a crawl for this file even more.

0 commit comments

Comments
 (0)