1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

Fix flag contributor bug.

This commit is contained in:
Cedric Beust 2016-02-07 07:18:10 +04:00
parent 403a3eccf4
commit f412e6eca0
6 changed files with 31 additions and 7 deletions

View file

@ -5,4 +5,10 @@ package com.beust.kobalt.api
*/
interface ICompilerFlagContributor : IContributor {
fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>): List<String>
val flagPriority: Int
get() = DEFAULT_FLAG_PRIORITY
companion object {
val DEFAULT_FLAG_PRIORITY = 20
}
}

View file

@ -2,8 +2,20 @@ package com.beust.kobalt.internal
import com.beust.kobalt.api.ConfigPlugin
import com.beust.kobalt.api.ICompilerFlagContributor
import com.beust.kobalt.api.Project
/**
* Base class for JVM language plug-ins.
*/
abstract class BaseJvmPlugin<T>: ConfigPlugin<T>(), ICompilerFlagContributor
abstract class BaseJvmPlugin<T> : ConfigPlugin<T>(), ICompilerFlagContributor {
companion object {
// Run before other flag contributors
val FLAG_CONTRIBUTOR_PRIORITY = ICompilerFlagContributor.DEFAULT_FLAG_PRIORITY - 10
}
protected fun maybeCompilerArgs(project: Project, args: List<String>)
= if (accept(project)) args else emptyList()
override val flagPriority = FLAG_CONTRIBUTOR_PRIORITY
}

View file

@ -29,10 +29,14 @@ class JvmCompiler @Inject constructor(val dependencyManager: DependencyManager)
.distinct()
// Plugins that add flags to the compiler
val contributorFlags = if (project != null) {
context.pluginInfo.compilerFlagContributors.flatMap {
it.flagsFor(project, context, info.compilerArgs)
val currentFlags = arrayListOf<String>().apply { addAll(info.compilerArgs) }
val contributorFlags : List<String> = if (project != null) {
val contributors = context.pluginInfo.compilerFlagContributors
contributors.sortBy { it.flagPriority }
context.pluginInfo.compilerFlagContributors.forEach {
currentFlags.addAll(it.flagsFor(project, context, currentFlags))
}
currentFlags
} else {
emptyList()
}