split code into common and native components
parent
cddb2b00c9
commit
40c0d8dd5e
|
@ -1,4 +1,4 @@
|
||||||
name: Build release on tag
|
name: Build native release on tag
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
|
@ -7,7 +7,7 @@ jobs:
|
||||||
gradle:
|
gradle:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
os: [ubuntu-latest, macos-latest]
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
@ -20,4 +20,4 @@ jobs:
|
||||||
uses: gradle/gradle-build-action@v2
|
uses: gradle/gradle-build-action@v2
|
||||||
|
|
||||||
- name: Execute Gradle build
|
- name: Execute Gradle build
|
||||||
run: ./gradlew build
|
run: ./gradlew nativeBinaries
|
|
@ -81,7 +81,7 @@ Probably one could automate the setup using systemd and/or cronjobs, but so far
|
||||||
## Building
|
## Building
|
||||||
It should be enough to do a simple:
|
It should be enough to do a simple:
|
||||||
```bash
|
```bash
|
||||||
./gradlew build
|
./gradlew nativeBinaries
|
||||||
```
|
```
|
||||||
You can then find the executable in `build/bin/native/hcReleaseExecutable`.
|
You can then find the executable in `build/bin/native/hcReleaseExecutable`.
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,18 @@
|
||||||
|
val toolVersion: String by project
|
||||||
|
val koinVersion: String by project
|
||||||
|
val cliktVersion: String by project
|
||||||
|
val coroutinesVersion: String by project
|
||||||
|
val serializationVersion: String by project
|
||||||
|
val datetimeVersion: String by project
|
||||||
|
val ktorVersion: String by project
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("multiplatform") version "1.6.10"
|
kotlin("multiplatform") version "1.6.10"
|
||||||
kotlin("plugin.serialization") version "1.6.10"
|
kotlin("plugin.serialization") version "1.6.10"
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "fi.schro"
|
group = "fi.schro"
|
||||||
version = "1.0.0"
|
version = toolVersion
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
@ -12,12 +20,11 @@ repositories {
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
val hostOs = System.getProperty("os.name")
|
val hostOs = System.getProperty("os.name")
|
||||||
val isMingwX64 = hostOs.startsWith("Windows")
|
|
||||||
|
|
||||||
val nativeTarget = when {
|
val nativeTarget = when {
|
||||||
hostOs == "Mac OS X" -> macosX64("native")
|
hostOs == "Mac OS X" -> macosX64("native")
|
||||||
hostOs == "Linux" -> linuxX64("native")
|
hostOs == "Linux" -> linuxX64("native")
|
||||||
isMingwX64 -> mingwX64("native")
|
hostOs.startsWith("Windows") -> mingwX64("native")
|
||||||
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
|
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,17 +43,19 @@ kotlin {
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
val nativeMain by getting {
|
val commonMain by getting {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("io.insert-koin:koin-core:3.1.5")
|
implementation(kotlin("stdlib"))
|
||||||
implementation("com.github.ajalt.clikt:clikt:3.4.0")
|
implementation("io.insert-koin:koin-core:$koinVersion")
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")
|
implementation("com.github.ajalt.clikt:clikt:$cliktVersion")
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.2")
|
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
|
||||||
implementation("io.ktor:ktor-client-core:1.6.7")
|
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion")
|
||||||
implementation("io.ktor:ktor-client-cio:1.6.7")
|
implementation("org.jetbrains.kotlinx:kotlinx-datetime:$datetimeVersion")
|
||||||
implementation("io.ktor:ktor-client-serialization:1.6.7")
|
implementation("io.ktor:ktor-client-core:$ktorVersion")
|
||||||
|
implementation("io.ktor:ktor-client-cio:$ktorVersion")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val nativeTest by getting
|
val commonTest by getting
|
||||||
|
val nativeMain by getting
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,11 @@
|
||||||
kotlin.code.style=official
|
kotlin.code.style=official
|
||||||
kotlin.mpp.enableGranularSourceSetsMetadata=true
|
kotlin.mpp.enableGranularSourceSetsMetadata=true
|
||||||
kotlin.native.enableDependencyPropagation=false
|
kotlin.native.enableDependencyPropagation=false
|
||||||
kotlin.native.cacheKind.linuxX64=none
|
kotlin.native.cacheKind.linuxX64=none
|
||||||
|
toolVersion=1.0.0
|
||||||
|
koinVersion=3.1.5
|
||||||
|
cliktVersion=3.4.0
|
||||||
|
coroutinesVersion=1.5.2-native
|
||||||
|
serializationVersion=1.3.2
|
||||||
|
datetimeVersion=0.3.2
|
||||||
|
ktorVersion=1.6.7
|
|
@ -21,12 +21,13 @@ interface ConfigurationRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConfigurationRepositoryImpl(
|
class ConfigurationRepositoryImpl(
|
||||||
private val lightRepository: LightRepository
|
private val lightRepository: LightRepository,
|
||||||
|
private val fileUtil: FileUtil
|
||||||
): ConfigurationRepository {
|
): ConfigurationRepository {
|
||||||
private val timezone = TimeZone.currentSystemDefault()
|
private val timezone = TimeZone.currentSystemDefault()
|
||||||
|
|
||||||
override suspend fun applyConfiguration(configurationFilePath: String, lightAddress: String, port: Int?) {
|
override suspend fun applyConfiguration(configurationFilePath: String, lightAddress: String, port: Int?) {
|
||||||
val configString = FileUtil.readAllText(configurationFilePath)
|
val configString = fileUtil.readAllText(configurationFilePath)
|
||||||
val configuration = Json.decodeFromString<Configuration>(configString)
|
val configuration = Json.decodeFromString<Configuration>(configString)
|
||||||
val statusToApply = determineCurrentStatus(configuration)
|
val statusToApply = determineCurrentStatus(configuration)
|
||||||
|
|
|
@ -13,6 +13,7 @@ import fi.schro.data.ElgatoLightRepository.Companion.MIN_TEMPERATURE
|
||||||
import fi.schro.ui.LightPowerStatus
|
import fi.schro.ui.LightPowerStatus
|
||||||
import fi.schro.util.clamp
|
import fi.schro.util.clamp
|
||||||
import io.ktor.client.*
|
import io.ktor.client.*
|
||||||
|
import io.ktor.client.call.*
|
||||||
import io.ktor.client.request.*
|
import io.ktor.client.request.*
|
||||||
import io.ktor.client.statement.*
|
import io.ktor.client.statement.*
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
|
@ -0,0 +1,13 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 Florian Schrofner
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package fi.schro.util
|
||||||
|
|
||||||
|
interface FileUtil {
|
||||||
|
fun readAllText(filePath: String): String
|
||||||
|
}
|
|
@ -16,9 +16,10 @@ import fi.schro.ui.ApplyCommand
|
||||||
import fi.schro.ui.DaemonCommand
|
import fi.schro.ui.DaemonCommand
|
||||||
import fi.schro.ui.GetCommand
|
import fi.schro.ui.GetCommand
|
||||||
import fi.schro.ui.SetCommand
|
import fi.schro.ui.SetCommand
|
||||||
|
import fi.schro.util.FileUtil
|
||||||
|
import fi.schro.util.FileUtilImpl
|
||||||
import io.ktor.client.*
|
import io.ktor.client.*
|
||||||
import io.ktor.client.engine.cio.*
|
import io.ktor.client.engine.cio.*
|
||||||
import io.ktor.client.features.json.*
|
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
|
|
||||||
val commandModule = module {
|
val commandModule = module {
|
||||||
|
@ -30,18 +31,21 @@ val commandModule = module {
|
||||||
|
|
||||||
val dataModule = module {
|
val dataModule = module {
|
||||||
single<LightRepository> { ElgatoLightRepository() }
|
single<LightRepository> { ElgatoLightRepository() }
|
||||||
single<ConfigurationRepository> { ConfigurationRepositoryImpl(get()) }
|
single<ConfigurationRepository> { ConfigurationRepositoryImpl(get(), get()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
val networkModule = module {
|
val networkModule = module {
|
||||||
//HttpClient has to be recreated every time it is used
|
//HttpClient has to be recreated every time it is used
|
||||||
factory<HttpClient> { HttpClient(CIO){
|
factory<HttpClient> { HttpClient(CIO)}
|
||||||
install(JsonFeature)
|
}
|
||||||
}}
|
|
||||||
|
val fileModule = module {
|
||||||
|
single<FileUtil> { FileUtilImpl() }
|
||||||
}
|
}
|
||||||
|
|
||||||
val mainModule = listOf(
|
val mainModule = listOf(
|
||||||
commandModule,
|
commandModule,
|
||||||
dataModule,
|
dataModule,
|
||||||
networkModule
|
networkModule,
|
||||||
|
fileModule
|
||||||
)
|
)
|
|
@ -16,8 +16,8 @@ import platform.posix.fclose
|
||||||
import platform.posix.fgets
|
import platform.posix.fgets
|
||||||
import platform.posix.fopen
|
import platform.posix.fopen
|
||||||
|
|
||||||
object FileUtil {
|
class FileUtilImpl: FileUtil {
|
||||||
fun readAllText(filePath: String): String {
|
override fun readAllText(filePath: String): String {
|
||||||
val returnBuffer = StringBuilder()
|
val returnBuffer = StringBuilder()
|
||||||
val file = fopen(filePath, "r") ?:
|
val file = fopen(filePath, "r") ?:
|
||||||
throw IllegalArgumentException("Cannot open input file $filePath")
|
throw IllegalArgumentException("Cannot open input file $filePath")
|
||||||
|
|
Loading…
Reference in New Issue