mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Fix variants.
This commit is contained in:
parent
221c7850e8
commit
e37930253d
4 changed files with 16 additions and 10 deletions
|
@ -37,7 +37,7 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sourceDirectories(project: Project, context: KobaltContext) : List<File> {
|
fun sourceDirectories(project: Project, context: KobaltContext) : List<File> {
|
||||||
val result = hashSetOf<File>()
|
val result = arrayListOf<File>()
|
||||||
val compilerContributors = ActorUtils.selectAffinityActors(project, context,
|
val compilerContributors = ActorUtils.selectAffinityActors(project, context,
|
||||||
context.pluginInfo.compilerContributors)
|
context.pluginInfo.compilerContributors)
|
||||||
compilerContributors.forEach {
|
compilerContributors.forEach {
|
||||||
|
@ -53,6 +53,7 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
||||||
* Might be used by plug-ins.
|
* Might be used by plug-ins.
|
||||||
*/
|
*/
|
||||||
fun resourceDirectories(project: Project) = sourceDirectories(project, "resources", variantFirst = false)
|
fun resourceDirectories(project: Project) = sourceDirectories(project, "resources", variantFirst = false)
|
||||||
|
.filter { it.path.contains("resources") || it.path.contains("res") }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* suffix is either "java" (to find source files) or "resources" (to find resources).
|
* suffix is either "java" (to find source files) or "resources" (to find resources).
|
||||||
|
@ -97,7 +98,8 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
||||||
val filteredResult = result.filter { File(project.directory, it.path).exists() }
|
val filteredResult = result.filter { File(project.directory, it.path).exists() }
|
||||||
val sortedResult = if (variantFirst) filteredResult
|
val sortedResult = if (variantFirst) filteredResult
|
||||||
else filteredResult.reversed().toList()
|
else filteredResult.reversed().toList()
|
||||||
return LinkedHashSet(sortedResult).toList()
|
val deduplicatedResult = LinkedHashSet(sortedResult).toList()
|
||||||
|
return deduplicatedResult
|
||||||
}
|
}
|
||||||
|
|
||||||
fun archiveName(project: Project, archiveName: String?, suffix: String) : String {
|
fun archiveName(project: Project, archiveName: String?, suffix: String) : String {
|
||||||
|
|
|
@ -46,12 +46,11 @@ class TaskContributor @Inject constructor(val incrementalManager: IncrementalMan
|
||||||
runTask: (Project) -> IncrementalTaskInfo) {
|
runTask: (Project) -> IncrementalTaskInfo) {
|
||||||
Variant.allVariants(project).forEach { variant ->
|
Variant.allVariants(project).forEach { variant ->
|
||||||
val variantTaskName = variant.toTask(taskName)
|
val variantTaskName = variant.toTask(taskName)
|
||||||
context.variant = variant
|
|
||||||
dynamicTasks.add(DynamicTask(plugin, variantTaskName, variantTaskName,
|
dynamicTasks.add(DynamicTask(plugin, variantTaskName, variantTaskName,
|
||||||
runBefore = runBefore.map { variant.toTask(it) },
|
runBefore = runBefore.map { variant.toTask(it) },
|
||||||
runAfter = runAfter.map { variant.toTask(it) },
|
runAfter = runAfter.map { variant.toTask(it) },
|
||||||
alwaysRunAfter = alwaysRunAfter.map { variant.toTask(it) },
|
alwaysRunAfter = alwaysRunAfter.map { variant.toTask(it) },
|
||||||
closure = incrementalManager.toIncrementalTaskClosure(taskName, runTask)))
|
closure = incrementalManager.toIncrementalTaskClosure(taskName, runTask, variant)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@ package com.beust.kobalt.internal
|
||||||
|
|
||||||
import com.beust.kobalt.IncrementalTaskInfo
|
import com.beust.kobalt.IncrementalTaskInfo
|
||||||
import com.beust.kobalt.TaskResult
|
import com.beust.kobalt.TaskResult
|
||||||
|
import com.beust.kobalt.Variant
|
||||||
|
import com.beust.kobalt.api.Kobalt
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
||||||
|
@ -74,9 +76,11 @@ class IncrementalManager(val fileName: String = IncrementalManager.BUILD_INFO_FI
|
||||||
* @return a closure that invokes that method and decide whether to run the task or not based
|
* @return a closure that invokes that method and decide whether to run the task or not based
|
||||||
* on the content of that IncrementalTaskInfo
|
* on the content of that IncrementalTaskInfo
|
||||||
*/
|
*/
|
||||||
fun toIncrementalTaskClosure(shortTaskName: String, method: (Project) -> IncrementalTaskInfo)
|
fun toIncrementalTaskClosure(shortTaskName: String, method: (Project) -> IncrementalTaskInfo,
|
||||||
|
variant: Variant = Variant())
|
||||||
: (Project) -> TaskResult {
|
: (Project) -> TaskResult {
|
||||||
return { project: Project ->
|
return { project: Project ->
|
||||||
|
Kobalt.context?.variant = variant
|
||||||
val iit = method(project)
|
val iit = method(project)
|
||||||
val taskName = project.name + ":" + shortTaskName
|
val taskName = project.name + ":" + shortTaskName
|
||||||
var upToDate = false
|
var upToDate = false
|
||||||
|
|
|
@ -113,13 +113,14 @@ open class JvmCompilerPlugin @Inject constructor(
|
||||||
throw IllegalArgumentException("Custom source sets not supported yet: $sourceSet")
|
throw IllegalArgumentException("Custom source sets not supported yet: $sourceSet")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sourceDirs.size > 0) {
|
val variantSourceDirs = context.variant.resourceDirectories(project)
|
||||||
|
if (variantSourceDirs.size > 0) {
|
||||||
lp(project, "Copying $sourceSet resources")
|
lp(project, "Copying $sourceSet resources")
|
||||||
val absOutputDir = File(KFiles.joinDir(project.directory, project.buildDirectory, outputDir))
|
val absOutputDir = File(KFiles.joinDir(project.directory, project.buildDirectory, outputDir))
|
||||||
sourceDirs.map { File(project.directory, it) }.filter {
|
variantSourceDirs.map { File(project.directory, it.path) }.filter {
|
||||||
it.exists()
|
it.exists()
|
||||||
}.forEach {
|
}.forEach {
|
||||||
log(2, "Copying from $sourceDirs to $absOutputDir")
|
log(2, "Copying from $it to $absOutputDir")
|
||||||
KFiles.copyRecursively(it, absOutputDir, deleteFirst = false)
|
KFiles.copyRecursively(it, absOutputDir, deleteFirst = false)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -241,7 +242,7 @@ open class JvmCompilerPlugin @Inject constructor(
|
||||||
* Runs all the contributors and interceptors relevant to that task.
|
* Runs all the contributors and interceptors relevant to that task.
|
||||||
*/
|
*/
|
||||||
protected fun createCompilerActionInfo(project: Project, context: KobaltContext, isTest: Boolean,
|
protected fun createCompilerActionInfo(project: Project, context: KobaltContext, isTest: Boolean,
|
||||||
sourceDirectories: Set<File>, sourceSuffixes: List<String>): CompilerActionInfo {
|
sourceDirectories: List<File>, sourceSuffixes: List<String>): CompilerActionInfo {
|
||||||
copyResources(project, JvmCompilerPlugin.SOURCE_SET_MAIN)
|
copyResources(project, JvmCompilerPlugin.SOURCE_SET_MAIN)
|
||||||
|
|
||||||
val fullClasspath = if (isTest) dependencyManager.testDependencies(project, context)
|
val fullClasspath = if (isTest) dependencyManager.testDependencies(project, context)
|
||||||
|
@ -312,7 +313,7 @@ open class JvmCompilerPlugin @Inject constructor(
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
val sourceDirectories = hashSetOf<File>()
|
val sourceDirectories = arrayListOf<File>()
|
||||||
|
|
||||||
// ISourceDirectoryContributor
|
// ISourceDirectoryContributor
|
||||||
override fun sourceDirectoriesFor(project: Project, context: KobaltContext)
|
override fun sourceDirectoriesFor(project: Project, context: KobaltContext)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue