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:
|
||||
push:
|
||||
tags:
|
||||
|
@ -7,7 +7,7 @@ jobs:
|
|||
gradle:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
os: [ubuntu-latest, macos-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
@ -20,4 +20,4 @@ jobs:
|
|||
uses: gradle/gradle-build-action@v2
|
||||
|
||||
- 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
|
||||
It should be enough to do a simple:
|
||||
```bash
|
||||
./gradlew build
|
||||
./gradlew nativeBinaries
|
||||
```
|
||||
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 {
|
||||
kotlin("multiplatform") version "1.6.10"
|
||||
kotlin("plugin.serialization") version "1.6.10"
|
||||
}
|
||||
|
||||
group = "fi.schro"
|
||||
version = "1.0.0"
|
||||
version = toolVersion
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
@ -12,12 +20,11 @@ repositories {
|
|||
|
||||
kotlin {
|
||||
val hostOs = System.getProperty("os.name")
|
||||
val isMingwX64 = hostOs.startsWith("Windows")
|
||||
|
||||
val nativeTarget = when {
|
||||
hostOs == "Mac OS X" -> macosX64("native")
|
||||
hostOs == "Linux" -> linuxX64("native")
|
||||
isMingwX64 -> mingwX64("native")
|
||||
hostOs.startsWith("Windows") -> mingwX64("native")
|
||||
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
|
||||
}
|
||||
|
||||
|
@ -36,17 +43,19 @@ kotlin {
|
|||
}
|
||||
|
||||
sourceSets {
|
||||
val nativeMain by getting {
|
||||
val commonMain by getting {
|
||||
dependencies {
|
||||
implementation("io.insert-koin:koin-core:3.1.5")
|
||||
implementation("com.github.ajalt.clikt:clikt:3.4.0")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.2")
|
||||
implementation("io.ktor:ktor-client-core:1.6.7")
|
||||
implementation("io.ktor:ktor-client-cio:1.6.7")
|
||||
implementation("io.ktor:ktor-client-serialization:1.6.7")
|
||||
implementation(kotlin("stdlib"))
|
||||
implementation("io.insert-koin:koin-core:$koinVersion")
|
||||
implementation("com.github.ajalt.clikt:clikt:$cliktVersion")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-datetime:$datetimeVersion")
|
||||
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
|
||||
}
|
||||
}
|
|
@ -2,3 +2,10 @@ kotlin.code.style=official
|
|||
kotlin.mpp.enableGranularSourceSetsMetadata=true
|
||||
kotlin.native.enableDependencyPropagation=false
|
||||
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(
|
||||
private val lightRepository: LightRepository
|
||||
private val lightRepository: LightRepository,
|
||||
private val fileUtil: FileUtil
|
||||
): ConfigurationRepository {
|
||||
private val timezone = TimeZone.currentSystemDefault()
|
||||
|
||||
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 statusToApply = determineCurrentStatus(configuration)
|
||||
|
|
@ -13,6 +13,7 @@ import fi.schro.data.ElgatoLightRepository.Companion.MIN_TEMPERATURE
|
|||
import fi.schro.ui.LightPowerStatus
|
||||
import fi.schro.util.clamp
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.call.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.statement.*
|
||||
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.GetCommand
|
||||
import fi.schro.ui.SetCommand
|
||||
import fi.schro.util.FileUtil
|
||||
import fi.schro.util.FileUtilImpl
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.engine.cio.*
|
||||
import io.ktor.client.features.json.*
|
||||
import org.koin.dsl.module
|
||||
|
||||
val commandModule = module {
|
||||
|
@ -30,18 +31,21 @@ val commandModule = module {
|
|||
|
||||
val dataModule = module {
|
||||
single<LightRepository> { ElgatoLightRepository() }
|
||||
single<ConfigurationRepository> { ConfigurationRepositoryImpl(get()) }
|
||||
single<ConfigurationRepository> { ConfigurationRepositoryImpl(get(), get()) }
|
||||
}
|
||||
|
||||
val networkModule = module {
|
||||
//HttpClient has to be recreated every time it is used
|
||||
factory<HttpClient> { HttpClient(CIO){
|
||||
install(JsonFeature)
|
||||
}}
|
||||
factory<HttpClient> { HttpClient(CIO)}
|
||||
}
|
||||
|
||||
val fileModule = module {
|
||||
single<FileUtil> { FileUtilImpl() }
|
||||
}
|
||||
|
||||
val mainModule = listOf(
|
||||
commandModule,
|
||||
dataModule,
|
||||
networkModule
|
||||
networkModule,
|
||||
fileModule
|
||||
)
|
|
@ -16,8 +16,8 @@ import platform.posix.fclose
|
|||
import platform.posix.fgets
|
||||
import platform.posix.fopen
|
||||
|
||||
object FileUtil {
|
||||
fun readAllText(filePath: String): String {
|
||||
class FileUtilImpl: FileUtil {
|
||||
override fun readAllText(filePath: String): String {
|
||||
val returnBuffer = StringBuilder()
|
||||
val file = fopen(filePath, "r") ?:
|
||||
throw IllegalArgumentException("Cannot open input file $filePath")
|
||||
|
|
Loading…
Reference in New Issue