blob: be28fe9c2ddbc5df15478af9b71d5b36f6f1bd45 [file] [log] [blame]
satayev95e9c5b2021-04-29 11:50:26 +01001// 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
15package java
16
17import (
18 "android/soong/android"
satayev013485b2021-05-06 23:38:10 +010019 "android/soong/dexpreopt"
Colin Crosscbb2b812021-05-25 18:16:02 -070020
satayev7b182e72021-05-17 21:13:44 +010021 "github.com/google/blueprint"
satayev95e9c5b2021-04-29 11:50:26 +010022)
23
24func init() {
25 registerSystemserverClasspathBuildComponents(android.InitRegistrationContext)
26}
27
28func registerSystemserverClasspathBuildComponents(ctx android.RegistrationContext) {
satayev95e9c5b2021-04-29 11:50:26 +010029 ctx.RegisterModuleType("platform_systemserverclasspath", platformSystemServerClasspathFactory)
satayev0cf6de52021-05-13 19:01:52 +010030 ctx.RegisterModuleType("systemserverclasspath_fragment", systemServerClasspathFactory)
satayev95e9c5b2021-04-29 11:50:26 +010031}
32
33type platformSystemServerClasspathModule struct {
34 android.ModuleBase
35
36 ClasspathFragmentBase
37}
38
39func platformSystemServerClasspathFactory() android.Module {
40 m := &platformSystemServerClasspathModule{}
41 initClasspathFragment(m, SYSTEMSERVERCLASSPATH)
42 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
43 return m
44}
45
satayev0cf6de52021-05-13 19:01:52 +010046func (p *platformSystemServerClasspathModule) AndroidMkEntries() (entries []android.AndroidMkEntries) {
47 return p.classpathFragmentBase().androidMkEntries()
satayev95e9c5b2021-04-29 11:50:26 +010048}
49
satayev0cf6de52021-05-13 19:01:52 +010050func (p *platformSystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
satayev1d0f0232021-06-15 17:49:10 +010051 configuredJars := p.configuredJars(ctx)
52 classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, p.classpathType)
53 p.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
satayev013485b2021-05-06 23:38:10 +010054}
55
satayev64646ee2021-06-15 16:21:17 +010056func (p *platformSystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
satayev1d0f0232021-06-15 17:49:10 +010057 // TODO(satayev): include any apex jars that don't populate their classpath proto config.
58 return dexpreopt.GetGlobalConfig(ctx).SystemServerJars
satayev95e9c5b2021-04-29 11:50:26 +010059}
satayev0cf6de52021-05-13 19:01:52 +010060
satayev2f45f4e2021-05-17 21:35:26 +010061type SystemServerClasspathModule struct {
satayev0cf6de52021-05-13 19:01:52 +010062 android.ModuleBase
satayev2f45f4e2021-05-17 21:35:26 +010063 android.ApexModuleBase
satayev0cf6de52021-05-13 19:01:52 +010064
65 ClasspathFragmentBase
satayev7b182e72021-05-17 21:13:44 +010066
67 properties systemServerClasspathFragmentProperties
68}
69
satayev2f45f4e2021-05-17 21:35:26 +010070func (s *SystemServerClasspathModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
71 return nil
72}
73
satayev7b182e72021-05-17 21:13:44 +010074type systemServerClasspathFragmentProperties struct {
Jiakai Zhang9d929642022-01-19 19:37:39 +000075 // List of system_server classpath jars, could be either java_library, or java_sdk_library.
satayev7b182e72021-05-17 21:13:44 +010076 //
77 // The order of this list matters as it is the order that is used in the SYSTEMSERVERCLASSPATH.
78 Contents []string
Jiakai Zhang9d929642022-01-19 19:37:39 +000079
80 // List of jars that system_server loads dynamically using separate classloaders.
81 //
82 // The order does not matter.
83 Standalone_contents []string
satayev0cf6de52021-05-13 19:01:52 +010084}
85
86func systemServerClasspathFactory() android.Module {
satayev2f45f4e2021-05-17 21:35:26 +010087 m := &SystemServerClasspathModule{}
satayev7b182e72021-05-17 21:13:44 +010088 m.AddProperties(&m.properties)
satayev2f45f4e2021-05-17 21:35:26 +010089 android.InitApexModule(m)
satayev0cf6de52021-05-13 19:01:52 +010090 initClasspathFragment(m, SYSTEMSERVERCLASSPATH)
91 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
92 return m
93}
94
satayev2f45f4e2021-05-17 21:35:26 +010095func (s *SystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiakai Zhang9d929642022-01-19 19:37:39 +000096 if len(s.properties.Contents) == 0 && len(s.properties.Standalone_contents) == 0 {
97 ctx.PropertyErrorf("contents", "Either contents or standalone_contents needs to be non-empty")
98 }
99
100 if s.ShouldIgnore() {
101 return
satayev7b182e72021-05-17 21:13:44 +0100102 }
103
satayev1d0f0232021-06-15 17:49:10 +0100104 configuredJars := s.configuredJars(ctx)
105 classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, s.classpathType)
106 s.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
satayev0cf6de52021-05-13 19:01:52 +0100107}
108
satayev64646ee2021-06-15 16:21:17 +0100109func (s *SystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
satayev931a4482021-05-20 21:33:41 +0100110 global := dexpreopt.GetGlobalConfig(ctx)
111
satayev7a552ba2021-07-21 14:23:52 +0100112 possibleUpdatableModules := gatherPossibleApexModuleNamesAndStems(ctx, s.properties.Contents, systemServerClasspathFragmentContentDepTag)
satayevfcea20c2021-07-28 14:04:49 +0100113 return global.ApexSystemServerJars.Filter(possibleUpdatableModules)
satayev0cf6de52021-05-13 19:01:52 +0100114}
satayev7b182e72021-05-17 21:13:44 +0100115
116type systemServerClasspathFragmentContentDependencyTag struct {
117 blueprint.BaseDependencyTag
118}
119
Paul Duffinba96f7c2021-06-29 17:57:50 +0100120// The systemserverclasspath_fragment contents must never depend on prebuilts.
121func (systemServerClasspathFragmentContentDependencyTag) ReplaceSourceWithPrebuilt() bool {
122 return false
123}
124
Colin Crosscbb2b812021-05-25 18:16:02 -0700125// Contents of system server fragments in an apex are considered to be directly in the apex, as if
126// they were listed in java_libs.
127func (systemServerClasspathFragmentContentDependencyTag) CopyDirectlyInAnyApex() {}
128
129var _ android.CopyDirectlyInAnyApexTag = systemServerClasspathFragmentContentDepTag
130
satayev7b182e72021-05-17 21:13:44 +0100131// The tag used for the dependency between the systemserverclasspath_fragment module and its contents.
132var systemServerClasspathFragmentContentDepTag = systemServerClasspathFragmentContentDependencyTag{}
133
134func IsSystemServerClasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
135 return tag == systemServerClasspathFragmentContentDepTag
136}
137
satayev2f45f4e2021-05-17 21:35:26 +0100138func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
satayev7b182e72021-05-17 21:13:44 +0100139 module := ctx.Module()
Jiakai Zhang9d929642022-01-19 19:37:39 +0000140 var deps []string
141 deps = append(deps, s.properties.Contents...)
142 deps = append(deps, s.properties.Standalone_contents...)
satayev7b182e72021-05-17 21:13:44 +0100143
Jiakai Zhang9d929642022-01-19 19:37:39 +0000144 for _, name := range deps {
satayev7b182e72021-05-17 21:13:44 +0100145 ctx.AddDependency(module, systemServerClasspathFragmentContentDepTag, name)
146 }
147}
Jiakai Zhang9d929642022-01-19 19:37:39 +0000148
149func (s *SystemServerClasspathModule) ShouldIgnore() bool {
150 // Ignore this `systemserverclasspath_fragment` if it only contains `standalone_contents` because
151 // it is for T and above.
152 return len(s.properties.Contents) == 0
153}