mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -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
|
@Directive
|
||||||
fun kobaltOptions(vararg options: String) = Kobalt.addKobaltOptions(options)
|
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
|
// 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
|
// probably never need to do. Projects should use kotlinCompiler { compilerVersion } to configure the
|
||||||
// Kotin compiler for their source files.
|
// Kotin compiler for their source files.
|
||||||
|
@ -127,4 +131,3 @@ fun localMaven() : String {
|
||||||
}
|
}
|
||||||
return result.toURI().toString()
|
return result.toURI().toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,9 +120,13 @@ class Kobalt {
|
||||||
fun findPlugin(name: String) = Plugins.findPlugin(name)
|
fun findPlugin(name: String) = Plugins.findPlugin(name)
|
||||||
|
|
||||||
val optionsFromBuild = arrayListOf<String>()
|
val optionsFromBuild = arrayListOf<String>()
|
||||||
|
|
||||||
fun addKobaltOptions(options: Array<out String>) {
|
fun addKobaltOptions(options: Array<out String>) {
|
||||||
optionsFromBuild.addAll(options)
|
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
|
package com.beust.kobalt.internal.build
|
||||||
|
|
||||||
|
import com.beust.kobalt.api.Kobalt
|
||||||
import com.beust.kobalt.homeDir
|
import com.beust.kobalt.homeDir
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.file.*
|
import java.nio.file.*
|
||||||
|
@ -22,24 +23,25 @@ class BuildSources(val file: File) : IBuildSources {
|
||||||
override val root = file
|
override val root = file
|
||||||
|
|
||||||
override fun findSourceFiles() : List<File> {
|
override fun findSourceFiles() : List<File> {
|
||||||
return listOf(/* "kobalt/src/a.kt", */ "kobalt/src/Build.kt")
|
val result = arrayListOf("kobalt/src/Build.kt")
|
||||||
.map(::File)
|
if (Kobalt.buildSourceDirs.isNotEmpty()) result.addAll(findBuildFiles(Kobalt.buildSourceDirs))
|
||||||
// .map { BuildFile(Paths.get(it), it)}
|
|
||||||
|
return result.map(::File)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun exists() = findSourceFiles().isNotEmpty()
|
override fun exists() = findSourceFiles().isNotEmpty()
|
||||||
|
|
||||||
override fun toString() = "{BuildSources " + findSourceFiles()[0] + "...}"
|
override fun toString() = "{BuildSources " + findSourceFiles().joinToString(", ") + "}"
|
||||||
|
|
||||||
fun _findSourceFiles() : List<File> {
|
fun findBuildFiles(roots: List<String>) : List<String> {
|
||||||
val result = arrayListOf<File>()
|
val result = arrayListOf<String>()
|
||||||
Files.walkFileTree(Paths.get(file.absolutePath), object : SimpleFileVisitor<Path>() {
|
roots.forEach { file ->
|
||||||
|
Files.walkFileTree(Paths.get(file), object : SimpleFileVisitor<Path>() {
|
||||||
override fun preVisitDirectory(dir: Path?, attrs: BasicFileAttributes?): FileVisitResult {
|
override fun preVisitDirectory(dir: Path?, attrs: BasicFileAttributes?): FileVisitResult {
|
||||||
if (dir != null) {
|
if (dir != null) {
|
||||||
val path = dir.toFile()
|
val path = dir.toFile()
|
||||||
println(path.name)
|
|
||||||
if (path.name == "src" && path.parentFile.name == "kobalt") {
|
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)
|
result.addAll(sources)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,6 +49,7 @@ class BuildSources(val file: File) : IBuildSources {
|
||||||
return FileVisitResult.CONTINUE
|
return FileVisitResult.CONTINUE
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,8 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildSources") val buildS
|
||||||
val projects = arrayListOf<Project>()
|
val projects = arrayListOf<Project>()
|
||||||
run {
|
run {
|
||||||
// buildFiles.forEach { buildFile ->
|
// buildFiles.forEach { buildFile ->
|
||||||
|
|
||||||
|
// Parse kobalt/src/Build.kt
|
||||||
val parsedBuildFile = parseBuildFile(context, buildSources)
|
val parsedBuildFile = parseBuildFile(context, buildSources)
|
||||||
parsedBuildFiles.add(parsedBuildFile)
|
parsedBuildFiles.add(parsedBuildFile)
|
||||||
val pluginUrls = parsedBuildFile.pluginUrls
|
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,
|
// 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
|
// compile it, jar it in buildScript.jar and run it
|
||||||
val modifiedBuildFile = KFiles.createTempBuildFileInTempDirectory(deleteOnExit = true)
|
val modifiedBuildFile = KFiles.createTempBuildFileInTempDirectory(deleteOnExit = true)
|
||||||
KFiles.saveFile(modifiedBuildFile, parsedBuildFile.nonBuildScriptCode)
|
KFiles.saveFile(modifiedBuildFile, newParsedBuildFile.nonBuildScriptCode)
|
||||||
val taskResult = maybeCompileBuildFile(context, listOf(modifiedBuildFile.path),
|
val taskResult = maybeCompileBuildFile(context, listOf(modifiedBuildFile.path),
|
||||||
buildScriptJarFile, pluginUrls, context.internalContext.forceRecompile,
|
buildScriptJarFile, pluginUrls, context.internalContext.forceRecompile,
|
||||||
parsedBuildFile.containsProfiles)
|
newParsedBuildFile.containsProfiles)
|
||||||
if (taskResult.success) {
|
if (taskResult.success) {
|
||||||
projects.addAll(buildScriptUtil.runBuildScriptJarFile(buildScriptJarFile, pluginUrls, context))
|
projects.addAll(buildScriptUtil.runBuildScriptJarFile(buildScriptJarFile, pluginUrls, context))
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue