Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 1 | // Copyright 2019 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package java |
| 16 | |
Sam Delmerico | c06ea03 | 2022-01-28 21:11:03 +0000 | [diff] [blame] | 17 | import ( |
| 18 | "android/soong/android" |
Yu Liu | 39f5fb3 | 2025-01-13 23:52:19 +0000 | [diff] [blame] | 19 | "github.com/google/blueprint" |
Sam Delmerico | c06ea03 | 2022-01-28 21:11:03 +0000 | [diff] [blame] | 20 | ) |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 21 | |
Yu Liu | 39f5fb3 | 2025-01-13 23:52:19 +0000 | [diff] [blame] | 22 | type JavaPluginInfo struct { |
| 23 | ProcessorClass *string |
| 24 | GeneratesApi bool |
| 25 | } |
| 26 | |
| 27 | var JavaPluginInfoProvider = blueprint.NewProvider[JavaPluginInfo]() |
| 28 | |
| 29 | type KotlinPluginInfo struct { |
| 30 | } |
| 31 | |
| 32 | var KotlinPluginInfoProvider = blueprint.NewProvider[KotlinPluginInfo]() |
| 33 | |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 34 | func init() { |
Paul Duffin | c029c43 | 2021-03-22 15:00:28 +0000 | [diff] [blame] | 35 | registerJavaPluginBuildComponents(android.InitRegistrationContext) |
| 36 | } |
| 37 | |
| 38 | func registerJavaPluginBuildComponents(ctx android.RegistrationContext) { |
| 39 | ctx.RegisterModuleType("java_plugin", PluginFactory) |
Luca Stefani | 50098f7 | 2024-10-12 17:55:31 +0200 | [diff] [blame] | 40 | ctx.RegisterModuleType("kotlin_plugin", KotlinPluginFactory) |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 41 | } |
| 42 | |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 43 | func PluginFactory() android.Module { |
| 44 | module := &Plugin{} |
| 45 | |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 46 | module.addHostProperties() |
| 47 | module.AddProperties(&module.pluginProperties) |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 48 | |
| 49 | InitJavaModule(module, android.HostSupported) |
Sam Delmerico | c06ea03 | 2022-01-28 21:11:03 +0000 | [diff] [blame] | 50 | |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 51 | return module |
| 52 | } |
| 53 | |
Luca Stefani | 50098f7 | 2024-10-12 17:55:31 +0200 | [diff] [blame] | 54 | func KotlinPluginFactory() android.Module { |
| 55 | module := &KotlinPlugin{} |
| 56 | |
| 57 | module.addHostProperties() |
| 58 | |
| 59 | InitJavaModule(module, android.HostSupported) |
| 60 | |
| 61 | return module |
| 62 | } |
| 63 | |
Sam Delmerico | c06ea03 | 2022-01-28 21:11:03 +0000 | [diff] [blame] | 64 | // Plugin describes a java_plugin module, a host java library that will be used by javac as an annotation processor. |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 65 | type Plugin struct { |
| 66 | Library |
| 67 | |
| 68 | pluginProperties PluginProperties |
| 69 | } |
| 70 | |
| 71 | type PluginProperties struct { |
| 72 | // The optional name of the class that javac will use to run the annotation processor. |
| 73 | Processor_class *string |
| 74 | |
| 75 | // If true, assume the annotation processor will generate classes that are referenced from outside the module. |
| 76 | // This necessitates disabling the turbine optimization on modules that use this plugin, which will reduce |
| 77 | // parallelism and cause more recompilation for modules that depend on modules that use this plugin. |
| 78 | Generates_api *bool |
| 79 | } |
Luca Stefani | 50098f7 | 2024-10-12 17:55:31 +0200 | [diff] [blame] | 80 | |
Yu Liu | 39f5fb3 | 2025-01-13 23:52:19 +0000 | [diff] [blame] | 81 | func (p *Plugin) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 82 | p.Library.GenerateAndroidBuildActions(ctx) |
| 83 | |
| 84 | android.SetProvider(ctx, JavaPluginInfoProvider, JavaPluginInfo{ |
| 85 | ProcessorClass: p.pluginProperties.Processor_class, |
| 86 | GeneratesApi: Bool(p.pluginProperties.Generates_api), |
| 87 | }) |
| 88 | } |
| 89 | |
Luca Stefani | 50098f7 | 2024-10-12 17:55:31 +0200 | [diff] [blame] | 90 | // Plugin describes a kotlin_plugin module, a host java/kotlin library that will be used by kotlinc as a compiler plugin. |
| 91 | type KotlinPlugin struct { |
| 92 | Library |
| 93 | } |
Yu Liu | 39f5fb3 | 2025-01-13 23:52:19 +0000 | [diff] [blame] | 94 | |
| 95 | func (p *KotlinPlugin) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 96 | p.Library.GenerateAndroidBuildActions(ctx) |
| 97 | |
| 98 | android.SetProvider(ctx, KotlinPluginInfoProvider, KotlinPluginInfo{}) |
| 99 | } |