mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Fix multiple compilers.
This commit is contained in:
parent
187552500c
commit
030adfdd63
6 changed files with 62 additions and 41 deletions
|
@ -8,3 +8,10 @@ import java.io.File
|
||||||
interface ISourceDirectoryContributor {
|
interface ISourceDirectoryContributor {
|
||||||
fun sourceDirectoriesFor(project: Project, context: KobaltContext): List<File>
|
fun sourceDirectoriesFor(project: Project, context: KobaltContext): List<File>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun KobaltContext.sourceDirectories(project: Project) : List<File> {
|
||||||
|
val result = pluginInfo.sourceDirContributors.flatMap {
|
||||||
|
it.sourceDirectoriesFor(project, this)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import com.beust.kobalt.api.annotation.Directive
|
||||||
import com.beust.kobalt.internal.JvmCompilerPlugin
|
import com.beust.kobalt.internal.JvmCompilerPlugin
|
||||||
import com.beust.kobalt.maven.dependency.MavenDependency
|
import com.beust.kobalt.maven.dependency.MavenDependency
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
||||||
import com.beust.kobalt.misc.log
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
@ -25,27 +24,6 @@ open class Project(
|
||||||
@Directive open var packageName: String? = group) : IBuildConfig {
|
@Directive open var packageName: String? = group) : IBuildConfig {
|
||||||
|
|
||||||
class ProjectExtra(project: Project) {
|
class ProjectExtra(project: Project) {
|
||||||
val suffixesFound : Set<String> by lazy {
|
|
||||||
val sf = hashSetOf<String>()
|
|
||||||
Kobalt.context?.let {
|
|
||||||
project.sourceDirectories.forEach { source ->
|
|
||||||
val sourceDir = File(KFiles.joinDir(project.directory, source))
|
|
||||||
if (sourceDir.exists()) {
|
|
||||||
KFiles.findRecursively(sourceDir, { file ->
|
|
||||||
val ind = file.lastIndexOf(".")
|
|
||||||
if (ind >= 0) {
|
|
||||||
sf.add(file.substring(ind + 1))
|
|
||||||
}
|
|
||||||
false
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
log(2, "Skipping nonexistent directory $sourceDir")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sf
|
|
||||||
}
|
|
||||||
|
|
||||||
val dependsOn = arrayListOf<Project>()
|
val dependsOn = arrayListOf<Project>()
|
||||||
|
|
||||||
var isDirty = false
|
var isDirty = false
|
||||||
|
@ -64,7 +42,8 @@ open class Project(
|
||||||
|
|
||||||
val testConfigs = arrayListOf(TestConfig(this))
|
val testConfigs = arrayListOf(TestConfig(this))
|
||||||
|
|
||||||
override var buildConfig : BuildConfig? = BuildConfig()
|
// If one is specified by default, we only generate a BuildConfig, find a way to fix that
|
||||||
|
override var buildConfig : BuildConfig? = null // BuildConfig()
|
||||||
|
|
||||||
val projectProperties = ProjectProperties()
|
val projectProperties = ProjectProperties()
|
||||||
|
|
||||||
|
|
|
@ -174,7 +174,11 @@ open class JvmCompilerPlugin @Inject constructor(
|
||||||
} else {
|
} else {
|
||||||
compilerContributors.forEach { contributor ->
|
compilerContributors.forEach { contributor ->
|
||||||
contributor.compilersFor(project, context).forEach { compiler ->
|
contributor.compilersFor(project, context).forEach { compiler ->
|
||||||
if (containsSourceFiles(project, compiler)) {
|
val sourceFiles = KFiles.findSourceFiles(project,
|
||||||
|
context.sourceDirectories(project).map { it.path }, compiler.sourceSuffixes)
|
||||||
|
if (sourceFiles.size > 0) {
|
||||||
|
// TODO: createCompilerActionInfo recalculates the source files, only compute them
|
||||||
|
// once and pass them
|
||||||
val info = createCompilerActionInfo(project, context, isTest, sourceDirectories,
|
val info = createCompilerActionInfo(project, context, isTest, sourceDirectories,
|
||||||
sourceSuffixes = compiler.sourceSuffixes)
|
sourceSuffixes = compiler.sourceSuffixes)
|
||||||
val thisResult = compiler.compile(project, context, info)
|
val thisResult = compiler.compile(project, context, info)
|
||||||
|
@ -192,13 +196,6 @@ open class JvmCompilerPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun containsSourceFiles(project: Project, compiler: ICompiler): Boolean {
|
|
||||||
project.projectExtra.suffixesFound.forEach {
|
|
||||||
if (compiler.sourceSuffixes.contains(it)) return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
val allProjects = arrayListOf<ProjectDescription>()
|
val allProjects = arrayListOf<ProjectDescription>()
|
||||||
|
|
||||||
override fun projects() = allProjects
|
override fun projects() = allProjects
|
||||||
|
@ -270,7 +267,7 @@ open class JvmCompilerPlugin @Inject constructor(
|
||||||
})
|
})
|
||||||
|
|
||||||
// Transform them with the interceptors, if any
|
// Transform them with the interceptors, if any
|
||||||
val sourceDirectories = if (isTest) {
|
val allSourceDirectories = if (isTest) {
|
||||||
initialSourceDirectories
|
initialSourceDirectories
|
||||||
} else {
|
} else {
|
||||||
context.pluginInfo.sourceDirectoriesInterceptors.fold(initialSourceDirectories.toList(),
|
context.pluginInfo.sourceDirectoriesInterceptors.fold(initialSourceDirectories.toList(),
|
||||||
|
@ -280,7 +277,7 @@ open class JvmCompilerPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that we have all the source directories, find all the source files in them
|
// Now that we have all the source directories, find all the source files in them
|
||||||
val sourceFiles = files.findRecursively(projectDirectory, sourceDirectories,
|
val sourceFiles = files.findRecursively(projectDirectory, allSourceDirectories,
|
||||||
{ file -> sourceSuffixes.any { file.endsWith(it) }})
|
{ file -> sourceSuffixes.any { file.endsWith(it) }})
|
||||||
.map { File(projectDirectory, it).path }
|
.map { File(projectDirectory, it).path }
|
||||||
|
|
||||||
|
|
|
@ -284,6 +284,34 @@ class KFiles {
|
||||||
fun isExcluded(file: File, excludes: List<Glob>) = isExcluded(file.path, excludes)
|
fun isExcluded(file: File, excludes: List<Glob>) = isExcluded(file.path, excludes)
|
||||||
|
|
||||||
fun isExcluded(file: String, excludes: List<Glob>): Boolean = excludes.any { it.matches(file) }
|
fun isExcluded(file: String, excludes: List<Glob>): Boolean = excludes.any { it.matches(file) }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: cache these per project so we don't do it more than once.
|
||||||
|
*/
|
||||||
|
fun findSourceFiles(project: Project, sourceDirectories: Collection<String>,
|
||||||
|
suffixes: List<String>) : Set<String> {
|
||||||
|
val result = hashSetOf<String>()
|
||||||
|
Kobalt.context?.let {
|
||||||
|
sourceDirectories.forEach { source ->
|
||||||
|
val sourceDir = File(KFiles.joinDir(project.directory, source))
|
||||||
|
if (sourceDir.exists()) {
|
||||||
|
KFiles.findRecursively(sourceDir, { file ->
|
||||||
|
val ind = file.lastIndexOf(".")
|
||||||
|
if (ind >= 0) {
|
||||||
|
val suffix = file.substring(ind + 1)
|
||||||
|
if (suffixes.contains(suffix)) {
|
||||||
|
result.add(file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
log(2, "Skipping nonexistent directory $sourceDir")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun findRecursively(directory: File, function: Function1<String, Boolean>): List<String> {
|
fun findRecursively(directory: File, function: Function1<String, Boolean>): List<String> {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import com.beust.kobalt.api.*
|
||||||
import com.beust.kobalt.api.annotation.Directive
|
import com.beust.kobalt.api.annotation.Directive
|
||||||
import com.beust.kobalt.internal.BaseJvmPlugin
|
import com.beust.kobalt.internal.BaseJvmPlugin
|
||||||
import com.beust.kobalt.internal.JvmCompilerPlugin
|
import com.beust.kobalt.internal.JvmCompilerPlugin
|
||||||
|
import com.beust.kobalt.misc.KFiles
|
||||||
import com.beust.kobalt.misc.warn
|
import com.beust.kobalt.misc.warn
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -21,7 +22,14 @@ class JavaPlugin @Inject constructor(val javaCompiler: JavaCompiler)
|
||||||
|
|
||||||
override val name = PLUGIN_NAME
|
override val name = PLUGIN_NAME
|
||||||
|
|
||||||
override fun accept(project: Project) = project.projectExtra.suffixesFound.contains("java")
|
override fun accept(project: Project) = hasSourceFiles(project)
|
||||||
|
|
||||||
|
// IBuildConfigContributor
|
||||||
|
|
||||||
|
private fun hasSourceFiles(project: Project)
|
||||||
|
= KFiles.findSourceFiles(project, project.sourceDirectories, listOf("java")).size > 0
|
||||||
|
|
||||||
|
override fun affinity(project: Project) = if (hasSourceFiles(project)) 1 else 0
|
||||||
|
|
||||||
// IDocContributor
|
// IDocContributor
|
||||||
override fun affinity(project: Project, context: KobaltContext) =
|
override fun affinity(project: Project, context: KobaltContext) =
|
||||||
|
@ -66,9 +74,6 @@ class JavaPlugin @Inject constructor(val javaCompiler: JavaCompiler)
|
||||||
override fun testSourceDirectoriesFor(project: Project, context: KobaltContext)
|
override fun testSourceDirectoriesFor(project: Project, context: KobaltContext)
|
||||||
= project.sourceDirectoriesTest.map { File(it) }.toList()
|
= project.sourceDirectoriesTest.map { File(it) }.toList()
|
||||||
|
|
||||||
// IBuildConfigContributor
|
|
||||||
override fun affinity(project: Project) = if (project.projectExtra.suffixesFound.contains("java")) 1 else 0
|
|
||||||
|
|
||||||
override val buildConfigSuffix = compiler.sourceSuffixes[0]
|
override val buildConfigSuffix = compiler.sourceSuffixes[0]
|
||||||
|
|
||||||
override fun generateBuildConfig(project: Project, context: KobaltContext, packageName: String,
|
override fun generateBuildConfig(project: Project, context: KobaltContext, packageName: String,
|
||||||
|
|
|
@ -8,6 +8,7 @@ import com.beust.kobalt.internal.BaseJvmPlugin
|
||||||
import com.beust.kobalt.internal.JvmCompilerPlugin
|
import com.beust.kobalt.internal.JvmCompilerPlugin
|
||||||
import com.beust.kobalt.maven.dependency.FileDependency
|
import com.beust.kobalt.maven.dependency.FileDependency
|
||||||
import com.beust.kobalt.maven.dependency.MavenDependency
|
import com.beust.kobalt.maven.dependency.MavenDependency
|
||||||
|
import com.beust.kobalt.misc.KFiles
|
||||||
import com.beust.kobalt.misc.KobaltExecutors
|
import com.beust.kobalt.misc.KobaltExecutors
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
||||||
import com.beust.kobalt.misc.warn
|
import com.beust.kobalt.misc.warn
|
||||||
|
@ -26,7 +27,14 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors)
|
||||||
|
|
||||||
override val name = PLUGIN_NAME
|
override val name = PLUGIN_NAME
|
||||||
|
|
||||||
override fun accept(project: Project) = project.projectExtra.suffixesFound.contains("kt")
|
override fun accept(project: Project) = hasSourceFiles(project)
|
||||||
|
|
||||||
|
// IBuildConfigContributor
|
||||||
|
|
||||||
|
private fun hasSourceFiles(project: Project)
|
||||||
|
= KFiles.findSourceFiles(project, project.sourceDirectories, listOf("kt")).size > 0
|
||||||
|
|
||||||
|
override fun affinity(project: Project) = if (hasSourceFiles(project)) 1 else 0
|
||||||
|
|
||||||
// IDocContributor
|
// IDocContributor
|
||||||
override fun affinity(project: Project, context: KobaltContext) =
|
override fun affinity(project: Project, context: KobaltContext) =
|
||||||
|
@ -134,9 +142,6 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors)
|
||||||
log(2, "${project.name}: $s")
|
log(2, "${project.name}: $s")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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,
|
override fun generateBuildConfig(project: Project, context: KobaltContext, packageName: String,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue