-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
172 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ko_fi: bppleman |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ name: Kommand Publish | |
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- "*" | ||
workflow_dispatch: | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ plugins { | |
} | ||
|
||
group = "com.kgit2" | ||
version = "2.0.1" | ||
version = "2.0.2" | ||
|
||
repositories { | ||
mavenCentral() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform | ||
|
||
val currentPlatform: Platform = when { | ||
DefaultNativePlatform.getCurrentOperatingSystem().isMacOsX && DefaultNativePlatform.getCurrentArchitecture().isAmd64 -> Platform.MACOS_X64 | ||
DefaultNativePlatform.getCurrentOperatingSystem().isMacOsX && DefaultNativePlatform.getCurrentArchitecture().isArm64 -> Platform.MACOS_ARM64 | ||
DefaultNativePlatform.getCurrentOperatingSystem().isLinux && DefaultNativePlatform.getCurrentArchitecture().isAmd64 -> Platform.LINUX_X64 | ||
DefaultNativePlatform.getCurrentOperatingSystem().isLinux && DefaultNativePlatform.getCurrentArchitecture().isArm64 -> Platform.LINUX_ARM64 | ||
DefaultNativePlatform.getCurrentOperatingSystem().isWindows && DefaultNativePlatform.getCurrentArchitecture().isAmd64 -> Platform.MINGW_X64 | ||
else -> throw GradleException("Host OS is not supported in Kotlin/Native.") | ||
} | ||
|
||
plugins { | ||
kotlin("multiplatform") | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
gradlePluginPortal() | ||
} | ||
|
||
kotlin { | ||
jvm { | ||
compilations.all { | ||
kotlinOptions.jvmTarget = "17" | ||
} | ||
withJava() | ||
testRuns["test"].executionTask.configure { | ||
useJUnitPlatform() | ||
} | ||
} | ||
|
||
val nativeTarget = when (currentPlatform) { | ||
Platform.MACOS_X64 -> macosX64() | ||
Platform.MACOS_ARM64 -> macosArm64() | ||
Platform.LINUX_X64 -> linuxX64() | ||
Platform.LINUX_ARM64 -> linuxArm64() | ||
Platform.MINGW_X64 -> mingwX64() | ||
} | ||
|
||
nativeTarget.apply { | ||
binaries { | ||
executable { | ||
entryPoint = "com.kgit2.kommand.main" | ||
} | ||
} | ||
} | ||
|
||
applyDefaultHierarchyTemplate() | ||
|
||
sourceSets { | ||
// add opt-in | ||
all { | ||
languageSettings.optIn("kotlinx.cinterop.UnsafeNumber") | ||
languageSettings.optIn("kotlinx.cinterop.ExperimentalForeignApi") | ||
languageSettings.optIn("kotlin.experimental.ExperimentalNativeApi") | ||
languageSettings.optIn("kotlin.native.runtime.NativeRuntimeApi") | ||
languageSettings.optIn("kotlin.ExperimentalStdlibApi") | ||
} | ||
|
||
commonMain { | ||
dependencies { | ||
implementation(rootProject) | ||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0-RC2") | ||
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.5.0") | ||
} | ||
} | ||
} | ||
} | ||
|
||
enum class Platform( | ||
val archName: String | ||
) { | ||
MACOS_X64("x86_64-apple-darwin"), | ||
MACOS_ARM64("aarch64-apple-darwin"), | ||
LINUX_X64("x86_64-unknown-linux-gnu"), | ||
LINUX_ARM64("aarch64-unknown-linux-gnu"), | ||
MINGW_X64("x86_64-pc-windows-gnu"), | ||
; | ||
} |
60 changes: 60 additions & 0 deletions
60
kommand-examples/timeout/src/appleMain/kotlin/com/kgit2/kommand/Main.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.kgit2.kommand | ||
|
||
import com.kgit2.kommand.process.Command | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.IO | ||
import kotlinx.coroutines.async | ||
import kotlinx.coroutines.runBlocking | ||
import kotlinx.coroutines.withTimeout | ||
import kotlinx.datetime.Clock | ||
|
||
fun main() = runBlocking(Dispatchers.Default) { | ||
// Sleep with regular | ||
val start = Clock.System.now() | ||
val status = Command("sleep").arg("5").status() | ||
println("status: $status elapsed: ${Clock.System.now() - start}") | ||
|
||
// Sleep with timeout detection and timeout determination | ||
val start2 = Clock.System.now() | ||
val child = Command("sleep").arg("5").spawn() | ||
val childJob = async(Dispatchers.IO) { | ||
runCatching { | ||
child.wait() | ||
}.onFailure { | ||
println("child result: $it") | ||
}.getOrNull() | ||
} | ||
runCatching { | ||
withTimeout(3000) { | ||
childJob.await() | ||
} | ||
}.onSuccess { | ||
println("status: $it elapsed: ${Clock.System.now() - start2}") | ||
}.onFailure { | ||
child.kill() | ||
println("status: $it elapsed: ${Clock.System.now() - start2}") | ||
} | ||
|
||
// Sleep with timeout detection and determination that it will not timeout | ||
val start3 = Clock.System.now() | ||
val child2 = Command("sleep").arg("2").spawn() | ||
val childJob2 = async(Dispatchers.IO) { | ||
runCatching { | ||
child2.wait() | ||
}.onFailure { | ||
println("child result: $it") | ||
}.getOrNull() | ||
} | ||
runCatching { | ||
withTimeout(3000) { | ||
childJob2.await() | ||
} | ||
}.onSuccess { | ||
println("status: $it elapsed: ${Clock.System.now() - start3}") | ||
}.onFailure { | ||
child2.kill() | ||
println("status: $it elapsed: ${Clock.System.now() - start3}") | ||
} | ||
|
||
Unit | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters