mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -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 ->
|
||||
context.variant = variant
|
||||
runTask(project)
|
||||
TaskResult()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ open class RunCommand(val command: String) {
|
|||
val hasErrorStream = process.errorStream.available() > 0
|
||||
var hasErrors = ! callSucceeded
|
||||
if (useErrorStreamAsErrorIndicator && ! hasErrors) {
|
||||
hasErrors = hasErrors && hasErrorStream
|
||||
hasErrors = hasErrors || hasErrorStream
|
||||
}
|
||||
|
||||
if (! hasErrors) {
|
||||
|
@ -64,7 +64,7 @@ open class RunCommand(val command: String) {
|
|||
else "<no output>"
|
||||
errorCallback(listOf("$command failed") + errorString)
|
||||
}
|
||||
return if (callSucceeded) 0 else 1
|
||||
return if (hasErrors) 1 else 0
|
||||
}
|
||||
|
||||
private fun fromStream(ins: InputStream) : List<String> {
|
||||
|
|
|
@ -119,22 +119,25 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler, v
|
|||
val resDir = "temporaryBogusResDir"
|
||||
explodeAarFiles(project, intermediates, File(resDir))
|
||||
val generated = AndroidFiles.generated(project)
|
||||
generateR(project, generated, aapt(project))
|
||||
return TaskResult()
|
||||
val success = generateR(project, generated, aapt(project))
|
||||
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,
|
||||
useErrorStream: Boolean = false,
|
||||
cwd: File = File(".")) : AndroidCommand(project, androidHome(project), aapt) {
|
||||
init {
|
||||
directory = cwd
|
||||
useErrorStreamAsErrorIndicator = useErrorStream
|
||||
useErrorStreamAsErrorIndicator = true
|
||||
}
|
||||
|
||||
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 androidJar = Paths.get(androidHome(project), "platforms", "android-$compileSdkVersion", "android.jar")
|
||||
val applicationId = configurationFor(project)?.applicationId!!
|
||||
|
@ -150,7 +153,7 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler, v
|
|||
val variantDir = context.variant.toIntermediateDir()
|
||||
|
||||
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",
|
||||
"--no-crunch",
|
||||
"-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 generatedBuildDir = compile(project, rOutputDirectory)
|
||||
project.compileDependencies.add(FileDependency(generatedBuildDir.path))
|
||||
return result == 0
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue