Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
a4734c7
fix: create JMESPATH flattenIfPossible functions for Lists (#1169)
0marperez Dec 16, 2024
7911a94
chore: release 1.3.30
aws-sdk-kotlin-ci Dec 16, 2024
7085c8a
chore: bump snapshot version to 1.3.31-SNAPSHOT
aws-sdk-kotlin-ci Dec 16, 2024
4575023
misc: enhance support for replayable instances of `InputStream` (#1197)
lauzadis Dec 18, 2024
b0a4bac
chore: release 1.3.31
aws-sdk-kotlin-ci Dec 18, 2024
80f4538
chore: bump snapshot version to 1.3.32-SNAPSHOT
aws-sdk-kotlin-ci Dec 18, 2024
e9d16a9
fix: CBOR protocol test assertions / blob serialization (#1198)
lauzadis Dec 18, 2024
48849a1
fix: correctly serialize subset of shape's members when configured (#…
lauzadis Jan 6, 2025
ded3a4b
chore: release 1.3.32
aws-sdk-kotlin-ci Jan 6, 2025
d97e8ba
chore: bump snapshot version to 1.3.33-SNAPSHOT
aws-sdk-kotlin-ci Jan 6, 2025
78f17f3
chore: add *-main to branch workflows (#1209)
ianbotsf Jan 8, 2025
d06ee0a
chore: add .kotlin/ to .gitignore (#1208)
ianbotsf Jan 8, 2025
d2e7c91
chore: smithy version bump (#1213)
0marperez Jan 10, 2025
5a2df8f
chore: release 1.3.33
aws-sdk-kotlin-ci Jan 10, 2025
003633b
chore: bump snapshot version to 1.3.34-SNAPSHOT
aws-sdk-kotlin-ci Jan 10, 2025
5f5ec8f
feat: add `AuthTokenGenerator` (#1212)
lauzadis Jan 10, 2025
3fe1b5e
chore: release 1.3.34
aws-sdk-kotlin-ci Jan 10, 2025
0bba308
chore: bump snapshot version to 1.3.35-SNAPSHOT
aws-sdk-kotlin-ci Jan 10, 2025
52e4439
misc: merge v1.4 into main (#1218)
0marperez Jan 15, 2025
e0c25d6
feat: support default checksums (#1191)
0marperez Jan 15, 2025
14e0958
chore: release 1.4.0
aws-sdk-kotlin-ci Jan 15, 2025
ed95d7b
chore: bump snapshot version to 1.4.1-SNAPSHOT
aws-sdk-kotlin-ci Jan 15, 2025
a4ace35
fix: add 0.9.x aws-crt-kotlin transform (#1220)
lauzadis Jan 16, 2025
15e5f0c
fix: Ensure `Host` header is included when signing auth tokens (#1222)
lauzadis Jan 16, 2025
447ac10
chore: release 1.4.1
aws-sdk-kotlin-ci Jan 16, 2025
0f8db44
chore: bump snapshot version to 1.4.2-SNAPSHOT
aws-sdk-kotlin-ci Jan 16, 2025
8b33693
fix: address various failing protocol tests (#1223)
lauzadis Jan 23, 2025
03badf9
misc: re-enable `kotlinWarningsAsErrors=true` (#1224)
lauzadis Jan 23, 2025
9f44cdb
fix: ignore hop-by-hop headers when signing requests (#1227)
ianbotsf Jan 28, 2025
97ac447
chore: release 1.4.2
aws-sdk-kotlin-ci Jan 28, 2025
b7e50e3
chore: bump snapshot version to 1.4.3-SNAPSHOT
aws-sdk-kotlin-ci Jan 28, 2025
35ef3a1
Implement PlatformNative (except for getAllEnvVars), add `deleteFile`…
lauzadis Jan 30, 2025
002099b
ktlintFormat
lauzadis Jan 30, 2025
f2572f6
Use upload-artifact@v4
lauzadis Jan 30, 2025
9c201e2
apiDump
lauzadis Jan 30, 2025
c1f2eef
Rename test to `SystemPlatformProviderTest`
lauzadis Jan 30, 2025
e6f0735
Check USERPROFILE too
lauzadis Jan 30, 2025
e6357f9
misc: add telemetry configuration to DefaultAwsSigner (#1226)
xinsong-cui Jan 30, 2025
22886ed
Remove `deleteFile`, use temp dir
lauzadis Jan 31, 2025
992efbc
Remove usage of deleteFile
lauzadis Jan 31, 2025
a8a22da
Use correct tempdir on windows
lauzadis Jan 31, 2025
7115a34
ktlint
lauzadis Jan 31, 2025
c5a138f
Remove transfer-encoding from expected signed headers
lauzadis Jan 31, 2025
0323e98
Merge branch 'main' of github.com:smithy-lang/smithy-kotlin into kn-p…
lauzadis Feb 1, 2025
cda0523
Revert
lauzadis Feb 3, 2025
e5c0f64
Merge branch 'kn-main' of github.com:smithy-lang/smithy-kotlin into k…
lauzadis Feb 3, 2025
d0dc45d
Implement getAllEnvVars
lauzadis Feb 3, 2025
a674cf4
Update filePathSeparator for Windows
lauzadis Feb 3, 2025
426bcfe
e -> _
lauzadis Feb 3, 2025
f4fdfe3
Merge branch 'kn-main' of github.com:smithy-lang/smithy-kotlin into k…
lauzadis Feb 4, 2025
aa44461
PR feedback
lauzadis Feb 4, 2025
6bc63cf
Add LinuxX64 test
lauzadis Feb 4, 2025
5e5c541
ktlint
lauzadis Feb 4, 2025
e282e5c
Expand support of Apple platforms
lauzadis Feb 4, 2025
ee85998
Remove debug test
lauzadis Feb 4, 2025
7dc3766
ktlint
lauzadis Feb 4, 2025
8142608
apiDump new OsFamily
lauzadis Feb 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ kotlin.code.style=official
kotlin.incremental.js=true
kotlin.incremental.multiplatform=true
kotlin.mpp.stability.nowarn=true
kotlin.mpp.enableCInteropCommonization=true
kotlin.native.ignoreDisabledTargets=true

# atomicfu
Expand Down
3 changes: 3 additions & 0 deletions runtime/runtime-core/api/runtime-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -2383,9 +2383,12 @@ public final class aws/smithy/kotlin/runtime/util/OperatingSystem {
public final class aws/smithy/kotlin/runtime/util/OsFamily : java/lang/Enum {
public static final field Android Laws/smithy/kotlin/runtime/util/OsFamily;
public static final field Ios Laws/smithy/kotlin/runtime/util/OsFamily;
public static final field IpadOs Laws/smithy/kotlin/runtime/util/OsFamily;
public static final field Linux Laws/smithy/kotlin/runtime/util/OsFamily;
public static final field MacOs Laws/smithy/kotlin/runtime/util/OsFamily;
public static final field TvOs Laws/smithy/kotlin/runtime/util/OsFamily;
public static final field Unknown Laws/smithy/kotlin/runtime/util/OsFamily;
public static final field WatchOs Laws/smithy/kotlin/runtime/util/OsFamily;
public static final field Windows Laws/smithy/kotlin/runtime/util/OsFamily;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public fun toString ()Ljava/lang/String;
Expand Down
13 changes: 13 additions & 0 deletions runtime/runtime-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

plugins {
alias(libs.plugins.kotlinx.serialization)
}
Expand Down Expand Up @@ -54,4 +56,15 @@ kotlin {
languageSettings.optIn("aws.smithy.kotlin.runtime.InternalApi")
}
}

targets.withType<KotlinNativeTarget> {
compilations["main"].cinterops {
val interopDir = "$projectDir/native/src/nativeInterop/cinterop"
create("environ") {
includeDirs(interopDir)
packageName("aws.smithy.platform.posix")
headers(listOf("$interopDir/environ.h"))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public enum class OsFamily {
Windows,
Android,
Ios,
IpadOs,
TvOs,
WatchOs,
Unknown,
;

Expand All @@ -67,6 +70,9 @@ public enum class OsFamily {
Windows -> "windows"
Android -> "android"
Ios -> "ios"
IpadOs -> "ipados"
TvOs -> "tvos"
WatchOs -> "watchos"
Unknown -> "unknown"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package aws.smithy.kotlin.runtime.util

import kotlinx.coroutines.test.runTest
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertNotEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNull
import kotlin.test.assertTrue

class SystemPlatformProviderTest {
@Test
fun testReadWriteFile() = runTest {
val ps = PlatformProvider.System

val tempDir = if (ps.osInfo().family == OsFamily.Windows) {
requireNotNull(ps.getenv("TEMP")) { "%TEMP% unexpectedly null" }
} else {
"/tmp"
}
val path = "$tempDir/testReadWriteFile-${Uuid.random()}.txt"

val expected = "Hello, File!".encodeToByteArray()

ps.writeFile(path, expected)
assertTrue(ps.fileExists(path))

val actual = ps.readFileOrNull(path)
assertContentEquals(expected, actual)
}

@Test
fun testGetEnv() = runTest {
val envVarKeys = listOf("PATH", "USERPROFILE") // PATH is not set on Windows CI
assertNotNull(
envVarKeys.firstNotNullOfOrNull { PlatformProvider.System.getenv(it) },
)

assertNull(PlatformProvider.System.getenv("THIS_ENV_VAR_IS_NOT_SET"))
}

@Test
fun testGetAllEnvVars() = runTest {
val allEnv = PlatformProvider.System.getAllEnvVars()
assertTrue(allEnv.isNotEmpty())

val envVarKeys = listOf("PATH", "USERPROFILE") // PATH is not set on Windows CI
assertTrue(
envVarKeys.any { allEnv.contains(it) },
)
}

@Test
fun testOsInfo() = runTest {
val osInfo = PlatformProvider.System.osInfo()
assertNotEquals(OsFamily.Unknown, osInfo.family)
}
Comment on lines +57 to +61
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Do we have tests anywhere to verify that the correct OS family is returned as opposed to verifying the incorrect one isn't?

Copy link
Contributor Author

@lauzadis lauzadis Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we don't. Since this is a common test it's not possible to assert on a specific OS family. I'll try making a target-specific source set (i.e. linuxx64) and add a test there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a LinuxX64 test

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package aws.smithy.kotlin.runtime.util

import kotlinx.coroutines.test.runTest
import kotlin.test.Test
import kotlin.test.assertEquals

class SystemPlatformProviderLinuxX64Test {
@Test
fun testOsInfo() = runTest {
val osInfo = PlatformProvider.System.osInfo()
assertEquals(OsFamily.Linux, osInfo.family)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,104 @@
*/
package aws.smithy.kotlin.runtime.util

import aws.smithy.kotlin.runtime.io.IOException
import aws.smithy.kotlin.runtime.io.internal.SdkDispatchers
import aws.smithy.platform.posix.get_environ_ptr
import kotlinx.cinterop.*
import kotlinx.coroutines.withContext
import platform.posix.*

internal actual object SystemDefaultProvider : PlatformProvider {
actual override fun getAllEnvVars(): Map<String, String> {
TODO("Not yet implemented")
actual override fun getAllEnvVars(): Map<String, String> = memScoped {
val environ = get_environ_ptr()
generateSequence(0) { it + 1 }
.map { idx -> environ?.get(idx)?.toKString() }
.takeWhile { it != null }
.associate { env ->
val parts = env?.split("=", limit = 2)
check(parts?.size == 2) { "Environment entry \"$env\" is malformed" }
parts[0] to parts[1]
}
}

actual override fun getenv(key: String): String? {
TODO("Not yet implemented")
}
actual override fun getenv(key: String): String? = platform.posix.getenv(key)?.toKString()

actual override val filePathSeparator: String
get() = TODO("Not yet implemented")
get() = when (osInfo().family) {
OsFamily.Windows -> "\\"
else -> "/"
}

actual override suspend fun readFileOrNull(path: String): ByteArray? {
TODO("Not yet implemented")
}
actual override suspend fun readFileOrNull(path: String): ByteArray? = withContext(SdkDispatchers.IO) {
try {
val file = fopen(path, "rb") ?: return@withContext null

actual override suspend fun writeFile(path: String, data: ByteArray) {
TODO("Not yet implemented")
}
try {
// Get file size
fseek(file, 0L, SEEK_END)
val size = ftell(file)
fseek(file, 0L, SEEK_SET)

actual override fun fileExists(path: String): Boolean {
TODO("Not yet implemented")
// Read file content
val buffer = ByteArray(size.toInt()).pin()
val rc = fread(buffer.addressOf(0), 1uL, size.toULong(), file)
if (rc == size.toULong()) buffer.get() else null
} finally {
fclose(file)
}
} catch (_: Exception) {
null
}
}

actual override fun osInfo(): OperatingSystem {
TODO("Not yet implemented")
actual override suspend fun writeFile(path: String, data: ByteArray) = withContext(SdkDispatchers.IO) {
val file = fopen(path, "wb") ?: throw IOException("Cannot open file for writing: $path")
try {
val wc = fwrite(data.refTo(0), 1uL, data.size.toULong(), file)
if (wc != data.size.toULong()) {
throw IOException("Failed to write all bytes to file $path, expected ${data.size.toLong()}, wrote $wc")
}
} finally {
fclose(file)
}
}

actual override val isJvm: Boolean
get() = TODO("Not yet implemented")
actual override val isAndroid: Boolean
get() = TODO("Not yet implemented")
actual override val isBrowser: Boolean
get() = TODO("Not yet implemented")
actual override val isNode: Boolean
get() = TODO("Not yet implemented")
actual override val isNative: Boolean
get() = TODO("Not yet implemented")

actual override fun getAllProperties(): Map<String, String> {
TODO("Not yet implemented")
}
actual override fun fileExists(path: String): Boolean = access(path, F_OK) == 0

actual override fun getProperty(key: String): String? {
TODO("Not yet implemented")
actual override fun osInfo(): OperatingSystem = memScoped {
val utsname = alloc<utsname>()
uname(utsname.ptr)

val sysName = utsname.sysname.toKString().lowercase()
val version = utsname.release.toKString()
val machine = utsname.machine.toKString().lowercase() // Helps differentiate Apple platforms

val family = when {
sysName.contains("darwin") -> {
when {
machine.startsWith("iphone") -> OsFamily.Ios
// TODO Validate that iPadOS/tvOS/watchOS resolves correctly on each of these devices
machine.startsWith("ipad") -> OsFamily.IpadOs
machine.startsWith("tv") -> OsFamily.TvOs
machine.startsWith("watch") -> OsFamily.WatchOs
else -> OsFamily.MacOs
}
}
sysName.contains("linux") -> OsFamily.Linux
sysName.contains("windows") -> OsFamily.Windows
else -> OsFamily.Unknown
}

return OperatingSystem(family, version)
}

actual override val isJvm: Boolean = false
actual override val isAndroid: Boolean = false
actual override val isBrowser: Boolean = false
actual override val isNode: Boolean = false
actual override val isNative: Boolean = true

// Kotlin/Native doesn't have system properties
actual override fun getAllProperties(): Map<String, String> = emptyMap()
actual override fun getProperty(key: String): String? = null
}
12 changes: 12 additions & 0 deletions runtime/runtime-core/native/src/nativeInterop/cinterop/environ.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef ENVIRON_H
#define ENVIRON_H

// External declaration to get environment variables
extern char **environ;

// Helper function to get the environ pointer
char** get_environ_ptr() {
return environ;
}

#endif
Loading