blob: 4b174b930af14f2fbb1992ef4333d8a787e06845 [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"
19 "android/soong/bazel"
Sam Delmericoc06ea032022-01-28 21:11:03 +000020)
Colin Crossbe9cdb82019-01-21 21:37:16 -080021
22func init() {
Paul Duffinc029c432021-03-22 15:00:28 +000023 registerJavaPluginBuildComponents(android.InitRegistrationContext)
24}
25
26func registerJavaPluginBuildComponents(ctx android.RegistrationContext) {
27 ctx.RegisterModuleType("java_plugin", PluginFactory)
Colin Crossbe9cdb82019-01-21 21:37:16 -080028}
29
Colin Crossbe9cdb82019-01-21 21:37:16 -080030func PluginFactory() android.Module {
31 module := &Plugin{}
32
Colin Crossce6734e2020-06-15 16:09:53 -070033 module.addHostProperties()
34 module.AddProperties(&module.pluginProperties)
Colin Crossbe9cdb82019-01-21 21:37:16 -080035
36 InitJavaModule(module, android.HostSupported)
Sam Delmericoc06ea032022-01-28 21:11:03 +000037
38 android.InitBazelModule(module)
39
Colin Crossbe9cdb82019-01-21 21:37:16 -080040 return module
41}
42
Sam Delmericoc06ea032022-01-28 21:11:03 +000043// 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 -080044type Plugin struct {
45 Library
46
47 pluginProperties PluginProperties
48}
49
50type PluginProperties struct {
51 // The optional name of the class that javac will use to run the annotation processor.
52 Processor_class *string
53
54 // If true, assume the annotation processor will generate classes that are referenced from outside the module.
55 // This necessitates disabling the turbine optimization on modules that use this plugin, which will reduce
56 // parallelism and cause more recompilation for modules that depend on modules that use this plugin.
57 Generates_api *bool
58}
Sam Delmericoc06ea032022-01-28 21:11:03 +000059
60type pluginAttributes struct {
61 *javaLibraryAttributes
62 Processor_class *string
63 Target_compatible_with bazel.LabelListAttribute
64}
65
66// ConvertWithBp2build is used to convert android_app to Bazel.
67func (p *Plugin) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
68 libAttrs := p.convertLibraryAttrsBp2Build(ctx)
69 attrs := &pluginAttributes{
70 libAttrs,
71 nil,
72 bazel.LabelListAttribute{},
73 }
74
75 if p.pluginProperties.Processor_class != nil {
76 attrs.Processor_class = p.pluginProperties.Processor_class
77 }
78
Sam Delmericoc06ea032022-01-28 21:11:03 +000079 props := bazel.BazelTargetModuleProperties{
80 Rule_class: "java_plugin",
81 }
82
Sam Delmerico75539d62022-01-31 14:37:29 +000083 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: p.Name()}, attrs)
Sam Delmericoc06ea032022-01-28 21:11:03 +000084}