blob: 9111c309f6f127f4fd72cf9db9aba69e5a8744b6 [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"
satayev9366a052021-05-17 21:13:44 +010020 "github.com/google/blueprint"
satayev95e9c5b2021-04-29 11:50:26 +010021)
22
23func init() {
24 registerSystemserverClasspathBuildComponents(android.InitRegistrationContext)
25}
26
27func registerSystemserverClasspathBuildComponents(ctx android.RegistrationContext) {
satayev95e9c5b2021-04-29 11:50:26 +010028 ctx.RegisterModuleType("platform_systemserverclasspath", platformSystemServerClasspathFactory)
satayevaa86bac2021-05-13 19:01:52 +010029 ctx.RegisterModuleType("systemserverclasspath_fragment", systemServerClasspathFactory)
satayev95e9c5b2021-04-29 11:50:26 +010030}
31
32type platformSystemServerClasspathModule struct {
33 android.ModuleBase
34
35 ClasspathFragmentBase
36}
37
38func platformSystemServerClasspathFactory() android.Module {
39 m := &platformSystemServerClasspathModule{}
40 initClasspathFragment(m, SYSTEMSERVERCLASSPATH)
41 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
42 return m
43}
44
satayevaa86bac2021-05-13 19:01:52 +010045func (p *platformSystemServerClasspathModule) AndroidMkEntries() (entries []android.AndroidMkEntries) {
46 return p.classpathFragmentBase().androidMkEntries()
satayev95e9c5b2021-04-29 11:50:26 +010047}
48
satayevaa86bac2021-05-13 19:01:52 +010049func (p *platformSystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
satayev8fab6f82021-05-07 00:10:33 +010050 classpathJars := configuredJarListToClasspathJars(ctx, p.ClasspathFragmentToConfiguredJarList(ctx), p.classpathType)
51 p.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, classpathJars)
satayev013485b2021-05-06 23:38:10 +010052}
53
satayevaa86bac2021-05-13 19:01:52 +010054func (p *platformSystemServerClasspathModule) ClasspathFragmentToConfiguredJarList(ctx android.ModuleContext) android.ConfiguredJarList {
satayev8fab6f82021-05-07 00:10:33 +010055 global := dexpreopt.GetGlobalConfig(ctx)
satayev703c67a2021-05-20 21:33:41 +010056 return global.SystemServerJars
satayev95e9c5b2021-04-29 11:50:26 +010057}
satayevaa86bac2021-05-13 19:01:52 +010058
satayev333a1732021-05-17 21:35:26 +010059type SystemServerClasspathModule struct {
satayevaa86bac2021-05-13 19:01:52 +010060 android.ModuleBase
satayev333a1732021-05-17 21:35:26 +010061 android.ApexModuleBase
satayevaa86bac2021-05-13 19:01:52 +010062
63 ClasspathFragmentBase
satayev9366a052021-05-17 21:13:44 +010064
65 properties systemServerClasspathFragmentProperties
66}
67
satayev333a1732021-05-17 21:35:26 +010068func (s *SystemServerClasspathModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
69 return nil
70}
71
satayev9366a052021-05-17 21:13:44 +010072type systemServerClasspathFragmentProperties struct {
73 // The contents of this systemserverclasspath_fragment, could be either java_library, or java_sdk_library.
74 //
75 // The order of this list matters as it is the order that is used in the SYSTEMSERVERCLASSPATH.
76 Contents []string
satayevaa86bac2021-05-13 19:01:52 +010077}
78
79func systemServerClasspathFactory() android.Module {
satayev333a1732021-05-17 21:35:26 +010080 m := &SystemServerClasspathModule{}
satayev9366a052021-05-17 21:13:44 +010081 m.AddProperties(&m.properties)
satayev333a1732021-05-17 21:35:26 +010082 android.InitApexModule(m)
satayevaa86bac2021-05-13 19:01:52 +010083 initClasspathFragment(m, SYSTEMSERVERCLASSPATH)
84 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
85 return m
86}
87
satayev333a1732021-05-17 21:35:26 +010088func (s *SystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
satayev9366a052021-05-17 21:13:44 +010089 if len(s.properties.Contents) == 0 {
90 ctx.PropertyErrorf("contents", "empty contents are not allowed")
91 }
92
satayev8fab6f82021-05-07 00:10:33 +010093 classpathJars := configuredJarListToClasspathJars(ctx, s.ClasspathFragmentToConfiguredJarList(ctx), s.classpathType)
94 s.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, classpathJars)
satayevaa86bac2021-05-13 19:01:52 +010095}
96
satayev333a1732021-05-17 21:35:26 +010097func (s *SystemServerClasspathModule) ClasspathFragmentToConfiguredJarList(ctx android.ModuleContext) android.ConfiguredJarList {
satayev703c67a2021-05-20 21:33:41 +010098 global := dexpreopt.GetGlobalConfig(ctx)
99
100 // Only create configs for updatable boot jars. Non-updatable system server jars must be part of the
101 // platform_systemserverclasspath's classpath proto config to guarantee that they come before any
102 // updatable jars at runtime.
103 return global.UpdatableSystemServerJars.Filter(s.properties.Contents)
satayevaa86bac2021-05-13 19:01:52 +0100104}
satayev9366a052021-05-17 21:13:44 +0100105
106type systemServerClasspathFragmentContentDependencyTag struct {
107 blueprint.BaseDependencyTag
108}
109
110// The tag used for the dependency between the systemserverclasspath_fragment module and its contents.
111var systemServerClasspathFragmentContentDepTag = systemServerClasspathFragmentContentDependencyTag{}
112
113func IsSystemServerClasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
114 return tag == systemServerClasspathFragmentContentDepTag
115}
116
satayev333a1732021-05-17 21:35:26 +0100117func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
satayev9366a052021-05-17 21:13:44 +0100118 module := ctx.Module()
119
120 for _, name := range s.properties.Contents {
121 ctx.AddDependency(module, systemServerClasspathFragmentContentDepTag, name)
122 }
123}