Gradle importer: Join compiler plugin options as before the new MPP refactoring (KT-26424)
Android Studio has at least two kinds of importers: a generic one (that is run when the "Refresh Gradle model" tool button is pressed) and a fast one (is run on the build variant switch). Fast importer doesn't invoke our import handlers (AndroidExtensionsGradleImportHandler) that modify the compiler options stored in Kotlin facet in some way. Until the recent MPP importer refactoring both old and new options were saved in the Kotlin facet; now only the new options persist. This is certainly better, though it breaks the existing behavior (as the options added by import handlers become lost). The alternative approach is to re-design import handlers in a way they won't require the whole module/source set node (so we can invoke them every time), though it requires a way more changes.
This commit is contained in:
@@ -281,8 +281,12 @@ fun applyCompilerArgumentsToFacet(
|
||||
val defaultCompilerArguments = defaultArguments?.let { copyBean(it) } ?: compilerArguments::class.java.newInstance()
|
||||
defaultCompilerArguments.convertPathsToSystemIndependent()
|
||||
|
||||
val oldPluginOptions = compilerArguments.pluginOptions
|
||||
|
||||
val emptyArgs = compilerArguments::class.java.newInstance()
|
||||
copyBeanTo(arguments, compilerArguments) { property, value -> value != property.get(emptyArgs) }
|
||||
compilerArguments.pluginOptions = joinPluginOptions(oldPluginOptions, arguments.pluginOptions)
|
||||
|
||||
compilerArguments.convertPathsToSystemIndependent()
|
||||
|
||||
// Retain only fields exposed (and not explicitly ignored) in facet configuration editor.
|
||||
@@ -321,3 +325,15 @@ fun applyCompilerArgumentsToFacet(
|
||||
updateMergedArguments()
|
||||
}
|
||||
}
|
||||
|
||||
private fun joinPluginOptions(old: Array<String>?, new: Array<String>?): Array<String>? {
|
||||
if (old == null && new == null) {
|
||||
return old
|
||||
} else if (new == null) {
|
||||
return old
|
||||
} else if (old == null) {
|
||||
return new
|
||||
}
|
||||
|
||||
return (old + new).distinct().toTypedArray()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user