Add support for kotlin plugins

Use the already existing hooks used by the compose
compiler plugin to support kotlin plugins bundled
alongside the compiler such as kotlin-serialize-compiler

Test: m, sample app with kotlin-serialize-compiler
Change-Id: I4d5fa6cd42acfc90ef437222e9e07f61c259d565
This commit is contained in:
Luca Stefani
2024-10-12 17:55:31 +02:00
committed by SkyMinus
parent 3f71bc7084
commit 73a17f04e0
4 changed files with 93 additions and 5 deletions

View File

@@ -61,6 +61,7 @@ func init() {
AddNeverAllowRules(createJavaExcludeStaticLibsRule())
AddNeverAllowRules(createProhibitHeaderOnlyRule())
AddNeverAllowRules(createLimitNdkExportRule()...)
AddNeverAllowRules(createKotlinPluginRule()...)
}
// Add a NeverAllow rule to the set of rules to apply.
@@ -284,6 +285,22 @@ func createLimitNdkExportRule() []Rule {
}
}
func createKotlinPluginRule() []Rule {
kotlinPluginProjectsAllowedList := []string{
// TODO: Migrate compose plugin to the bundled compiler plugin
// Actual path prebuilts/sdk/current/androidx/m2repository/androidx/compose/compiler/compiler-hosted
"prebuilts/sdk/current/androidx",
"external/kotlinc",
}
return []Rule{
NeverAllow().
NotIn(kotlinPluginProjectsAllowedList...).
ModuleType("kotlin_plugin").
Because("kotlin_plugin can only be used in allowed projects"),
}
}
func neverallowMutator(ctx BottomUpMutatorContext) {
m, ok := ctx.Module().(Module)
if !ok {