Skip to content

Commit

Permalink
fix everything
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-arold committed Jan 25, 2024
1 parent 5e6b4a1 commit faf1e61
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 75 deletions.
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ repositories {
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22")
}
20 changes: 6 additions & 14 deletions buildSrc/src/main/kotlin/Libraries.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import Versions.korVersion
import Versions.kotlinxCollectionsImmutableVersion
import Versions.KOR_VERSION
import Versions.KOTLINX_COLLECTIONS_IMMUTABLE_VERSION

object Libraries {

const val kotlinReflect = "org.jetbrains.kotlin:kotlin-reflect"
const val kotlinxCollectionsImmutable =
"org.jetbrains.kotlinx:kotlinx-collections-immutable:$kotlinxCollectionsImmutableVersion"
const val KOTLIN_REFLECT = "org.jetbrains.kotlin:kotlin-reflect"
const val KOTLINX_COLLECTIONS_IMMUTABLE =
"org.jetbrains.kotlinx:kotlinx-collections-immutable:$KOTLINX_COLLECTIONS_IMMUTABLE_VERSION"


const val korio = "com.soywiz.korlibs.korio:korio:$korVersion"
const val klogger = "com.soywiz.korlibs.klogger:klogger:$korVersion"

// TEST
const val kotlinTestCommon = "org.jetbrains.kotlin:kotlin-test-common"
const val kotlinTestAnnotationsCommon = "org.jetbrains.kotlin:kotlin-test-annotations-common"
const val kotlinTestJunit = "org.jetbrains.kotlin:kotlin-test-junit"
const val kotlinTestJs = "org.jetbrains.kotlin:kotlin-test-js"
const val KORGE_FOUNDATION = "com.soywiz.korge:korge-foundation:$KOR_VERSION"
}
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
object Versions {

const val kotlinxCollectionsImmutableVersion = "0.3.5"
const val KOTLINX_COLLECTIONS_IMMUTABLE_VERSION = "0.3.5"

const val korVersion = "4.0.8"
const val KOR_VERSION = "5.3.0"
}
82 changes: 35 additions & 47 deletions cobalt.core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,70 +1,57 @@
import Libraries.klogger
import Libraries.korio
import Libraries.kotlinReflect
import Libraries.kotlinxCollectionsImmutable
import org.jetbrains.kotlin.konan.target.HostManager
import Libraries.KORGE_FOUNDATION
import Libraries.KOTLINX_COLLECTIONS_IMMUTABLE
import Libraries.KOTLIN_REFLECT

plugins {
kotlin("multiplatform")
id("maven-publish")
id("signing")
}

val javaVersion = JavaVersion.VERSION_11

java {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}

kotlin {

targets {
js(IR) {
compilations.all {
kotlinOptions {
sourceMap = true
moduleKind = "umd"
metaInfo = true
}
}
browser {
testTask {
useMocha()
}
jvm {
withJava()
compilations.all {
kotlinOptions {
apiVersion = "1.9"
languageVersion = "1.9"
jvmTarget = javaVersion.toString()

}
nodejs()
}
jvm {
// Intentionally left blank.
}
if (HostManager.hostIsMac) {
macosX64()
macosArm64()
iosX64()
iosArm64()
iosSimulatorArm64()
watchosArm32()
watchosArm64()
watchosX64()
watchosSimulatorArm64()
watchosDeviceArm64()
tvosArm64()
tvosX64()
tvosSimulatorArm64()
}
if (HostManager.hostIsMingw || HostManager.hostIsMac) {
mingwX64 {
binaries.findTest(DEBUG)!!.linkerOpts = mutableListOf("-Wl,--subsystem,windows")
}

js(IR) {
compilations.all {
kotlinOptions {
sourceMap = true
moduleKind = "umd"
metaInfo = true
}
}
if (HostManager.hostIsLinux || HostManager.hostIsMac) {
linuxX64()
linuxArm64()
browser {
testTask {
useMocha()
}
}
nodejs()
}

sourceSets {
val commonMain by getting {
dependencies {
api(kotlinReflect)
api(kotlinxCollectionsImmutable)
api(KOTLIN_REFLECT)
api(KOTLINX_COLLECTIONS_IMMUTABLE)

api(korio)
api(klogger)
api(KORGE_FOUNDATION)
}
}
val commonTest by getting {
Expand All @@ -73,6 +60,7 @@ kotlin {
}
}
}

}

publishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ interface UUID {
/**
* Creates a random [UUID].
*/
fun randomUUID(): UUID = DefaultUUID(korlibs.io.util.UUID.randomUUID())
fun randomUUID(): UUID = DefaultUUID.randomDefaultUUID()

/**
* Tries to create a [UUID] from a [String].
* This will throw an exception if the [UUID] cannot be created.
*/
fun fromString(str: String): UUID = DefaultUUID(korlibs.io.util.UUID(str))
fun fromString(str: String): UUID = DefaultUUID(str)
}
}



Original file line number Diff line number Diff line change
@@ -1,8 +1,48 @@
package org.hexworks.cobalt.core.internal

import org.hexworks.cobalt.core.api.UUID
import kotlin.random.Random


internal class DefaultUUID(private val backend: korlibs.io.util.UUID) : UUID {
override fun toString() = backend.toString()
}
@Suppress("EXPERIMENTAL_API_USAGE")
@OptIn(ExperimentalStdlibApi::class, ExperimentalUnsignedTypes::class)
class DefaultUUID(val data: UByteArray) : UUID {
override fun equals(other: Any?): Boolean = other is DefaultUUID && this.data.contentEquals(other.data)
override fun hashCode(): Int = this.data.contentHashCode()

companion object {
private const val HEX = "0123456789ABCDEF"

private val regex =
Regex("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", RegexOption.IGNORE_CASE)

val NIL: UUID get() = DefaultUUID("00000000-0000-0000-0000-000000000000")

private fun fix(data: UByteArray, version: Int, variant: Int): UByteArray {
data[6] = ((data[6].toInt() and 0b0000_1111) or (version shl 4)).toUByte()
data[8] = ((data[8].toInt() and 0x00_111111) or (variant shl 6)).toUByte()
return data
}

fun randomDefaultUUID(random: Random = Random): UUID = DefaultUUID(fix(UByteArray(16).apply {
random.nextBytes(this.asByteArray())
}, version = 4, variant = 1))

operator fun invoke(str: String): UUID {
if (regex.matchEntire(str) == null) throw IllegalArgumentException("Invalid DefaultUUID")
return DefaultUUID(str.replace("-", "").hexToUByteArray())
}
}

val version: Int get() = (data[6].toInt() ushr 4) and 0b1111
val variant: Int get() = (data[8].toInt() ushr 6) and 0b11

override fun toString(): String = buildString(36) {
for (n in 0 until 16) {
val c = data[n].toInt()
append(HEX[c shr 4])
append(HEX[c and 0xF])
if (n == 3 || n == 5 || n == 7 || n == 9) append('-')
}
}
}
5 changes: 0 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ version=2023.1.0-RELEASE
kotlin.mpp.stability.nowarn=true
kotlin.js.compiler=both

org.gradle.parallel=true
org.gradle.daemon=true
org.gradle.jvmargs=-Xmx3g
org.gradle.configureondemand=true

POM_PACKAGING=jar
POM_URL=https://github.com/Hexworks/cobalt
POM_SCM_URL=https://github.com/Hexworks/cobalt.git
Expand Down
4 changes: 3 additions & 1 deletion script/release
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
./gradlew publish --no-daemon --no-parallel
#!/usr/bin/env bash

./gradlew publish --no-parallel --no-daemon

0 comments on commit faf1e61

Please sign in to comment.