Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ setOf(
}
}

val kotlinComposeWasmStdlibFile: Configuration by configurations.creating {
val kotlinComposeWasmRuntime: Configuration by configurations.creating {
isTransitive = false
isCanBeResolved = true
isCanBeConsumed = false
Expand All @@ -48,10 +48,6 @@ val kotlinComposeWasmStdlibFile: Configuration by configurations.creating {
Category.CATEGORY_ATTRIBUTE,
objects.categoryComposeCache
)
attribute(
CacheAttribute.cacheAttribute,
CacheAttribute.WASM
)
}
}

Expand Down Expand Up @@ -93,7 +89,7 @@ dependencies {
}
testImplementation(libs.kotlinx.coroutines.test)

kotlinComposeWasmStdlibFile(project(":cache-maker"))
kotlinComposeWasmRuntime(project(":cache-maker"))
composeWasmStaticResources(project(":resource-server"))
}

Expand Down Expand Up @@ -121,26 +117,20 @@ fun Project.generateProperties(
)

val propertiesGenerator by tasks.registering(PropertiesGenerator::class) {
dependsOn(kotlinComposeWasmStdlibFile)
dependsOn(kotlinComposeWasmRuntime)
propertiesFile.fileValue(rootDir.resolve("src/main/resources/${propertyFile}"))
hashableFile.fileProvider(
provider {
kotlinComposeWasmStdlibFile.singleFile
}
hashableDir.from(
kotlinComposeWasmRuntime
)
generateProperties().forEach { (name, value) ->
propertiesMap.put(name, value)
}
}

val lambdaPropertiesGenerator by tasks.registering(PropertiesGenerator::class) {
dependsOn(kotlinComposeWasmStdlibFile)
dependsOn(kotlinComposeWasmRuntime)
propertiesFile.set(layout.buildDirectory.file("tmp/propertiesGenerator/${propertyFile}"))
hashableFile.fileProvider(
provider {
kotlinComposeWasmStdlibFile.singleFile
}
)
hashableDir.from(kotlinComposeWasmRuntime)

generateProperties(lambdaPrefix).forEach { (name, value) ->
propertiesMap.put(name, value)
Expand Down Expand Up @@ -186,7 +176,7 @@ val buildLambda by tasks.creating(Zip::class) {
from(libJVMFolder) { into(libJVM) }
from(compilerPluginsForJVMFolder) { into(compilerPluginsForJVM) }
from(libComposeWasmCompilerPluginsFolder) { into(libComposeWasmCompilerPlugins) }
dependsOn(kotlinComposeWasmStdlibFile)
dependsOn(kotlinComposeWasmRuntime)
into("lib") {
from(configurations.compileClasspath) { exclude("tomcat-embed-*") }
}
Expand Down
10 changes: 0 additions & 10 deletions buildSrc/src/main/kotlin/CacheAttribute.kt

This file was deleted.

34 changes: 18 additions & 16 deletions buildSrc/src/main/kotlin/PropertiesUpdater.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import org.gradle.api.DefaultTask
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.MapProperty
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.*
import java.io.File
import java.io.FileInputStream
import java.security.MessageDigest

abstract class PropertiesGenerator : DefaultTask() {

@get:InputFile
abstract val hashableFile: RegularFileProperty
@get:InputFiles
@get:Classpath
abstract val hashableDir: ConfigurableFileCollection

@get:Input
abstract val propertiesMap: MapProperty<String, String>
Expand All @@ -34,23 +33,26 @@ abstract class PropertiesGenerator : DefaultTask() {
}

file.appendText(
"\ndependencies.compose.wasm=${hashFileContent(hashableFile.get().asFile.absolutePath)}"
"\ndependencies.compose-wasm=${hashFileContent(hashableDir.singleFile)}"
)
}
}

fun hashFileContent(filePath: String, hashAlgorithm: String = "SHA-256"): String {
val file = File(filePath)
fun hashFileContent(files: File, hashAlgorithm: String = "SHA-256"): String {
val digest = MessageDigest.getInstance(hashAlgorithm)

// Read the file content in chunks and update the digest
FileInputStream(file).use { fileInputStream ->
val buffer = ByteArray(1024)
var bytesRead: Int
while (fileInputStream.read(buffer).also { bytesRead = it } != -1) {
digest.update(buffer, 0, bytesRead)
files.listFiles()
.filter { it.isFile }
.forEach { file ->
// Read the file content in chunks and update the digest
FileInputStream(file).use { fileInputStream ->
val buffer = ByteArray(1024)
var bytesRead: Int
while (fileInputStream.read(buffer).also { bytesRead = it } != -1) {
digest.update(buffer, 0, bytesRead)
}
}
}
}

// Convert the resulting byte array to a readable hex string
return digest.digest().joinToString("") { "%02x".format(it) }
Expand Down
Loading
Loading