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" |
| 19 | "android/soong/bazel" |
| 20 | |
| 21 | "github.com/google/blueprint/proptools" |
| 22 | ) |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 23 | |
| 24 | func init() { |
Paul Duffin | c029c43 | 2021-03-22 15:00:28 +0000 | [diff] [blame] | 25 | registerJavaPluginBuildComponents(android.InitRegistrationContext) |
| 26 | } |
| 27 | |
| 28 | func registerJavaPluginBuildComponents(ctx android.RegistrationContext) { |
| 29 | ctx.RegisterModuleType("java_plugin", PluginFactory) |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 30 | } |
| 31 | |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 32 | func PluginFactory() android.Module { |
| 33 | module := &Plugin{} |
| 34 | |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 35 | module.addHostProperties() |
| 36 | module.AddProperties(&module.pluginProperties) |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 37 | |
| 38 | InitJavaModule(module, android.HostSupported) |
Sam Delmerico | c06ea03 | 2022-01-28 21:11:03 +0000 | [diff] [blame^] | 39 | |
| 40 | android.InitBazelModule(module) |
| 41 | |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 42 | return module |
| 43 | } |
| 44 | |
Sam Delmerico | c06ea03 | 2022-01-28 21:11:03 +0000 | [diff] [blame^] | 45 | // 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] | 46 | type Plugin struct { |
| 47 | Library |
| 48 | |
| 49 | pluginProperties PluginProperties |
| 50 | } |
| 51 | |
| 52 | type 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 Delmerico | c06ea03 | 2022-01-28 21:11:03 +0000 | [diff] [blame^] | 61 | |
| 62 | type 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. |
| 69 | func (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 | } |