license_kind.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright 2020 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 android
  15. import "android/soong/bazel"
  16. func init() {
  17. RegisterLicenseKindBuildComponents(InitRegistrationContext)
  18. }
  19. // Register the license_kind module type.
  20. func RegisterLicenseKindBuildComponents(ctx RegistrationContext) {
  21. ctx.RegisterModuleType("license_kind", LicenseKindFactory)
  22. }
  23. type licenseKindProperties struct {
  24. // Specifies the conditions for all licenses of the kind.
  25. Conditions []string
  26. // Specifies the url to the canonical license definition.
  27. Url string
  28. // Specifies where this license can be used
  29. Visibility []string
  30. }
  31. var _ Bazelable = &licenseKindModule{}
  32. type licenseKindModule struct {
  33. ModuleBase
  34. DefaultableModuleBase
  35. BazelModuleBase
  36. properties licenseKindProperties
  37. }
  38. type bazelLicenseKindAttributes struct {
  39. Conditions []string
  40. Url string
  41. Visibility []string
  42. }
  43. func (m *licenseKindModule) ConvertWithBp2build(ctx TopDownMutatorContext) {
  44. attrs := &bazelLicenseKindAttributes{
  45. Conditions: m.properties.Conditions,
  46. Url: m.properties.Url,
  47. Visibility: m.properties.Visibility,
  48. }
  49. ctx.CreateBazelTargetModule(
  50. bazel.BazelTargetModuleProperties{
  51. Rule_class: "license_kind",
  52. Bzl_load_location: "@rules_license//rules:license_kind.bzl",
  53. },
  54. CommonAttributes{
  55. Name: m.Name(),
  56. },
  57. attrs)
  58. }
  59. func (m *licenseKindModule) DepsMutator(ctx BottomUpMutatorContext) {
  60. // Nothing to do.
  61. }
  62. func (m *licenseKindModule) GenerateAndroidBuildActions(ModuleContext) {
  63. // Nothing to do.
  64. }
  65. func LicenseKindFactory() Module {
  66. module := &licenseKindModule{}
  67. base := module.base()
  68. module.AddProperties(&base.nameProperties, &module.properties, &base.commonProperties.BazelConversionStatus)
  69. // The visibility property needs to be checked and parsed by the visibility module.
  70. setPrimaryVisibilityProperty(module, "visibility", &module.properties.Visibility)
  71. initAndroidModuleBase(module)
  72. InitDefaultableModule(module)
  73. InitBazelModule(module)
  74. return module
  75. }