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

Compiler flag fixes.

This commit is contained in:
Cedric Beust 2016-02-09 01:38:17 +04:00
parent 6d61747fd5
commit 83282342ae
10 changed files with 26 additions and 19 deletions

View file

@ -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 // that directory will be added when trying to find recursively all the sources in it
generatedSourceDirectory = File(result.relativeTo(File(project.directory)).absolutePath) generatedSourceDirectory = File(result.relativeTo(File(project.directory)).absolutePath)
val outputGeneratedSourceDirectory = File(result, pkg.replace('.', File.separatorChar)) 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) KFiles.saveFile(outputDir, code)
log(2, "Generated ${outputDir.path}") log(2, "Generated ${outputDir.path}")
return result return result

View file

@ -8,6 +8,7 @@ import java.io.File
data class CompilerActionInfo(val directory: String?, data class CompilerActionInfo(val directory: String?,
val dependencies: List<IClasspathDependency>, val dependencies: List<IClasspathDependency>,
val sourceFiles: List<String>, val sourceFiles: List<String>,
val suffixesBeingCompiled: List<String>,
val outputDir: File, val outputDir: File,
val compilerArgs: List<String>) val compilerArgs: List<String>)

View file

@ -4,7 +4,8 @@ package com.beust.kobalt.api
* Plugins that add compiler flags. * Plugins that add compiler flags.
*/ */
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>,
suffixesBeingCompiled: List<String>): List<String>
val flagPriority: Int val flagPriority: Int
get() = DEFAULT_FLAG_PRIORITY get() = DEFAULT_FLAG_PRIORITY

View file

@ -2,7 +2,6 @@ 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.
@ -13,8 +12,9 @@ abstract class BaseJvmPlugin<T> : ConfigPlugin<T>(), ICompilerFlagContributor {
val FLAG_CONTRIBUTOR_PRIORITY = ICompilerFlagContributor.DEFAULT_FLAG_PRIORITY - 10 val FLAG_CONTRIBUTOR_PRIORITY = ICompilerFlagContributor.DEFAULT_FLAG_PRIORITY - 10
} }
protected fun maybeCompilerArgs(project: Project, args: List<String>) protected fun maybeCompilerArgs(sourceSuffixes: List<String>, suffixesBeingCompiled: List<String>,
= if (accept(project)) args else emptyList() args: List<String>)
= if (sourceSuffixes.any { suffixesBeingCompiled.contains(it) }) args else emptyList()
override val flagPriority = FLAG_CONTRIBUTOR_PRIORITY override val flagPriority = FLAG_CONTRIBUTOR_PRIORITY

View file

@ -34,7 +34,7 @@ class JvmCompiler @Inject constructor(val dependencyManager: DependencyManager)
val contributors = context.pluginInfo.compilerFlagContributors val contributors = context.pluginInfo.compilerFlagContributors
contributors.sortBy { it.flagPriority } contributors.sortBy { it.flagPriority }
context.pluginInfo.compilerFlagContributors.forEach { context.pluginInfo.compilerFlagContributors.forEach {
currentFlags.addAll(it.flagsFor(project, context, currentFlags)) currentFlags.addAll(it.flagsFor(project, context, currentFlags, info.suffixesBeingCompiled))
} }
currentFlags currentFlags
} else { } else {

View file

@ -293,7 +293,7 @@ open class JvmCompilerPlugin @Inject constructor(
// Finally, alter the info with the compiler interceptors before returning it // Finally, alter the info with the compiler interceptors before returning it
val initialActionInfo = CompilerActionInfo(projectDirectory.path, classpath, sourceFiles + extraSourceFiles, 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 -> val result = context.pluginInfo.compilerInterceptors.fold(initialActionInfo, { ai, interceptor ->
interceptor.intercept(project, context, ai) interceptor.intercept(project, context, ai)
}) })

View file

@ -31,7 +31,8 @@ public class AptPlugin @Inject constructor(val depFactory: DepFactory)
context.variant.toIntermediateDir()) context.variant.toIntermediateDir())
// ICompilerFlagContributor // 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>() val result = arrayListOf<String>()
configurationFor(project)?.let { config -> configurationFor(project)?.let { config ->
aptDependencies[project.name]?.let { aptDependencies -> aptDependencies[project.name]?.let { aptDependencies ->

View file

@ -39,12 +39,13 @@ class JavaPlugin @Inject constructor(val javaCompiler: JavaCompiler)
} }
// ICompilerFlagsContributor // ICompilerFlagsContributor
// ICompilerFlagsContributor override fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>,
override fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>) suffixesBeingCompiled: List<String>) =
= maybeCompilerArgs(project, configurationFor(project)?.compilerArgs ?: listOf<String>()) maybeCompilerArgs(sourceSuffixes, suffixesBeingCompiled,
configurationFor(project)?.compilerArgs ?: listOf<String>())
// ICompilerContributor // ICompilerContributor
override val sourceSuffixes = listOf(".java") override val sourceSuffixes = listOf("java")
override fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult { override fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult {
val result = val result =
@ -64,7 +65,7 @@ class JavaPlugin @Inject constructor(val javaCompiler: JavaCompiler)
// IBuildConfigContributor // IBuildConfigContributor
override fun affinity(project: Project) = if (project.projectExtra.suffixesFound.contains("java")) 1 else 0 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, override fun generateBuildConfig(project: Project, context: KobaltContext, packageName: String,
variant: Variant, buildConfigs: List<BuildConfig>): String { variant: Variant, buildConfigs: List<BuildConfig>): String {

View file

@ -129,7 +129,7 @@ class KotlinCompiler @Inject constructor(
// .map { FileDependency(it) } // .map { FileDependency(it) }
val dependencies = compileDependencies + otherClasspath.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) return jvmCompiler.doCompile(project, context, compilerAction, info)
} }
} }

View file

@ -37,9 +37,12 @@ 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>,
= maybeCompilerArgs(project, (configurationFor(project)?.compilerArgs ?: listOf<String>()) + suffixesBeingCompiled: List<String>) : List<String> {
listOf("-no-stdlib")) val result = maybeCompilerArgs(sourceSuffixes, suffixesBeingCompiled,
configurationFor(project)?.compilerArgs ?: listOf<String>())
return result
}
// 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]
@ -101,7 +104,7 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors)
// ICompilerContributor // ICompilerContributor
override val sourceSuffixes = listOf(".kt") override val sourceSuffixes = listOf("kt")
override fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult { override fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult {
val result = val result =
@ -129,7 +132,7 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors)
// IBuildConfigContributor // IBuildConfigContributor
override fun affinity(project: Project) = if (project.projectExtra.suffixesFound.contains("kotlin")) 2 else 0 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, override fun generateBuildConfig(project: Project, context: KobaltContext, packageName: String,
variant: Variant, buildConfigs: List<BuildConfig>): String { variant: Variant, buildConfigs: List<BuildConfig>): String {