mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
Multi build work.
This commit is contained in:
parent
33844b616e
commit
350b471460
4 changed files with 40 additions and 22 deletions
|
@ -31,6 +31,10 @@ class BuildScriptConfig {
|
|||
@Directive
|
||||
fun kobaltOptions(vararg options: String) = Kobalt.addKobaltOptions(options)
|
||||
|
||||
/** Where to find additional build files */
|
||||
@Directive
|
||||
fun buildSourceDirs(vararg dirs: String) = Kobalt.addBuildSourceDirs(dirs)
|
||||
|
||||
// The following settings modify the compiler used to compile the build file, which regular users should
|
||||
// probably never need to do. Projects should use kotlinCompiler { compilerVersion } to configure the
|
||||
// Kotin compiler for their source files.
|
||||
|
@ -127,4 +131,3 @@ fun localMaven() : String {
|
|||
}
|
||||
return result.toURI().toString()
|
||||
}
|
||||
|
||||
|
|
|
@ -120,9 +120,13 @@ class Kobalt {
|
|||
fun findPlugin(name: String) = Plugins.findPlugin(name)
|
||||
|
||||
val optionsFromBuild = arrayListOf<String>()
|
||||
|
||||
fun addKobaltOptions(options: Array<out String>) {
|
||||
optionsFromBuild.addAll(options)
|
||||
}
|
||||
|
||||
val buildSourceDirs = arrayListOf<String>()
|
||||
fun addBuildSourceDirs(dirs: Array<out String>) {
|
||||
buildSourceDirs.addAll(dirs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.beust.kobalt.internal.build
|
||||
|
||||
import com.beust.kobalt.api.Kobalt
|
||||
import com.beust.kobalt.homeDir
|
||||
import java.io.File
|
||||
import java.nio.file.*
|
||||
|
@ -22,24 +23,25 @@ class BuildSources(val file: File) : IBuildSources {
|
|||
override val root = file
|
||||
|
||||
override fun findSourceFiles() : List<File> {
|
||||
return listOf(/* "kobalt/src/a.kt", */ "kobalt/src/Build.kt")
|
||||
.map(::File)
|
||||
// .map { BuildFile(Paths.get(it), it)}
|
||||
val result = arrayListOf("kobalt/src/Build.kt")
|
||||
if (Kobalt.buildSourceDirs.isNotEmpty()) result.addAll(findBuildFiles(Kobalt.buildSourceDirs))
|
||||
|
||||
return result.map(::File)
|
||||
}
|
||||
|
||||
override fun exists() = findSourceFiles().isNotEmpty()
|
||||
|
||||
override fun toString() = "{BuildSources " + findSourceFiles()[0] + "...}"
|
||||
override fun toString() = "{BuildSources " + findSourceFiles().joinToString(", ") + "}"
|
||||
|
||||
fun _findSourceFiles() : List<File> {
|
||||
val result = arrayListOf<File>()
|
||||
Files.walkFileTree(Paths.get(file.absolutePath), object : SimpleFileVisitor<Path>() {
|
||||
fun findBuildFiles(roots: List<String>) : List<String> {
|
||||
val result = arrayListOf<String>()
|
||||
roots.forEach { file ->
|
||||
Files.walkFileTree(Paths.get(file), object : SimpleFileVisitor<Path>() {
|
||||
override fun preVisitDirectory(dir: Path?, attrs: BasicFileAttributes?): FileVisitResult {
|
||||
if (dir != null) {
|
||||
val path = dir.toFile()
|
||||
println(path.name)
|
||||
if (path.name == "src" && path.parentFile.name == "kobalt") {
|
||||
val sources = path.listFiles().filter { it.name.endsWith(".kt")}
|
||||
val sources = path.listFiles().filter { it.name.endsWith(".kt") }.map { it.path }
|
||||
result.addAll(sources)
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +49,7 @@ class BuildSources(val file: File) : IBuildSources {
|
|||
return FileVisitResult.CONTINUE
|
||||
}
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,6 +86,8 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildSources") val buildS
|
|||
val projects = arrayListOf<Project>()
|
||||
run {
|
||||
// buildFiles.forEach { buildFile ->
|
||||
|
||||
// Parse kobalt/src/Build.kt
|
||||
val parsedBuildFile = parseBuildFile(context, buildSources)
|
||||
parsedBuildFiles.add(parsedBuildFile)
|
||||
val pluginUrls = parsedBuildFile.pluginUrls
|
||||
|
@ -105,13 +107,19 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildSources") val buildS
|
|||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Now that Build.kt has been parsed, we might have additional build files (buildSources will
|
||||
// return additional build files) so we parse again.
|
||||
//
|
||||
val newParsedBuildFile = parseBuildFile(context, buildSources)
|
||||
|
||||
// Write the modified Build.kt (e.g. maybe profiles were applied) to a temporary file,
|
||||
// compile it, jar it in buildScript.jar and run it
|
||||
val modifiedBuildFile = KFiles.createTempBuildFileInTempDirectory(deleteOnExit = true)
|
||||
KFiles.saveFile(modifiedBuildFile, parsedBuildFile.nonBuildScriptCode)
|
||||
KFiles.saveFile(modifiedBuildFile, newParsedBuildFile.nonBuildScriptCode)
|
||||
val taskResult = maybeCompileBuildFile(context, listOf(modifiedBuildFile.path),
|
||||
buildScriptJarFile, pluginUrls, context.internalContext.forceRecompile,
|
||||
parsedBuildFile.containsProfiles)
|
||||
newParsedBuildFile.containsProfiles)
|
||||
if (taskResult.success) {
|
||||
projects.addAll(buildScriptUtil.runBuildScriptJarFile(buildScriptJarFile, pluginUrls, context))
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue