sdk_library_external.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 java
  15. import (
  16. "android/soong/android"
  17. )
  18. type partitionGroup int
  19. // Representation of partition group for checking inter-partition library dependencies.
  20. // Between system and system_ext, there are no restrictions of dependencies,
  21. // so we can treat these partitions as the same in terms of inter-partition dependency.
  22. // Same policy is applied between vendor and odm partiton.
  23. const (
  24. partitionGroupNone partitionGroup = iota
  25. // group for system, and system_ext partition
  26. partitionGroupSystem
  27. // group for vendor and odm partition
  28. partitionGroupVendor
  29. // product partition
  30. partitionGroupProduct
  31. )
  32. func (g partitionGroup) String() string {
  33. switch g {
  34. case partitionGroupSystem:
  35. return "system"
  36. case partitionGroupVendor:
  37. return "vendor"
  38. case partitionGroupProduct:
  39. return "product"
  40. }
  41. return ""
  42. }
  43. // Get partition group of java module that can be used at inter-partition dependency check.
  44. // We currently have three groups
  45. //
  46. // (system, system_ext) => system partition group
  47. // (vendor, odm) => vendor partition group
  48. // (product) => product partition group
  49. func (j *Module) partitionGroup(ctx android.EarlyModuleContext) partitionGroup {
  50. // system and system_ext partition can be treated as the same in terms of inter-partition dependency.
  51. if j.Platform() || j.SystemExtSpecific() {
  52. return partitionGroupSystem
  53. }
  54. // vendor and odm partition can be treated as the same in terms of inter-partition dependency.
  55. if j.SocSpecific() || j.DeviceSpecific() {
  56. return partitionGroupVendor
  57. }
  58. // product partition is independent.
  59. if j.ProductSpecific() {
  60. return partitionGroupProduct
  61. }
  62. panic("Cannot determine partition type")
  63. }
  64. func (j *Module) allowListedInterPartitionJavaLibrary(ctx android.EarlyModuleContext) bool {
  65. return inList(j.Name(), ctx.Config().InterPartitionJavaLibraryAllowList())
  66. }
  67. func (j *Module) syspropWithPublicStubs() bool {
  68. return j.deviceProperties.SyspropPublicStub != ""
  69. }
  70. type javaSdkLibraryEnforceContext interface {
  71. Name() string
  72. allowListedInterPartitionJavaLibrary(ctx android.EarlyModuleContext) bool
  73. partitionGroup(ctx android.EarlyModuleContext) partitionGroup
  74. syspropWithPublicStubs() bool
  75. }
  76. var _ javaSdkLibraryEnforceContext = (*Module)(nil)
  77. func (j *Module) checkPartitionsForJavaDependency(ctx android.EarlyModuleContext, propName string, dep javaSdkLibraryEnforceContext) {
  78. if dep.allowListedInterPartitionJavaLibrary(ctx) {
  79. return
  80. }
  81. if dep.syspropWithPublicStubs() {
  82. return
  83. }
  84. // If product interface is not enforced, skip check between system and product partition.
  85. // But still need to check between product and vendor partition because product interface flag
  86. // just represents enforcement between product and system, and vendor interface enforcement
  87. // that is enforced here by precondition is representing enforcement between vendor and other partitions.
  88. if !ctx.Config().EnforceProductPartitionInterface() {
  89. productToSystem := j.partitionGroup(ctx) == partitionGroupProduct && dep.partitionGroup(ctx) == partitionGroupSystem
  90. systemToProduct := j.partitionGroup(ctx) == partitionGroupSystem && dep.partitionGroup(ctx) == partitionGroupProduct
  91. if productToSystem || systemToProduct {
  92. return
  93. }
  94. }
  95. // If module and dependency library is inter-partition
  96. if j.partitionGroup(ctx) != dep.partitionGroup(ctx) {
  97. errorFormat := "dependency on java_library (%q) is not allowed across the partitions (%s -> %s), use java_sdk_library instead"
  98. ctx.PropertyErrorf(propName, errorFormat, dep.Name(), j.partitionGroup(ctx), dep.partitionGroup(ctx))
  99. }
  100. }