blob: 3534c7b132823f87fa4823e44b3b820f5e5da649 [file] [log] [blame]
Colin Crossbe9cdb82019-01-21 21:37:16 -08001// 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
15package java
16
Sam Delmericoc06ea032022-01-28 21:11:03 +000017import (
18 "android/soong/android"
Yu Liu39f5fb32025-01-13 23:52:19 +000019 "github.com/google/blueprint"
Sam Delmericoc06ea032022-01-28 21:11:03 +000020)
Colin Crossbe9cdb82019-01-21 21:37:16 -080021
Yu Liu39f5fb32025-01-13 23:52:19 +000022type JavaPluginInfo struct {
23 ProcessorClass *string
24 GeneratesApi bool
25}
26
27var JavaPluginInfoProvider = blueprint.NewProvider[JavaPluginInfo]()
28
29type KotlinPluginInfo struct {
30}
31
32var KotlinPluginInfoProvider = blueprint.NewProvider[KotlinPluginInfo]()
33
Colin Crossbe9cdb82019-01-21 21:37:16 -080034func init() {
Paul Duffinc029c432021-03-22 15:00:28 +000035 registerJavaPluginBuildComponents(android.InitRegistrationContext)
36}
37
38func registerJavaPluginBuildComponents(ctx android.RegistrationContext) {
39 ctx.RegisterModuleType("java_plugin", PluginFactory)
Luca Stefani50098f72024-10-12 17:55:31 +020040 ctx.RegisterModuleType("kotlin_plugin", KotlinPluginFactory)
Colin Crossbe9cdb82019-01-21 21:37:16 -080041}
42
Colin Crossbe9cdb82019-01-21 21:37:16 -080043func PluginFactory() android.Module {
44 module := &Plugin{}
45
Colin Crossce6734e2020-06-15 16:09:53 -070046 module.addHostProperties()
47 module.AddProperties(&module.pluginProperties)
Colin Crossbe9cdb82019-01-21 21:37:16 -080048
49 InitJavaModule(module, android.HostSupported)
Sam Delmericoc06ea032022-01-28 21:11:03 +000050
Colin Crossbe9cdb82019-01-21 21:37:16 -080051 return module
52}
53
Luca Stefani50098f72024-10-12 17:55:31 +020054func KotlinPluginFactory() android.Module {
55 module := &KotlinPlugin{}
56
57 module.addHostProperties()
58
59 InitJavaModule(module, android.HostSupported)
60
61 return module
62}
63
Sam Delmericoc06ea032022-01-28 21:11:03 +000064// Plugin describes a java_plugin module, a host java library that will be used by javac as an annotation processor.
Colin Crossbe9cdb82019-01-21 21:37:16 -080065type Plugin struct {
66 Library
67
68 pluginProperties PluginProperties
69}
70
71type 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 Stefani50098f72024-10-12 17:55:31 +020080
Yu Liu39f5fb32025-01-13 23:52:19 +000081func (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 Stefani50098f72024-10-12 17:55:31 +020090// Plugin describes a kotlin_plugin module, a host java/kotlin library that will be used by kotlinc as a compiler plugin.
91type KotlinPlugin struct {
92 Library
93}
Yu Liu39f5fb32025-01-13 23:52:19 +000094
95func (p *KotlinPlugin) GenerateAndroidBuildActions(ctx android.ModuleContext) {
96 p.Library.GenerateAndroidBuildActions(ctx)
97
98 android.SetProvider(ctx, KotlinPluginInfoProvider, KotlinPluginInfo{})
99}