license.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 (
  16. "github.com/google/blueprint"
  17. )
  18. type licenseKindDependencyTag struct {
  19. blueprint.BaseDependencyTag
  20. }
  21. var (
  22. licenseKindTag = licenseKindDependencyTag{}
  23. )
  24. func init() {
  25. RegisterLicenseBuildComponents(InitRegistrationContext)
  26. }
  27. // Register the license module type.
  28. func RegisterLicenseBuildComponents(ctx RegistrationContext) {
  29. ctx.RegisterModuleType("license", LicenseFactory)
  30. }
  31. type licenseProperties struct {
  32. // Specifies the kinds of license that apply.
  33. License_kinds []string
  34. // Specifies a short copyright notice to use for the license.
  35. Copyright_notice *string
  36. // Specifies the path or label for the text of the license.
  37. License_text []string `android:"path"`
  38. // Specifies the package name to which the license applies.
  39. Package_name *string
  40. // Specifies where this license can be used
  41. Visibility []string
  42. }
  43. type licenseModule struct {
  44. ModuleBase
  45. DefaultableModuleBase
  46. SdkBase
  47. properties licenseProperties
  48. }
  49. func (m *licenseModule) DepsMutator(ctx BottomUpMutatorContext) {
  50. ctx.AddVariationDependencies(nil, licenseKindTag, m.properties.License_kinds...)
  51. }
  52. func (m *licenseModule) GenerateAndroidBuildActions(ctx ModuleContext) {
  53. // license modules have no licenses, but license_kinds must refer to license_kind modules
  54. mergeStringProps(&m.base().commonProperties.Effective_licenses, ctx.ModuleName())
  55. namePathProps(&m.base().commonProperties.Effective_license_text, m.properties.Package_name, PathsForModuleSrc(ctx, m.properties.License_text)...)
  56. for _, module := range ctx.GetDirectDepsWithTag(licenseKindTag) {
  57. if lk, ok := module.(*licenseKindModule); ok {
  58. mergeStringProps(&m.base().commonProperties.Effective_license_conditions, lk.properties.Conditions...)
  59. mergeStringProps(&m.base().commonProperties.Effective_license_kinds, ctx.OtherModuleName(module))
  60. } else {
  61. ctx.ModuleErrorf("license_kinds property %q is not a license_kind module", ctx.OtherModuleName(module))
  62. }
  63. }
  64. }
  65. func LicenseFactory() Module {
  66. module := &licenseModule{}
  67. base := module.base()
  68. module.AddProperties(&base.nameProperties, &module.properties)
  69. // The visibility property needs to be checked and parsed by the visibility module.
  70. setPrimaryVisibilityProperty(module, "visibility", &module.properties.Visibility)
  71. InitSdkAwareModule(module)
  72. initAndroidModuleBase(module)
  73. InitDefaultableModule(module)
  74. return module
  75. }