mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Compiler flag fixes.
This commit is contained in:
parent
6d61747fd5
commit
83282342ae
10 changed files with 26 additions and 19 deletions
|
@ -149,7 +149,7 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
|||
// that directory will be added when trying to find recursively all the sources in it
|
||||
generatedSourceDirectory = File(result.relativeTo(File(project.directory)).absolutePath)
|
||||
val outputGeneratedSourceDirectory = File(result, pkg.replace('.', File.separatorChar))
|
||||
val outputDir = File(outputGeneratedSourceDirectory, "BuildConfig" + contributor.buildConfigSuffix)
|
||||
val outputDir = File(outputGeneratedSourceDirectory, "BuildConfig." + contributor.buildConfigSuffix)
|
||||
KFiles.saveFile(outputDir, code)
|
||||
log(2, "Generated ${outputDir.path}")
|
||||
return result
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.io.File
|
|||
data class CompilerActionInfo(val directory: String?,
|
||||
val dependencies: List<IClasspathDependency>,
|
||||
val sourceFiles: List<String>,
|
||||
val suffixesBeingCompiled: List<String>,
|
||||
val outputDir: File,
|
||||
val compilerArgs: List<String>)
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@ package com.beust.kobalt.api
|
|||
* Plugins that add compiler flags.
|
||||
*/
|
||||
interface ICompilerFlagContributor : IContributor {
|
||||
fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>): List<String>
|
||||
fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>,
|
||||
suffixesBeingCompiled: List<String>): List<String>
|
||||
val flagPriority: Int
|
||||
get() = DEFAULT_FLAG_PRIORITY
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ 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.
|
||||
|
@ -13,8 +12,9 @@ abstract class BaseJvmPlugin<T> : ConfigPlugin<T>(), ICompilerFlagContributor {
|
|||
val FLAG_CONTRIBUTOR_PRIORITY = ICompilerFlagContributor.DEFAULT_FLAG_PRIORITY - 10
|
||||
}
|
||||
|
||||
protected fun maybeCompilerArgs(project: Project, args: List<String>)
|
||||
= if (accept(project)) args else emptyList()
|
||||
protected fun maybeCompilerArgs(sourceSuffixes: List<String>, suffixesBeingCompiled: List<String>,
|
||||
args: List<String>)
|
||||
= if (sourceSuffixes.any { suffixesBeingCompiled.contains(it) }) args else emptyList()
|
||||
|
||||
override val flagPriority = FLAG_CONTRIBUTOR_PRIORITY
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class JvmCompiler @Inject constructor(val dependencyManager: DependencyManager)
|
|||
val contributors = context.pluginInfo.compilerFlagContributors
|
||||
contributors.sortBy { it.flagPriority }
|
||||
context.pluginInfo.compilerFlagContributors.forEach {
|
||||
currentFlags.addAll(it.flagsFor(project, context, currentFlags))
|
||||
currentFlags.addAll(it.flagsFor(project, context, currentFlags, info.suffixesBeingCompiled))
|
||||
}
|
||||
currentFlags
|
||||
} else {
|
||||
|
|
|
@ -293,7 +293,7 @@ open class JvmCompilerPlugin @Inject constructor(
|
|||
|
||||
// Finally, alter the info with the compiler interceptors before returning it
|
||||
val initialActionInfo = CompilerActionInfo(projectDirectory.path, classpath, sourceFiles + extraSourceFiles,
|
||||
buildDirectory, emptyList() /* the flags will be provided by flag contributors */)
|
||||
sourceSuffixes, buildDirectory, emptyList() /* the flags will be provided by flag contributors */)
|
||||
val result = context.pluginInfo.compilerInterceptors.fold(initialActionInfo, { ai, interceptor ->
|
||||
interceptor.intercept(project, context, ai)
|
||||
})
|
||||
|
|
|
@ -31,7 +31,8 @@ public class AptPlugin @Inject constructor(val depFactory: DepFactory)
|
|||
context.variant.toIntermediateDir())
|
||||
|
||||
// ICompilerFlagContributor
|
||||
override fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>) : List<String> {
|
||||
override fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>,
|
||||
suffixesBeingCompiled: List<String>) : List<String> {
|
||||
val result = arrayListOf<String>()
|
||||
configurationFor(project)?.let { config ->
|
||||
aptDependencies[project.name]?.let { aptDependencies ->
|
||||
|
|
|
@ -39,12 +39,13 @@ class JavaPlugin @Inject constructor(val javaCompiler: JavaCompiler)
|
|||
}
|
||||
|
||||
// ICompilerFlagsContributor
|
||||
// ICompilerFlagsContributor
|
||||
override fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>)
|
||||
= maybeCompilerArgs(project, configurationFor(project)?.compilerArgs ?: listOf<String>())
|
||||
override fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>,
|
||||
suffixesBeingCompiled: List<String>) =
|
||||
maybeCompilerArgs(sourceSuffixes, suffixesBeingCompiled,
|
||||
configurationFor(project)?.compilerArgs ?: listOf<String>())
|
||||
|
||||
// ICompilerContributor
|
||||
override val sourceSuffixes = listOf(".java")
|
||||
override val sourceSuffixes = listOf("java")
|
||||
|
||||
override fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult {
|
||||
val result =
|
||||
|
@ -64,7 +65,7 @@ class JavaPlugin @Inject constructor(val javaCompiler: JavaCompiler)
|
|||
// IBuildConfigContributor
|
||||
override fun affinity(project: Project) = if (project.projectExtra.suffixesFound.contains("java")) 1 else 0
|
||||
|
||||
override val buildConfigSuffix = ".java"
|
||||
override val buildConfigSuffix = sourceSuffixes[0]
|
||||
|
||||
override fun generateBuildConfig(project: Project, context: KobaltContext, packageName: String,
|
||||
variant: Variant, buildConfigs: List<BuildConfig>): String {
|
||||
|
|
|
@ -129,7 +129,7 @@ class KotlinCompiler @Inject constructor(
|
|||
// .map { FileDependency(it) }
|
||||
|
||||
val dependencies = compileDependencies + otherClasspath.map { FileDependency(it) }
|
||||
val info = CompilerActionInfo(project?.directory, dependencies, sourceFiles, outputDir, args)
|
||||
val info = CompilerActionInfo(project?.directory, dependencies, sourceFiles, listOf("kt"), outputDir, args)
|
||||
return jvmCompiler.doCompile(project, context, compilerAction, info)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,9 +37,12 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors)
|
|||
}
|
||||
|
||||
// ICompilerFlagsContributor
|
||||
override fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>)
|
||||
= maybeCompilerArgs(project, (configurationFor(project)?.compilerArgs ?: listOf<String>()) +
|
||||
listOf("-no-stdlib"))
|
||||
override fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>,
|
||||
suffixesBeingCompiled: List<String>) : List<String> {
|
||||
val result = maybeCompilerArgs(sourceSuffixes, suffixesBeingCompiled,
|
||||
configurationFor(project)?.compilerArgs ?: listOf<String>())
|
||||
return result
|
||||
}
|
||||
|
||||
// override fun generateDoc(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult {
|
||||
// val configs = dokkaConfigurations[project.name]
|
||||
|
@ -101,7 +104,7 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors)
|
|||
|
||||
// ICompilerContributor
|
||||
|
||||
override val sourceSuffixes = listOf(".kt")
|
||||
override val sourceSuffixes = listOf("kt")
|
||||
|
||||
override fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult {
|
||||
val result =
|
||||
|
@ -129,7 +132,7 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors)
|
|||
// IBuildConfigContributor
|
||||
override fun affinity(project: Project) = if (project.projectExtra.suffixesFound.contains("kotlin")) 2 else 0
|
||||
|
||||
override val buildConfigSuffix = ".kt"
|
||||
override val buildConfigSuffix = "kt"
|
||||
|
||||
override fun generateBuildConfig(project: Project, context: KobaltContext, packageName: String,
|
||||
variant: Variant, buildConfigs: List<BuildConfig>): String {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue