mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 00:38:11 -07:00
GITHUB-57: Bubble up aapt errors correctly.
Fixes https://github.com/cbeust/kobalt/issues/57.
This commit is contained in:
parent
56ef7a8c1d
commit
0146bbd2fc
3 changed files with 12 additions and 9 deletions
|
@ -42,7 +42,6 @@ abstract public class BasePlugin : IPlugin {
|
||||||
task = { p: Project ->
|
task = { p: Project ->
|
||||||
context.variant = variant
|
context.variant = variant
|
||||||
runTask(project)
|
runTask(project)
|
||||||
TaskResult()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ open class RunCommand(val command: String) {
|
||||||
val hasErrorStream = process.errorStream.available() > 0
|
val hasErrorStream = process.errorStream.available() > 0
|
||||||
var hasErrors = ! callSucceeded
|
var hasErrors = ! callSucceeded
|
||||||
if (useErrorStreamAsErrorIndicator && ! hasErrors) {
|
if (useErrorStreamAsErrorIndicator && ! hasErrors) {
|
||||||
hasErrors = hasErrors && hasErrorStream
|
hasErrors = hasErrors || hasErrorStream
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! hasErrors) {
|
if (! hasErrors) {
|
||||||
|
@ -64,7 +64,7 @@ open class RunCommand(val command: String) {
|
||||||
else "<no output>"
|
else "<no output>"
|
||||||
errorCallback(listOf("$command failed") + errorString)
|
errorCallback(listOf("$command failed") + errorString)
|
||||||
}
|
}
|
||||||
return if (callSucceeded) 0 else 1
|
return if (hasErrors) 1 else 0
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fromStream(ins: InputStream) : List<String> {
|
private fun fromStream(ins: InputStream) : List<String> {
|
||||||
|
|
|
@ -119,22 +119,25 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler, v
|
||||||
val resDir = "temporaryBogusResDir"
|
val resDir = "temporaryBogusResDir"
|
||||||
explodeAarFiles(project, intermediates, File(resDir))
|
explodeAarFiles(project, intermediates, File(resDir))
|
||||||
val generated = AndroidFiles.generated(project)
|
val generated = AndroidFiles.generated(project)
|
||||||
generateR(project, generated, aapt(project))
|
val success = generateR(project, generated, aapt(project))
|
||||||
return TaskResult()
|
return TaskResult(success)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* aapt returns 0 even if it fails, so in order to detect whether it failed, we are checking
|
||||||
|
* if its error stream contains anything.
|
||||||
|
*/
|
||||||
inner class AaptCommand(project: Project, aapt: String, val aaptCommand: String,
|
inner class AaptCommand(project: Project, aapt: String, val aaptCommand: String,
|
||||||
useErrorStream: Boolean = false,
|
|
||||||
cwd: File = File(".")) : AndroidCommand(project, androidHome(project), aapt) {
|
cwd: File = File(".")) : AndroidCommand(project, androidHome(project), aapt) {
|
||||||
init {
|
init {
|
||||||
directory = cwd
|
directory = cwd
|
||||||
useErrorStreamAsErrorIndicator = useErrorStream
|
useErrorStreamAsErrorIndicator = true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun call(args: List<String>) = super.run(arrayListOf(aaptCommand) + args)
|
override fun call(args: List<String>) = super.run(arrayListOf(aaptCommand) + args)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateR(project: Project, generated: String, aapt: String) {
|
private fun generateR(project: Project, generated: String, aapt: String) : Boolean {
|
||||||
val compileSdkVersion = compileSdkVersion(project)
|
val compileSdkVersion = compileSdkVersion(project)
|
||||||
val androidJar = Paths.get(androidHome(project), "platforms", "android-$compileSdkVersion", "android.jar")
|
val androidJar = Paths.get(androidHome(project), "platforms", "android-$compileSdkVersion", "android.jar")
|
||||||
val applicationId = configurationFor(project)?.applicationId!!
|
val applicationId = configurationFor(project)?.applicationId!!
|
||||||
|
@ -150,7 +153,7 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler, v
|
||||||
val variantDir = context.variant.toIntermediateDir()
|
val variantDir = context.variant.toIntermediateDir()
|
||||||
|
|
||||||
val rDirectory = KFiles.joinAndMakeDir(generated, "source", "r", variantDir).toString()
|
val rDirectory = KFiles.joinAndMakeDir(generated, "source", "r", variantDir).toString()
|
||||||
AaptCommand(project, aapt, "package", false).call(listOf(
|
val result = AaptCommand(project, aapt, "package").call(listOf(
|
||||||
"-f",
|
"-f",
|
||||||
"--no-crunch",
|
"--no-crunch",
|
||||||
"-I", androidJar.toString(),
|
"-I", androidJar.toString(),
|
||||||
|
@ -172,6 +175,7 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler, v
|
||||||
val rOutputDirectory = KFiles.joinDir(rDirectory, applicationId.replace(".", File.separator))
|
val rOutputDirectory = KFiles.joinDir(rDirectory, applicationId.replace(".", File.separator))
|
||||||
val generatedBuildDir = compile(project, rOutputDirectory)
|
val generatedBuildDir = compile(project, rOutputDirectory)
|
||||||
project.compileDependencies.add(FileDependency(generatedBuildDir.path))
|
project.compileDependencies.add(FileDependency(generatedBuildDir.path))
|
||||||
|
return result == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue