Merge pull request #324 from InsanusMokrassar/0.20.9

0.20.9
This commit is contained in:
InsanusMokrassar 2023-10-24 16:25:05 +06:00 committed by GitHub
commit ebd7befe73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 398 additions and 30 deletions

View File

@ -1,5 +1,9 @@
# Changelog # Changelog
## 0.20.9
* Most of common modules now supports `linuxArm64` target
## 0.20.8 ## 0.20.8
**THIS VERSION CONTAINS UPDATES OF DEPENDENCIES UP TO RC VERSIONS. USE WITH CAUTION** **THIS VERSION CONTAINS UPDATES OF DEPENDENCIES UP TO RC VERSIONS. USE WITH CAUTION**

View File

@ -4,7 +4,7 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
kotlin { kotlin {
sourceSets { sourceSets {
@ -31,5 +31,10 @@ kotlin {
api libs.okio api libs.okio
} }
} }
linuxArm64Main {
dependencies {
api libs.okio
}
}
} }
} }

View File

@ -0,0 +1,36 @@
package dev.inmo.micro_utils.common
import okio.FileSystem
import okio.Path
import okio.use
actual typealias MPPFile = Path
/**
* @suppress
*/
actual val MPPFile.filename: FileName
get() = FileName(toString())
/**
* @suppress
*/
actual val MPPFile.filesize: Long
get() = FileSystem.SYSTEM.openReadOnly(this).use {
it.size()
}
/**
* @suppress
*/
actual val MPPFile.bytesAllocatorSync: ByteArrayAllocator
get() = {
FileSystem.SYSTEM.read(this) {
readByteArray()
}
}
/**
* @suppress
*/
actual val MPPFile.bytesAllocator: SuspendByteArrayAllocator
get() = {
bytesAllocatorSync()
}

View File

@ -0,0 +1,25 @@
package dev.inmo.micro_utils.common
import kotlinx.cinterop.*
import platform.posix.snprintf
import platform.posix.sprintf
@OptIn(ExperimentalForeignApi::class)
actual fun Float.fixed(signs: Int): Float {
return memScoped {
val buff = allocArray<ByteVar>(Float.SIZE_BYTES * 2)
sprintf(buff, "%.${signs}f", this@fixed)
buff.toKString().toFloat()
}
}
@OptIn(ExperimentalForeignApi::class)
actual fun Double.fixed(signs: Int): Double {
return memScoped {
val buff = allocArray<ByteVar>(Double.SIZE_BYTES * 2)
sprintf(buff, "%.${signs}f", this@fixed)
buff.toKString().toDouble()
}
}

View File

@ -4,7 +4,7 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
kotlin { kotlin {
sourceSets { sourceSets {

View File

@ -4,7 +4,7 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
kotlin { kotlin {
sourceSets { sourceSets {

View File

@ -26,10 +26,12 @@ allprojects {
// composePluginKotlinVersion = compilerPluginVersionFromLibrariesVersions // composePluginKotlinVersion = compilerPluginVersionFromLibrariesVersions
// } // }
mppProjectWithSerializationPresetPath = "${rootProject.projectDir.absolutePath}/mppProjectWithSerialization.gradle" mppProjectWithSerializationPresetPath = "${rootProject.projectDir.absolutePath}/mppJvmJsAndroidProject.gradle"
mppProjectWithSerializationAndComposePresetPath = "${rootProject.projectDir.absolutePath}/mppProjectWithSerializationAndCompose.gradle" mppProjectWithSerializationAndComposePresetPath = "${rootProject.projectDir.absolutePath}/mppProjectWithSerializationAndCompose.gradle"
mppJavaProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppJavaProject.gradle" mppJavaProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppJavaProject.gradle"
mppJvmJsLinuxMingwProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppJvmJsLinuxMingwProject.gradle" mppJvmJsLinuxMingwProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppJvmJsLinuxMingwProject.gradle"
mppJvmJsLinuxMingwLinuxArm64ProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppJvmJsLinuxMingwLinuxArm64Project.gradle"
mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppJvmJsAndroidLinuxMingwLinuxArm64Project.gradle"
mppAndroidProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppAndroidProject.gradle" mppAndroidProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppAndroidProject.gradle"
defaultAndroidSettingsPresetPath = "${rootProject.projectDir.absolutePath}/defaultAndroidSettings.gradle" defaultAndroidSettingsPresetPath = "${rootProject.projectDir.absolutePath}/defaultAndroidSettings.gradle"

View File

@ -4,7 +4,7 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
kotlin { kotlin {
sourceSets { sourceSets {

View File

@ -4,7 +4,7 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
kotlin { kotlin {
sourceSets { sourceSets {

View File

@ -15,5 +15,5 @@ crypto_js_version=4.1.1
# Project data # Project data
group=dev.inmo group=dev.inmo
version=0.20.8 version=0.20.9
android_code_version=214 android_code_version=215

View File

@ -4,7 +4,7 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
kotlin { kotlin {
sourceSets { sourceSets {
@ -30,5 +30,11 @@ kotlin {
api internalProject("micro_utils.mime_types") api internalProject("micro_utils.mime_types")
} }
} }
linuxArm64Main {
dependencies {
api internalProject("micro_utils.mime_types")
}
}
} }
} }

View File

@ -0,0 +1,40 @@
package dev.inmo.micro_utils.ktor.client
import dev.inmo.micro_utils.common.MPPFile
import dev.inmo.micro_utils.common.filename
import dev.inmo.micro_utils.ktor.common.TemporalFileId
import dev.inmo.micro_utils.mime_types.getMimeTypeOrAny
import io.ktor.client.HttpClient
import io.ktor.client.plugins.onUpload
import io.ktor.client.request.forms.formData
import io.ktor.client.request.forms.submitFormWithBinaryData
import io.ktor.client.statement.bodyAsText
import io.ktor.http.Headers
import io.ktor.http.HttpHeaders
internal val MPPFile.mimeType: String
get() = getMimeTypeOrAny(filename.extension).raw
actual suspend fun HttpClient.tempUpload(
fullTempUploadDraftPath: String,
file: MPPFile,
onUpload: OnUploadCallback
): TemporalFileId {
val inputProvider = file.inputProvider()
val fileId = submitFormWithBinaryData(
fullTempUploadDraftPath,
formData = formData {
append(
"data",
inputProvider,
Headers.build {
append(HttpHeaders.ContentType, file.mimeType)
append(HttpHeaders.ContentDisposition, "filename=\"${file.filename.string}\"")
}
)
}
) {
onUpload(onUpload)
}.bodyAsText()
return TemporalFileId(fileId)
}

View File

@ -0,0 +1,107 @@
package dev.inmo.micro_utils.ktor.client
import dev.inmo.micro_utils.common.MPPFile
import dev.inmo.micro_utils.common.Progress
import io.ktor.client.HttpClient
import io.ktor.client.engine.mergeHeaders
import io.ktor.client.plugins.onUpload
import io.ktor.client.request.HttpRequestBuilder
import io.ktor.client.request.forms.InputProvider
import io.ktor.client.request.forms.formData
import io.ktor.client.request.forms.submitForm
import io.ktor.client.request.forms.submitFormWithBinaryData
import io.ktor.client.request.headers
import io.ktor.client.statement.bodyAsText
import io.ktor.http.Headers
import io.ktor.http.HttpHeaders
import io.ktor.http.HttpStatusCode
import io.ktor.http.Parameters
import io.ktor.http.content.PartData
import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.InternalSerializationApi
import kotlinx.serialization.SerializationStrategy
import kotlinx.serialization.StringFormat
import kotlinx.serialization.encodeToString
import kotlinx.serialization.serializer
/**
* Will execute submitting of multipart data request
*
* @param data [Map] where keys will be used as names for multipart parts and values as values. If you will pass
* [dev.inmo.micro_utils.common.MPPFile] (File from JS or JVM platform). Also you may pass [UniUploadFileInfo] as value
* in case you wish to pass other source of multipart binary data than regular file
* @suppress
*/
@OptIn(InternalSerializationApi::class)
actual suspend fun <T> HttpClient.uniUpload(
url: String,
data: Map<String, Any>,
resultDeserializer: DeserializationStrategy<T>,
headers: Headers,
stringFormat: StringFormat,
onUpload: OnUploadCallback
): T? {
val withBinary = data.values.any { it is MPPFile || it is UniUploadFileInfo }
val formData = formData {
for (k in data.keys) {
val v = data[k] ?: continue
when (v) {
is MPPFile -> append(
k,
v.inputProvider(),
Headers.build {
append(HttpHeaders.ContentType, v.mimeType)
append(HttpHeaders.ContentDisposition, "filename=\"${v.name}\"")
}
)
is UniUploadFileInfo -> append(
k,
InputProvider(block = v.inputAllocator),
Headers.build {
append(HttpHeaders.ContentType, v.mimeType)
append(HttpHeaders.ContentDisposition, "filename=\"${v.fileName.name}\"")
}
)
else -> append(
k,
stringFormat.encodeToString(v::class.serializer() as SerializationStrategy<in Any>, v)
)
}
}
}
val requestBuilder: HttpRequestBuilder.() -> Unit = {
headers {
appendAll(headers)
}
onUpload { bytesSentTotal, contentLength ->
onUpload(bytesSentTotal, contentLength)
}
}
val response = if (withBinary) {
submitFormWithBinaryData(
url,
formData,
block = requestBuilder
)
} else {
submitForm(
url,
Parameters.build {
for (it in formData) {
val formItem = (it as PartData.FormItem)
append(it.name!!, it.value)
}
},
block = requestBuilder
)
}
return if (response.status == HttpStatusCode.OK) {
stringFormat.decodeFromString(resultDeserializer, response.bodyAsText())
} else {
null
}
}

View File

@ -4,7 +4,7 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
kotlin { kotlin {
sourceSets { sourceSets {

View File

@ -0,0 +1,11 @@
package dev.inmo.micro_utils.ktor.common
import dev.inmo.micro_utils.common.MPPFile
import dev.inmo.micro_utils.common.bytesAllocatorSync
import io.ktor.utils.io.core.ByteReadPacket
import io.ktor.utils.io.core.Input
actual fun MPPFile.input(): Input {
return ByteReadPacket(bytesAllocatorSync())
}

View File

@ -4,7 +4,7 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
kotlin { kotlin {
sourceSets { sourceSets {

View File

@ -4,4 +4,4 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"

View File

@ -4,4 +4,4 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"

View File

@ -0,0 +1,66 @@
project.version = "$version"
project.group = "$group"
apply from: "$publishGradlePath"
kotlin {
jvm {
compilations.main {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
js (IR) {
browser()
nodejs()
}
androidTarget {
publishAllLibraryVariants()
}
linuxX64()
mingwX64()
linuxArm64()
sourceSets {
commonMain {
dependencies {
implementation kotlin('stdlib')
api libs.kt.serialization
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
implementation libs.kt.coroutines.test
}
}
androidUnitTest {
dependencies {
implementation kotlin('test-junit')
implementation libs.android.test.junit
implementation libs.android.espresso
}
}
jvmTest {
dependencies {
implementation kotlin('test-junit')
}
}
jsTest {
dependencies {
implementation kotlin('test-js')
implementation kotlin('test-junit')
}
}
}
}
apply from: "$defaultAndroidSettingsPresetPath"
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

View File

@ -0,0 +1,54 @@
project.version = "$version"
project.group = "$group"
apply from: "$publishGradlePath"
kotlin {
jvm {
compilations.main {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
js (IR) {
browser()
nodejs()
}
linuxX64()
mingwX64()
linuxArm64()
sourceSets {
commonMain {
dependencies {
implementation kotlin('stdlib')
api libs.kt.serialization
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
implementation libs.kt.coroutines.test
}
}
jvmTest {
dependencies {
implementation kotlin('test-junit')
}
}
jsTest {
dependencies {
implementation kotlin('test-js')
implementation kotlin('test-junit')
}
}
}
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

View File

@ -22,6 +22,7 @@ kotlin {
commonMain { commonMain {
dependencies { dependencies {
implementation kotlin('stdlib') implementation kotlin('stdlib')
api libs.kt.serialization
} }
} }
commonTest { commonTest {
@ -43,6 +44,18 @@ kotlin {
implementation kotlin('test-junit') implementation kotlin('test-junit')
} }
} }
mingwX64Test {
dependencies {
implementation kotlin('test-junit')
}
}
linuxX64Test {
dependencies {
implementation kotlin('test-junit')
}
}
androidMain.dependsOn jvmMain
} }
} }

View File

@ -4,7 +4,7 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
kotlin { kotlin {
sourceSets { sourceSets {

View File

@ -4,7 +4,7 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
kotlin { kotlin {
sourceSets { sourceSets {

View File

@ -4,7 +4,7 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
kotlin { kotlin {
sourceSets { sourceSets {

View File

@ -4,7 +4,7 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
kotlin { kotlin {
sourceSets { sourceSets {

View File

@ -5,7 +5,7 @@ plugins {
id "com.google.devtools.ksp" id "com.google.devtools.ksp"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
kotlin { kotlin {

View File

@ -4,7 +4,7 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
kotlin { kotlin {
sourceSets { sourceSets {

View File

@ -4,7 +4,7 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
kotlin { kotlin {
sourceSets { sourceSets {

View File

@ -4,7 +4,7 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
kotlin { kotlin {
sourceSets { sourceSets {

View File

@ -4,7 +4,7 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
kotlin { kotlin {
sourceSets { sourceSets {

View File

@ -4,7 +4,7 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
kotlin { kotlin {
sourceSets { sourceSets {

View File

@ -4,7 +4,7 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
kotlin { kotlin {
sourceSets { sourceSets {

View File

@ -4,4 +4,4 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"

View File

@ -4,4 +4,4 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"

View File

@ -4,4 +4,4 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"

View File

@ -10,7 +10,6 @@ kotlin {
commonMain { commonMain {
dependencies { dependencies {
api libs.koin api libs.koin
api libs.kt.serialization
api libs.kslog api libs.kslog
api libs.kt.reflect api libs.kt.reflect
api project(":micro_utils.coroutines") api project(":micro_utils.coroutines")

View File

@ -5,7 +5,7 @@ plugins {
alias(libs.plugins.compose) alias(libs.plugins.compose)
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
kotlin { kotlin {
sourceSets { sourceSets {

View File

@ -4,4 +4,4 @@ plugins {
id "com.android.library" id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"