mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27: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 {
|
||||
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.maven.dependency.MavenDependency
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.log
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
|
@ -25,27 +24,6 @@ open class Project(
|
|||
@Directive open var packageName: String? = group) : IBuildConfig {
|
||||
|
||||
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>()
|
||||
|
||||
var isDirty = false
|
||||
|
@ -64,7 +42,8 @@ open class Project(
|
|||
|
||||
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()
|
||||
|
||||
|
|
|
@ -174,7 +174,11 @@ open class JvmCompilerPlugin @Inject constructor(
|
|||
} else {
|
||||
compilerContributors.forEach { contributor ->
|
||||
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,
|
||||
sourceSuffixes = compiler.sourceSuffixes)
|
||||
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>()
|
||||
|
||||
override fun projects() = allProjects
|
||||
|
@ -270,7 +267,7 @@ open class JvmCompilerPlugin @Inject constructor(
|
|||
})
|
||||
|
||||
// Transform them with the interceptors, if any
|
||||
val sourceDirectories = if (isTest) {
|
||||
val allSourceDirectories = if (isTest) {
|
||||
initialSourceDirectories
|
||||
} else {
|
||||
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
|
||||
val sourceFiles = files.findRecursively(projectDirectory, sourceDirectories,
|
||||
val sourceFiles = files.findRecursively(projectDirectory, allSourceDirectories,
|
||||
{ file -> sourceSuffixes.any { file.endsWith(it) }})
|
||||
.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: 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> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue