mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Fix flag contributor bug.
This commit is contained in:
parent
403a3eccf4
commit
f412e6eca0
6 changed files with 31 additions and 7 deletions
|
@ -5,4 +5,10 @@ package com.beust.kobalt.api
|
||||||
*/
|
*/
|
||||||
interface ICompilerFlagContributor : IContributor {
|
interface ICompilerFlagContributor : IContributor {
|
||||||
fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>): List<String>
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,20 @@ package com.beust.kobalt.internal
|
||||||
|
|
||||||
import com.beust.kobalt.api.ConfigPlugin
|
import com.beust.kobalt.api.ConfigPlugin
|
||||||
import com.beust.kobalt.api.ICompilerFlagContributor
|
import com.beust.kobalt.api.ICompilerFlagContributor
|
||||||
|
import com.beust.kobalt.api.Project
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for JVM language plug-ins.
|
* 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
|
||||||
|
|
||||||
|
}
|
|
@ -29,10 +29,14 @@ class JvmCompiler @Inject constructor(val dependencyManager: DependencyManager)
|
||||||
.distinct()
|
.distinct()
|
||||||
|
|
||||||
// Plugins that add flags to the compiler
|
// Plugins that add flags to the compiler
|
||||||
val contributorFlags = if (project != null) {
|
val currentFlags = arrayListOf<String>().apply { addAll(info.compilerArgs) }
|
||||||
context.pluginInfo.compilerFlagContributors.flatMap {
|
val contributorFlags : List<String> = if (project != null) {
|
||||||
it.flagsFor(project, context, info.compilerArgs)
|
val contributors = context.pluginInfo.compilerFlagContributors
|
||||||
|
contributors.sortBy { it.flagPriority }
|
||||||
|
context.pluginInfo.compilerFlagContributors.forEach {
|
||||||
|
currentFlags.addAll(it.flagsFor(project, context, currentFlags))
|
||||||
}
|
}
|
||||||
|
currentFlags
|
||||||
} else {
|
} else {
|
||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,9 +38,10 @@ class JavaPlugin @Inject constructor(val javaCompiler: JavaCompiler)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ICompilerFlagsContributor
|
||||||
// ICompilerFlagsContributor
|
// ICompilerFlagsContributor
|
||||||
override fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>)
|
override fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>)
|
||||||
= configurationFor(project)?.compilerArgs ?: listOf<String>()
|
= maybeCompilerArgs(project, configurationFor(project)?.compilerArgs ?: listOf<String>())
|
||||||
|
|
||||||
// ICompilerContributor
|
// ICompilerContributor
|
||||||
override val sourceSuffixes = listOf("java")
|
override val sourceSuffixes = listOf("java")
|
||||||
|
|
|
@ -152,7 +152,7 @@ class KConfiguration @Inject constructor(val compiler: KotlinCompiler){
|
||||||
fun compilerArgs(s: List<String>) = args.addAll(s)
|
fun compilerArgs(s: List<String>) = args.addAll(s)
|
||||||
|
|
||||||
fun compile(project: Project? = null, context: KobaltContext? = null) : TaskResult {
|
fun compile(project: Project? = null, context: KobaltContext? = null) : TaskResult {
|
||||||
return compiler.compile(project, context, dependencies, classpath, source, output, args + "-no-stdlib")
|
return compiler.compile(project, context, dependencies, classpath, source, output, args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,8 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors)
|
||||||
|
|
||||||
// ICompilerFlagsContributor
|
// ICompilerFlagsContributor
|
||||||
override fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>)
|
override fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>)
|
||||||
= configurationFor(project)?.compilerArgs ?: listOf<String>()
|
= maybeCompilerArgs(project, (configurationFor(project)?.compilerArgs ?: listOf<String>()) +
|
||||||
|
listOf("-no-stdlib"))
|
||||||
|
|
||||||
// override fun generateDoc(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult {
|
// override fun generateDoc(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult {
|
||||||
// val configs = dokkaConfigurations[project.name]
|
// val configs = dokkaConfigurations[project.name]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue