blob: f1a5ec451a2da0fa5024c7f753fac73954073c02 [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"
20
21 "github.com/google/blueprint/proptools"
22)
Colin Crossbe9cdb82019-01-21 21:37:16 -080023
24func init() {
Paul Duffinc029c432021-03-22 15:00:28 +000025 registerJavaPluginBuildComponents(android.InitRegistrationContext)
26}
27
28func registerJavaPluginBuildComponents(ctx android.RegistrationContext) {
29 ctx.RegisterModuleType("java_plugin", PluginFactory)
Colin Crossbe9cdb82019-01-21 21:37:16 -080030}
31
Colin Crossbe9cdb82019-01-21 21:37:16 -080032func PluginFactory() android.Module {
33 module := &Plugin{}
34
Colin Crossce6734e2020-06-15 16:09:53 -070035 module.addHostProperties()
36 module.AddProperties(&module.pluginProperties)
Colin Crossbe9cdb82019-01-21 21:37:16 -080037
38 InitJavaModule(module, android.HostSupported)
Sam Delmericoc06ea032022-01-28 21:11:03 +000039
40 android.InitBazelModule(module)
41
Colin Crossbe9cdb82019-01-21 21:37:16 -080042 return module
43}
44
Sam Delmericoc06ea032022-01-28 21:11:03 +000045// 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 -080046type Plugin struct {
47 Library
48
49 pluginProperties PluginProperties
50}
51
52type PluginProperties struct {
53 // The optional name of the class that javac will use to run the annotation processor.
54 Processor_class *string
55
56 // If true, assume the annotation processor will generate classes that are referenced from outside the module.
57 // This necessitates disabling the turbine optimization on modules that use this plugin, which will reduce
58 // parallelism and cause more recompilation for modules that depend on modules that use this plugin.
59 Generates_api *bool
60}
Sam Delmericoc06ea032022-01-28 21:11:03 +000061
62type pluginAttributes struct {
63 *javaLibraryAttributes
64 Processor_class *string
65 Target_compatible_with bazel.LabelListAttribute
66}
67
68// ConvertWithBp2build is used to convert android_app to Bazel.
69func (p *Plugin) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
70 libAttrs := p.convertLibraryAttrsBp2Build(ctx)
71 attrs := &pluginAttributes{
72 libAttrs,
73 nil,
74 bazel.LabelListAttribute{},
75 }
76
77 if p.pluginProperties.Processor_class != nil {
78 attrs.Processor_class = p.pluginProperties.Processor_class
79 }
80
81 var enabledProperty bazel.BoolAttribute
82 enabledProperty.SetSelectValue(bazel.OsConfigurationAxis, android.Android.Name, proptools.BoolPtr(false))
83
84 props := bazel.BazelTargetModuleProperties{
85 Rule_class: "java_plugin",
86 }
87
88 ctx.CreateBazelTargetModuleWithRestrictions(props, android.CommonAttributes{Name: p.Name()}, attrs, enabledProperty)
89}