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 15package java 16 17import ( 18 "android/soong/android" 19 "android/soong/bazel" 20) 21 22func init() { 23 registerJavaPluginBuildComponents(android.InitRegistrationContext) 24} 25 26func registerJavaPluginBuildComponents(ctx android.RegistrationContext) { 27 ctx.RegisterModuleType("java_plugin", PluginFactory) 28} 29 30func PluginFactory() android.Module { 31 module := &Plugin{} 32 33 module.addHostProperties() 34 module.AddProperties(&module.pluginProperties) 35 36 InitJavaModule(module, android.HostSupported) 37 38 android.InitBazelModule(module) 39 40 return module 41} 42 43// Plugin describes a java_plugin module, a host java library that will be used by javac as an annotation processor. 44type 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} 59 60type pluginAttributes struct { 61 *javaCommonAttributes 62 Deps bazel.LabelListAttribute 63 Processor_class *string 64} 65 66// ConvertWithBp2build is used to convert android_app to Bazel. 67func (p *Plugin) ConvertWithBp2build(ctx android.TopDownMutatorContext) { 68 pluginName := p.Name() 69 commonAttrs, depLabels := p.convertLibraryAttrsBp2Build(ctx) 70 71 deps := depLabels.Deps 72 deps.Append(depLabels.StaticDeps) 73 74 var processorClass *string 75 if p.pluginProperties.Processor_class != nil { 76 processorClass = p.pluginProperties.Processor_class 77 } 78 79 attrs := &pluginAttributes{ 80 javaCommonAttributes: commonAttrs, 81 Deps: deps, 82 Processor_class: processorClass, 83 } 84 85 props := bazel.BazelTargetModuleProperties{ 86 Rule_class: "java_plugin", 87 } 88 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: pluginName}, attrs) 89} 90