Skip to content

Commit

Permalink
prepare for configuration cache
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Aug 13, 2024
1 parent f1f3d30 commit 78bcfaf
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 83 deletions.
12 changes: 6 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[versions]
lib = "2.0.0-alpha-05"
android = "8.1.2"
lib = "2.0.0-alpha-06-SNAPSHOT"
android = "8.5.2"
auto-service = "1.1.1"
kotlin = "2.0.0"
kotlinpoet = "1.17.0"
publish = "0.28.0"
kotlin = "2.0.10"
kotlinpoet = "1.18.1"
publish = "0.29.0"
kase-change = "1.4.1"
osdetector = "1.7.3"
ksp = "2.0.0-1.0.21"
ksp = "2.0.10-1.0.24"

[libraries]
auto-service = { group = "com.google.auto.service", name = "auto-service", version.ref = "auto-service" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@ import java.util.*
open class SekretPlugin : Plugin<Project> {

override fun apply(project: Project) {
project.createSekretExtension()
val extension = project.createSekretExtension()

project.tasks.maybeCreate(GenerateSekretBuildScriptTask.NAME, GenerateSekretBuildScriptTask::class)
project.tasks.maybeCreate(GenerateSekretTask.NAME, GenerateSekretTask::class)
project.tasks.maybeCreate(CopySekretNativeBinaryTask.NAME, CopySekretNativeBinaryTask::class)
project.tasks.maybeCreate(GenerateSekretBuildScriptTask.NAME, GenerateSekretBuildScriptTask::class).also { task ->
task.apply(project, extension)
}
project.tasks.maybeCreate(GenerateSekretTask.NAME, GenerateSekretTask::class).also { task ->
task.apply(project, extension)
}
project.tasks.maybeCreate(CopySekretNativeBinaryTask.NAME, CopySekretNativeBinaryTask::class).also { task ->
task.apply(project, extension)
}
project.tasks.maybeCreate(CreateSekretNativeBinaryTask.NAME, CreateSekretNativeBinaryTask::class).also {
it.setupDependingTasks()
it.setupDependingTasks(project)
}
project.tasks.maybeCreate(CreateAndCopySekretNativeBinaryTask.NAME, CreateAndCopySekretNativeBinaryTask::class).also {
it.setupDependingTasks()
it.setupDependingTasks(project)
}

when (project.kotlinProjectExtension) {
Expand Down Expand Up @@ -55,7 +61,7 @@ open class SekretPlugin : Plugin<Project> {
}

companion object {
private const val VERSION = "2.0.0-alpha-05"
private const val VERSION = "2.0.0-alpha-06-SNAPSHOT"

internal fun getVersion(): String {
return runCatching {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,7 @@ import java.io.File
object BuildFileGenerator {

fun generate(
project: Project,
version: String = SekretPlugin.getVersion(),
overwrite: Boolean = false
) {
val defaultTargets = project.targetsMapped
val requiredTargets = Target.addDependingTargets(defaultTargets)

generate(
version = version,
targets = requiredTargets,
packageName = project.sekretExtension.properties.packageName.getOrElse(PropertiesExtension.sekretPackageName),
outputDir = ModuleGenerator.createBase(project),
overwrite = overwrite
)
}

fun generate(
version: String,
targets: Iterable<Target>,
packageName: String,
outputDir: File,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import java.io.File

object ModuleGenerator {

fun createBase(project: Project) = createBase(
project.findProject("sekret")?.projectDir ?: File(project.projectDir, "sekret")
)

fun createBase(directory: File): File {
directory.mkdirsSafely()
return directory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,63 @@
package dev.datlag.sekret.gradle.tasks

import dev.datlag.sekret.gradle.SekretPluginExtension
import dev.datlag.sekret.gradle.common.existsSafely
import dev.datlag.sekret.gradle.common.mkdirsSafely
import dev.datlag.sekret.gradle.common.sekretExtension
import dev.datlag.sekret.gradle.generator.ModuleGenerator
import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.FileSystemOperations
import org.gradle.api.file.ProjectLayout
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import java.io.File
import javax.inject.Inject

open class CopySekretNativeBinaryTask : DefaultTask() {
abstract class CopySekretNativeBinaryTask : DefaultTask() {

@get:Input
abstract val enabled: Property<Boolean>

@get:InputDirectory
abstract val buildDirectory: DirectoryProperty

@get:InputDirectory
abstract val sekretDirectory: DirectoryProperty

@get:OutputDirectory
abstract val androidDirectory: DirectoryProperty

@get:OutputDirectory
abstract val desktopComposeDirectory: DirectoryProperty

@get:Inject
abstract val projectLayout: ProjectLayout

@get:Inject
abstract val fileSystem: FileSystemOperations

private val sekretDir: File
get() = sekretDirectory.asFile.orNull
?: projectLayout.projectDirectory.dir("sekret").asFile

init {
group = "sekret"
}

private val sekretProject: Project?
get() = runCatching {
project.findProject("sekret")
}.getOrNull()

@TaskAction
fun copy() {
val config = project.sekretExtension.properties
val copyConfig = config.nativeCopy
if (!config.enabled.getOrElse(false)) {
if (!enabled.getOrElse(false)) {
return
}

val sekretDir = ModuleGenerator.createBase(project)
val sekretBuildDir = sekretProject?.layout?.buildDirectory?.orNull?.asFile ?: File(sekretDir, "build")
val sekretBuildDir = buildDirectory.asFile.orNull ?: File(ModuleGenerator.createBase(sekretDir), "build")

val androidJniFolder = copyConfig.androidJNIFolder.orNull?.asFile
val androidJniFolder = androidDirectory.asFile.orNull
if (androidJniFolder != null) {
val androidArm32 = getBinPath("androidNativeArm32", sekretBuildDir)
val androidArm64 = getBinPath("androidNativeArm64", sekretBuildDir)
Expand All @@ -55,7 +81,7 @@ open class CopySekretNativeBinaryTask : DefaultTask() {
}
}

val desktopComposeResourcesFolder = copyConfig.desktopComposeResourcesFolder.orNull?.asFile
val desktopComposeResourcesFolder = desktopComposeDirectory.asFile.orNull
if (desktopComposeResourcesFolder != null) {
val linuxArm64 = getBinPath("linuxArm64", sekretBuildDir)
val linuxX64 = getBinPath("linuxX64", sekretBuildDir)
Expand Down Expand Up @@ -100,15 +126,23 @@ open class CopySekretNativeBinaryTask : DefaultTask() {
}

private fun copyFileFromTo(from: String, dest: File) {
File(from).listFiles { _, name ->
!name.endsWith(".h") && !name.endsWith(".def")
}?.filterNotNull()?.forEach {
dest.mkdirsSafely()

it.copyRecursively(File(dest, it.name), true)
fileSystem.copy {
from(File(from))
into(dest.mkdirsSafely())
exclude("**/*.h", "**/*.def")
}
}

fun apply(project: Project, extension: SekretPluginExtension = project.sekretExtension) {
val sekretProject = project.findProject("sekret")

enabled.set(extension.properties.enabled)
buildDirectory.set(sekretProject?.layout?.buildDirectory?.orNull?.asFile)
sekretDirectory.set(sekretProject?.projectDir ?: File(project.projectDir, "sekret"))
androidDirectory.set(extension.properties.nativeCopy.androidJNIFolder)
desktopComposeDirectory.set(extension.properties.nativeCopy.desktopComposeResourcesFolder)
}

companion object {
internal const val NAME = "copySekretNativeBinary"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@ open class CreateAndCopySekretNativeBinaryTask : DefaultTask() {
group = "sekret"
}

private val sekretProject: Project?
get() = runCatching {
project.findProject("sekret")
}.getOrNull()

fun setupDependingTasks() {
val assembleTask = sekretProject?.findMatchingTask("assemble")
fun setupDependingTasks(project: Project) {
val assembleTask = project.findProject("sekret")?.findMatchingTask("assemble")
val generateTask = project.findMatchingTaskWithType<GenerateSekretTask>(GenerateSekretTask.NAME)
val copyTask = project.findMatchingTaskWithType<CopySekretNativeBinaryTask>(CopySekretNativeBinaryTask.NAME)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@ open class CreateSekretNativeBinaryTask : DefaultTask() {
group = "sekret"
}

private val sekretProject: Project?
get() = runCatching {
project.findProject("sekret")
}.getOrNull()

fun setupDependingTasks() {
val assembleTask = sekretProject?.findMatchingTask("assemble")
fun setupDependingTasks(project: Project) {
val assembleTask = project.findProject("sekret")?.findMatchingTask("assemble")
val generateTask = project.findMatchingTaskWithType<GenerateSekretTask>(GenerateSekretTask.NAME)

if (assembleTask != null && generateTask != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,70 @@
package dev.datlag.sekret.gradle.tasks

import dev.datlag.sekret.gradle.SekretPlugin
import dev.datlag.sekret.gradle.SekretPluginExtension
import dev.datlag.sekret.gradle.Target
import dev.datlag.sekret.gradle.common.sekretExtension
import dev.datlag.sekret.gradle.common.targetsMapped
import dev.datlag.sekret.gradle.extension.PropertiesExtension
import dev.datlag.sekret.gradle.generator.BuildFileGenerator
import dev.datlag.sekret.gradle.generator.ModuleGenerator
import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.ProjectLayout
import org.gradle.api.provider.Property
import org.gradle.api.provider.SetProperty
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import java.io.File
import javax.inject.Inject

open class GenerateSekretBuildScriptTask : DefaultTask() {
abstract class GenerateSekretBuildScriptTask : DefaultTask() {

@get:Input
abstract val enabled: Property<Boolean>

@get:Input
abstract val packageName: Property<String>

@get:Input
abstract val targets: SetProperty<Target>

@get:OutputDirectory
abstract val outputDirectory: DirectoryProperty

@get:Inject
abstract val projectLayout: ProjectLayout

private val outputDir: File
get() = outputDirectory.asFile.orNull
?: projectLayout.projectDirectory.dir("sekret").asFile

init {
group = "sekret"
}

@TaskAction
fun generate() {
if (!project.sekretExtension.properties.enabled.getOrElse(false)) {
if (!enabled.getOrElse(false)) {
return
}
BuildFileGenerator.generate(
project = project,
targets = Target.addDependingTargets(targets.get()),
packageName = packageName.getOrElse(PropertiesExtension.sekretPackageName),
outputDir = ModuleGenerator.createBase(outputDir),
overwrite = true
)
}

fun apply(project: Project, extension: SekretPluginExtension = project.sekretExtension) {
enabled.set(extension.properties.enabled)
packageName.set(extension.properties.packageName)
targets.set(project.targetsMapped)
outputDirectory.set(project.findProject("sekret")?.projectDir ?: File(project.projectDir, "sekret"))
}

companion object {
internal const val NAME = "generateSekretBuildScript"
}
Expand Down
Loading

0 comments on commit 78bcfaf

Please sign in to comment.