plugin.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. package java
  15. import (
  16. "android/soong/android"
  17. "android/soong/bazel"
  18. )
  19. func init() {
  20. registerJavaPluginBuildComponents(android.InitRegistrationContext)
  21. }
  22. func registerJavaPluginBuildComponents(ctx android.RegistrationContext) {
  23. ctx.RegisterModuleType("java_plugin", PluginFactory)
  24. }
  25. func PluginFactory() android.Module {
  26. module := &Plugin{}
  27. module.addHostProperties()
  28. module.AddProperties(&module.pluginProperties)
  29. InitJavaModule(module, android.HostSupported)
  30. android.InitBazelModule(module)
  31. return module
  32. }
  33. // Plugin describes a java_plugin module, a host java library that will be used by javac as an annotation processor.
  34. type Plugin struct {
  35. Library
  36. pluginProperties PluginProperties
  37. }
  38. type PluginProperties struct {
  39. // The optional name of the class that javac will use to run the annotation processor.
  40. Processor_class *string
  41. // If true, assume the annotation processor will generate classes that are referenced from outside the module.
  42. // This necessitates disabling the turbine optimization on modules that use this plugin, which will reduce
  43. // parallelism and cause more recompilation for modules that depend on modules that use this plugin.
  44. Generates_api *bool
  45. }
  46. type pluginAttributes struct {
  47. *javaCommonAttributes
  48. Deps bazel.LabelListAttribute
  49. Processor_class *string
  50. }
  51. // ConvertWithBp2build is used to convert android_app to Bazel.
  52. func (p *Plugin) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
  53. pluginName := p.Name()
  54. commonAttrs, bp2BuildInfo := p.convertLibraryAttrsBp2Build(ctx)
  55. depLabels := bp2BuildInfo.DepLabels
  56. deps := depLabels.Deps
  57. deps.Append(depLabels.StaticDeps)
  58. var processorClass *string
  59. if p.pluginProperties.Processor_class != nil {
  60. processorClass = p.pluginProperties.Processor_class
  61. }
  62. attrs := &pluginAttributes{
  63. javaCommonAttributes: commonAttrs,
  64. Deps: deps,
  65. Processor_class: processorClass,
  66. }
  67. props := bazel.BazelTargetModuleProperties{
  68. Rule_class: "java_plugin",
  69. }
  70. ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: pluginName}, attrs)
  71. }