mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Fix the profile rebuild.
Fixes https://github.com/cbeust/kobalt/issues/278
This commit is contained in:
parent
e7407fdcf8
commit
bf1863db32
3 changed files with 56 additions and 2 deletions
|
@ -125,7 +125,9 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b
|
||||||
// in this case, we won't recompile the build file. A potential solution for this would be
|
// in this case, we won't recompile the build file. A potential solution for this would be
|
||||||
// to have a side file that describes which profiles the current buildScript.jar was
|
// to have a side file that describes which profiles the current buildScript.jar was
|
||||||
// compiled with.
|
// compiled with.
|
||||||
if (args.profiles.isNullOrEmpty() && buildScriptUtil.isUpToDate(buildFile, buildScriptJarFile)) {
|
val bs = BuildScriptJarFile(buildScriptJarFile)
|
||||||
|
val same = bs.sameProfiles(args.profiles)
|
||||||
|
if (same && buildScriptUtil.isUpToDate(buildFile, buildScriptJarFile)) {
|
||||||
log(2, " Build file is up to date")
|
log(2, " Build file is up to date")
|
||||||
return TaskResult()
|
return TaskResult()
|
||||||
} else {
|
} else {
|
||||||
|
@ -141,6 +143,12 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b
|
||||||
output = buildScriptJarFile
|
output = buildScriptJarFile
|
||||||
}.compile(context = context)
|
}.compile(context = context)
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Generate the file that contains the list of active profiles for this build file
|
||||||
|
//
|
||||||
|
BuildScriptJarFile(buildScriptJarFile).saveProfiles(args.profiles)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
39
src/main/kotlin/com/beust/kobalt/app/BuildScriptJarFile.kt
Normal file
39
src/main/kotlin/com/beust/kobalt/app/BuildScriptJarFile.kt
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
package com.beust.kobalt.app
|
||||||
|
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileWriter
|
||||||
|
|
||||||
|
class BuildScriptJarFile(val jarFile: File) {
|
||||||
|
val file = File(jarFile.parent, "profiles")
|
||||||
|
|
||||||
|
fun saveProfiles(profiles: String?) {
|
||||||
|
if (profiles != null) {
|
||||||
|
FileWriter(file).use {
|
||||||
|
it.write(profiles.split(",").sorted().joinToString(" "))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
file.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @{profiles} is a comma-separated list of profiles, or null
|
||||||
|
*/
|
||||||
|
fun sameProfiles(profiles: String?) : Boolean {
|
||||||
|
if (! file.exists()) {
|
||||||
|
return profiles == null
|
||||||
|
} else {
|
||||||
|
val fileContent = file.readText().trim()
|
||||||
|
if (fileContent.isEmpty() && profiles == null) {
|
||||||
|
return true
|
||||||
|
} else if (profiles != null) {
|
||||||
|
val savedProfiles = fileContent.split(" ").sorted()
|
||||||
|
val expected = profiles.split(",").sorted()
|
||||||
|
return savedProfiles == expected
|
||||||
|
} else {
|
||||||
|
return fileContent.isEmpty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val
|
||||||
val profileLines = arrayListOf<String>()
|
val profileLines = arrayListOf<String>()
|
||||||
val pluginUrls = arrayListOf<URL>()
|
val pluginUrls = arrayListOf<URL>()
|
||||||
val projects = arrayListOf<Project>()
|
val projects = arrayListOf<Project>()
|
||||||
|
val activeProfiles = arrayListOf<String>()
|
||||||
|
|
||||||
private val preBuildScript = arrayListOf(
|
private val preBuildScript = arrayListOf(
|
||||||
"import com.beust.kobalt.*",
|
"import com.beust.kobalt.*",
|
||||||
|
@ -85,6 +86,7 @@ class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val
|
||||||
if (line.matches(Regex("[ \\t]*val[ \\t]+$it[ \\t]+=.*"))) {
|
if (line.matches(Regex("[ \\t]*val[ \\t]+$it[ \\t]+=.*"))) {
|
||||||
with("val $it = true") {
|
with("val $it = true") {
|
||||||
log(2, "Activating profile $it in build file")
|
log(2, "Activating profile $it in build file")
|
||||||
|
activeProfiles.add(it)
|
||||||
profileLines.add(this)
|
profileLines.add(this)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
@ -138,13 +140,18 @@ class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val
|
||||||
|
|
||||||
private fun generateJarFile(context: KobaltContext, buildFile: BuildFile, buildScriptJarFile: File,
|
private fun generateJarFile(context: KobaltContext, buildFile: BuildFile, buildScriptJarFile: File,
|
||||||
originalFile: BuildFile) {
|
originalFile: BuildFile) {
|
||||||
|
|
||||||
|
//
|
||||||
|
// Compile the jar file
|
||||||
|
//
|
||||||
val kotlintDeps = dependencyManager.calculateDependencies(null, context)
|
val kotlintDeps = dependencyManager.calculateDependencies(null, context)
|
||||||
val deps: List<String> = kotlintDeps.map { it.jarFile.get().absolutePath }
|
val deps: List<String> = kotlintDeps.map { it.jarFile.get().absolutePath }
|
||||||
|
val outputJar = File(buildScriptJarFile.absolutePath)
|
||||||
val result = kotlinCompilePrivate {
|
val result = kotlinCompilePrivate {
|
||||||
classpath(files.kobaltJar)
|
classpath(files.kobaltJar)
|
||||||
classpath(deps)
|
classpath(deps)
|
||||||
sourceFiles(buildFile.path.toFile().absolutePath)
|
sourceFiles(buildFile.path.toFile().absolutePath)
|
||||||
output = File(buildScriptJarFile.absolutePath)
|
output = outputJar
|
||||||
}.compile(context = context)
|
}.compile(context = context)
|
||||||
if (! result.success) {
|
if (! result.success) {
|
||||||
throw KobaltException("Couldn't compile ${originalFile.realPath}:\n"
|
throw KobaltException("Couldn't compile ${originalFile.realPath}:\n"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue