blob: a505c6d01605f01354567bf97dbf045bee01cac6 [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) {
50 configuredJars := configuredJarListToClasspathJars(ctx, p.ClasspathFragmentToConfiguredJarList(ctx), p.classpathType)
51 p.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars)
satayev013485b2021-05-06 23:38:10 +010052}
53
54var platformSystemServerClasspathKey = android.NewOnceKey("platform_systemserverclasspath")
55
satayevaa86bac2021-05-13 19:01:52 +010056func (p *platformSystemServerClasspathModule) ClasspathFragmentToConfiguredJarList(ctx android.ModuleContext) android.ConfiguredJarList {
satayev013485b2021-05-06 23:38:10 +010057 return ctx.Config().Once(platformSystemServerClasspathKey, func() interface{} {
58 global := dexpreopt.GetGlobalConfig(ctx)
59
60 jars := global.SystemServerJars
61
62 // TODO(satayev): split apex jars into separate configs.
63 for i := 0; i < global.UpdatableSystemServerJars.Len(); i++ {
64 jars = jars.Append(global.UpdatableSystemServerJars.Apex(i), global.UpdatableSystemServerJars.Jar(i))
65 }
66 return jars
67 }).(android.ConfiguredJarList)
satayev95e9c5b2021-04-29 11:50:26 +010068}
satayevaa86bac2021-05-13 19:01:52 +010069
satayev333a1732021-05-17 21:35:26 +010070type SystemServerClasspathModule struct {
satayevaa86bac2021-05-13 19:01:52 +010071 android.ModuleBase
satayev333a1732021-05-17 21:35:26 +010072 android.ApexModuleBase
satayevaa86bac2021-05-13 19:01:52 +010073
74 ClasspathFragmentBase
satayev9366a052021-05-17 21:13:44 +010075
76 properties systemServerClasspathFragmentProperties
77}
78
satayev333a1732021-05-17 21:35:26 +010079func (s *SystemServerClasspathModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
80 return nil
81}
82
satayev9366a052021-05-17 21:13:44 +010083type systemServerClasspathFragmentProperties struct {
84 // The contents of this systemserverclasspath_fragment, could be either java_library, or java_sdk_library.
85 //
86 // The order of this list matters as it is the order that is used in the SYSTEMSERVERCLASSPATH.
87 Contents []string
satayevaa86bac2021-05-13 19:01:52 +010088}
89
90func systemServerClasspathFactory() android.Module {
satayev333a1732021-05-17 21:35:26 +010091 m := &SystemServerClasspathModule{}
satayev9366a052021-05-17 21:13:44 +010092 m.AddProperties(&m.properties)
satayev333a1732021-05-17 21:35:26 +010093 android.InitApexModule(m)
satayevaa86bac2021-05-13 19:01:52 +010094 initClasspathFragment(m, SYSTEMSERVERCLASSPATH)
95 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
96 return m
97}
98
satayev333a1732021-05-17 21:35:26 +010099func (s *SystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
satayev9366a052021-05-17 21:13:44 +0100100 if len(s.properties.Contents) == 0 {
101 ctx.PropertyErrorf("contents", "empty contents are not allowed")
102 }
103
satayevaa86bac2021-05-13 19:01:52 +0100104 s.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJarListToClasspathJars(ctx, s.ClasspathFragmentToConfiguredJarList(ctx)))
105}
106
satayev333a1732021-05-17 21:35:26 +0100107func (s *SystemServerClasspathModule) ClasspathFragmentToConfiguredJarList(ctx android.ModuleContext) android.ConfiguredJarList {
satayevaa86bac2021-05-13 19:01:52 +0100108 // TODO(satayev): populate with actual content
109 return android.EmptyConfiguredJarList()
110}
satayev9366a052021-05-17 21:13:44 +0100111
112type systemServerClasspathFragmentContentDependencyTag struct {
113 blueprint.BaseDependencyTag
114}
115
116// The tag used for the dependency between the systemserverclasspath_fragment module and its contents.
117var systemServerClasspathFragmentContentDepTag = systemServerClasspathFragmentContentDependencyTag{}
118
119func IsSystemServerClasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
120 return tag == systemServerClasspathFragmentContentDepTag
121}
122
satayev333a1732021-05-17 21:35:26 +0100123func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
satayev9366a052021-05-17 21:13:44 +0100124 module := ctx.Module()
125
126 for _, name := range s.properties.Contents {
127 ctx.AddDependency(module, systemServerClasspathFragmentContentDepTag, name)
128 }
129}