systemserver_classpath_fragment.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. // Copyright 2021 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/dexpreopt"
  18. "github.com/google/blueprint"
  19. )
  20. func init() {
  21. registerSystemserverClasspathBuildComponents(android.InitRegistrationContext)
  22. android.RegisterSdkMemberType(SystemServerClasspathFragmentSdkMemberType)
  23. }
  24. func registerSystemserverClasspathBuildComponents(ctx android.RegistrationContext) {
  25. ctx.RegisterModuleType("platform_systemserverclasspath", platformSystemServerClasspathFactory)
  26. ctx.RegisterModuleType("systemserverclasspath_fragment", systemServerClasspathFactory)
  27. ctx.RegisterModuleType("prebuilt_systemserverclasspath_fragment", prebuiltSystemServerClasspathModuleFactory)
  28. }
  29. var SystemServerClasspathFragmentSdkMemberType = &systemServerClasspathFragmentMemberType{
  30. SdkMemberTypeBase: android.SdkMemberTypeBase{
  31. PropertyName: "systemserverclasspath_fragments",
  32. SupportsSdk: true,
  33. // Support for adding systemserverclasspath_fragments to the sdk snapshot was only added in
  34. // Tiramisu.
  35. SupportedBuildReleaseSpecification: "Tiramisu+",
  36. },
  37. }
  38. type platformSystemServerClasspathModule struct {
  39. android.ModuleBase
  40. ClasspathFragmentBase
  41. }
  42. func platformSystemServerClasspathFactory() android.Module {
  43. m := &platformSystemServerClasspathModule{}
  44. initClasspathFragment(m, SYSTEMSERVERCLASSPATH)
  45. android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
  46. return m
  47. }
  48. func (p *platformSystemServerClasspathModule) AndroidMkEntries() (entries []android.AndroidMkEntries) {
  49. return p.classpathFragmentBase().androidMkEntries()
  50. }
  51. func (p *platformSystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
  52. configuredJars := p.configuredJars(ctx)
  53. classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, p.classpathType)
  54. standaloneConfiguredJars := p.standaloneConfiguredJars(ctx)
  55. standaloneClasspathJars := configuredJarListToClasspathJars(ctx, standaloneConfiguredJars, STANDALONE_SYSTEMSERVER_JARS)
  56. configuredJars = configuredJars.AppendList(&standaloneConfiguredJars)
  57. classpathJars = append(classpathJars, standaloneClasspathJars...)
  58. p.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
  59. }
  60. func (p *platformSystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
  61. // TODO(satayev): include any apex jars that don't populate their classpath proto config.
  62. return dexpreopt.GetGlobalConfig(ctx).SystemServerJars
  63. }
  64. func (p *platformSystemServerClasspathModule) standaloneConfiguredJars(ctx android.ModuleContext) android.ConfiguredJarList {
  65. return dexpreopt.GetGlobalConfig(ctx).StandaloneSystemServerJars
  66. }
  67. type SystemServerClasspathModule struct {
  68. android.ModuleBase
  69. android.ApexModuleBase
  70. ClasspathFragmentBase
  71. properties systemServerClasspathFragmentProperties
  72. // Collect the module directory for IDE info in java/jdeps.go.
  73. modulePaths []string
  74. }
  75. func (s *SystemServerClasspathModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
  76. return nil
  77. }
  78. type systemServerClasspathFragmentProperties struct {
  79. // List of system_server classpath jars, could be either java_library, or java_sdk_library.
  80. //
  81. // The order of this list matters as it is the order that is used in the SYSTEMSERVERCLASSPATH.
  82. Contents []string
  83. // List of jars that system_server loads dynamically using separate classloaders.
  84. //
  85. // The order does not matter.
  86. Standalone_contents []string
  87. }
  88. func systemServerClasspathFactory() android.Module {
  89. m := &SystemServerClasspathModule{}
  90. m.AddProperties(&m.properties)
  91. android.InitApexModule(m)
  92. initClasspathFragment(m, SYSTEMSERVERCLASSPATH)
  93. android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
  94. return m
  95. }
  96. func (s *SystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
  97. if len(s.properties.Contents) == 0 && len(s.properties.Standalone_contents) == 0 {
  98. ctx.PropertyErrorf("contents", "Either contents or standalone_contents needs to be non-empty")
  99. }
  100. configuredJars := s.configuredJars(ctx)
  101. classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, s.classpathType)
  102. standaloneConfiguredJars := s.standaloneConfiguredJars(ctx)
  103. standaloneClasspathJars := configuredJarListToClasspathJars(ctx, standaloneConfiguredJars, STANDALONE_SYSTEMSERVER_JARS)
  104. configuredJars = configuredJars.AppendList(&standaloneConfiguredJars)
  105. classpathJars = append(classpathJars, standaloneClasspathJars...)
  106. s.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
  107. // Collect the module directory for IDE info in java/jdeps.go.
  108. s.modulePaths = append(s.modulePaths, ctx.ModuleDir())
  109. }
  110. func (s *SystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
  111. global := dexpreopt.GetGlobalConfig(ctx)
  112. possibleUpdatableModules := gatherPossibleApexModuleNamesAndStems(ctx, s.properties.Contents, systemServerClasspathFragmentContentDepTag)
  113. jars, unknown := global.ApexSystemServerJars.Filter(possibleUpdatableModules)
  114. // TODO(satayev): remove geotz ssc_fragment, since geotz is not part of SSCP anymore.
  115. _, unknown = android.RemoveFromList("geotz", unknown)
  116. // This module only exists in car products.
  117. // So ignore it even if it is not in PRODUCT_APEX_SYSTEM_SERVER_JARS.
  118. // TODO(b/203233647): Add better mechanism to make it optional.
  119. _, unknown = android.RemoveFromList("car-frameworks-service-module", unknown)
  120. // This module is optional, so it is not present in all products.
  121. // (See PRODUCT_ISOLATED_COMPILATION_ENABLED.)
  122. // So ignore it even if it is not in PRODUCT_APEX_SYSTEM_SERVER_JARS.
  123. // TODO(b/203233647): Add better mechanism to make it optional.
  124. _, unknown = android.RemoveFromList("service-compos", unknown)
  125. // TODO(satayev): for apex_test we want to include all contents unconditionally to classpaths
  126. // config. However, any test specific jars would not be present in ApexSystemServerJars. Instead,
  127. // we should check if we are creating a config for apex_test via ApexInfo and amend the values.
  128. // This is an exception to support end-to-end test for ApexdUnitTests, until such support exists.
  129. if android.InList("test_service-apexd", possibleUpdatableModules) {
  130. jars = jars.Append("com.android.apex.test_package", "test_service-apexd")
  131. } else if global.ApexSystemServerJars.Len() > 0 && len(unknown) > 0 {
  132. // For non test apexes, make sure that all contents are actually declared in make.
  133. ctx.ModuleErrorf("%s in contents must also be declared in PRODUCT_APEX_SYSTEM_SERVER_JARS", unknown)
  134. }
  135. return jars
  136. }
  137. func (s *SystemServerClasspathModule) standaloneConfiguredJars(ctx android.ModuleContext) android.ConfiguredJarList {
  138. global := dexpreopt.GetGlobalConfig(ctx)
  139. possibleUpdatableModules := gatherPossibleApexModuleNamesAndStems(ctx, s.properties.Standalone_contents, systemServerClasspathFragmentContentDepTag)
  140. jars, _ := global.ApexStandaloneSystemServerJars.Filter(possibleUpdatableModules)
  141. // TODO(jiakaiz): add a check to ensure that the contents are declared in make.
  142. return jars
  143. }
  144. type systemServerClasspathFragmentContentDependencyTag struct {
  145. blueprint.BaseDependencyTag
  146. }
  147. // The systemserverclasspath_fragment contents must never depend on prebuilts.
  148. func (systemServerClasspathFragmentContentDependencyTag) ReplaceSourceWithPrebuilt() bool {
  149. return false
  150. }
  151. // SdkMemberType causes dependencies added with this tag to be automatically added to the sdk as if
  152. // they were specified using java_systemserver_libs or java_sdk_libs.
  153. func (b systemServerClasspathFragmentContentDependencyTag) SdkMemberType(child android.Module) android.SdkMemberType {
  154. // If the module is a java_sdk_library then treat it as if it was specified in the java_sdk_libs
  155. // property, otherwise treat if it was specified in the java_systemserver_libs property.
  156. if javaSdkLibrarySdkMemberType.IsInstance(child) {
  157. return javaSdkLibrarySdkMemberType
  158. }
  159. return javaSystemserverLibsSdkMemberType
  160. }
  161. func (b systemServerClasspathFragmentContentDependencyTag) ExportMember() bool {
  162. return true
  163. }
  164. // Contents of system server fragments in an apex are considered to be directly in the apex, as if
  165. // they were listed in java_libs.
  166. func (systemServerClasspathFragmentContentDependencyTag) CopyDirectlyInAnyApex() {}
  167. // Contents of system server fragments require files from prebuilt apex files.
  168. func (systemServerClasspathFragmentContentDependencyTag) RequiresFilesFromPrebuiltApex() {}
  169. var _ android.ReplaceSourceWithPrebuilt = systemServerClasspathFragmentContentDepTag
  170. var _ android.SdkMemberDependencyTag = systemServerClasspathFragmentContentDepTag
  171. var _ android.CopyDirectlyInAnyApexTag = systemServerClasspathFragmentContentDepTag
  172. var _ android.RequiresFilesFromPrebuiltApexTag = systemServerClasspathFragmentContentDepTag
  173. // The tag used for the dependency between the systemserverclasspath_fragment module and its contents.
  174. var systemServerClasspathFragmentContentDepTag = systemServerClasspathFragmentContentDependencyTag{}
  175. func IsSystemServerClasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
  176. return tag == systemServerClasspathFragmentContentDepTag
  177. }
  178. func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
  179. module := ctx.Module()
  180. _, isSourceModule := module.(*SystemServerClasspathModule)
  181. var deps []string
  182. deps = append(deps, s.properties.Contents...)
  183. deps = append(deps, s.properties.Standalone_contents...)
  184. for _, name := range deps {
  185. // A systemserverclasspath_fragment must depend only on other source modules, while the
  186. // prebuilt_systemserverclasspath_fragment_fragment must only depend on other prebuilt modules.
  187. if !isSourceModule {
  188. name = android.PrebuiltNameFromSource(name)
  189. }
  190. ctx.AddDependency(module, systemServerClasspathFragmentContentDepTag, name)
  191. }
  192. }
  193. // Collect information for opening IDE project files in java/jdeps.go.
  194. func (s *SystemServerClasspathModule) IDEInfo(dpInfo *android.IdeInfo) {
  195. dpInfo.Deps = append(dpInfo.Deps, s.properties.Contents...)
  196. dpInfo.Deps = append(dpInfo.Deps, s.properties.Standalone_contents...)
  197. dpInfo.Paths = append(dpInfo.Paths, s.modulePaths...)
  198. }
  199. type systemServerClasspathFragmentMemberType struct {
  200. android.SdkMemberTypeBase
  201. }
  202. func (s *systemServerClasspathFragmentMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
  203. ctx.AddVariationDependencies(nil, dependencyTag, names...)
  204. }
  205. func (s *systemServerClasspathFragmentMemberType) IsInstance(module android.Module) bool {
  206. _, ok := module.(*SystemServerClasspathModule)
  207. return ok
  208. }
  209. func (s *systemServerClasspathFragmentMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
  210. return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_systemserverclasspath_fragment")
  211. }
  212. func (s *systemServerClasspathFragmentMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
  213. return &systemServerClasspathFragmentSdkMemberProperties{}
  214. }
  215. type systemServerClasspathFragmentSdkMemberProperties struct {
  216. android.SdkMemberPropertiesBase
  217. // List of system_server classpath jars, could be either java_library, or java_sdk_library.
  218. //
  219. // The order of this list matters as it is the order that is used in the SYSTEMSERVERCLASSPATH.
  220. Contents []string
  221. // List of jars that system_server loads dynamically using separate classloaders.
  222. //
  223. // The order does not matter.
  224. Standalone_contents []string
  225. }
  226. func (s *systemServerClasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
  227. module := variant.(*SystemServerClasspathModule)
  228. s.Contents = module.properties.Contents
  229. s.Standalone_contents = module.properties.Standalone_contents
  230. }
  231. func (s *systemServerClasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
  232. builder := ctx.SnapshotBuilder()
  233. requiredMemberDependency := builder.SdkMemberReferencePropertyTag(true)
  234. if len(s.Contents) > 0 {
  235. propertySet.AddPropertyWithTag("contents", s.Contents, requiredMemberDependency)
  236. }
  237. if len(s.Standalone_contents) > 0 {
  238. propertySet.AddPropertyWithTag("standalone_contents", s.Standalone_contents, requiredMemberDependency)
  239. }
  240. }
  241. var _ android.SdkMemberType = (*systemServerClasspathFragmentMemberType)(nil)
  242. // A prebuilt version of the systemserverclasspath_fragment module.
  243. type prebuiltSystemServerClasspathModule struct {
  244. SystemServerClasspathModule
  245. prebuilt android.Prebuilt
  246. }
  247. func (module *prebuiltSystemServerClasspathModule) Prebuilt() *android.Prebuilt {
  248. return &module.prebuilt
  249. }
  250. func (module *prebuiltSystemServerClasspathModule) Name() string {
  251. return module.prebuilt.Name(module.ModuleBase.Name())
  252. }
  253. func (module *prebuiltSystemServerClasspathModule) RequiredFilesFromPrebuiltApex(ctx android.BaseModuleContext) []string {
  254. return nil
  255. }
  256. var _ android.RequiredFilesFromPrebuiltApex = (*prebuiltSystemServerClasspathModule)(nil)
  257. func prebuiltSystemServerClasspathModuleFactory() android.Module {
  258. m := &prebuiltSystemServerClasspathModule{}
  259. m.AddProperties(&m.properties)
  260. // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs
  261. // array.
  262. android.InitPrebuiltModule(m, &[]string{"placeholder"})
  263. android.InitApexModule(m)
  264. android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
  265. return m
  266. }