blob: a72b3f60ce212711c96619fada62f4340f256fd8 [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)
satayev013485b2021-05-06 23:38:10 +010056
satayev8fab6f82021-05-07 00:10:33 +010057 jars := global.SystemServerJars
58 // TODO(satayev): split apex jars into separate configs.
59 for i := 0; i < global.UpdatableSystemServerJars.Len(); i++ {
60 jars = jars.Append(global.UpdatableSystemServerJars.Apex(i), global.UpdatableSystemServerJars.Jar(i))
61 }
62 return jars
satayev95e9c5b2021-04-29 11:50:26 +010063}
satayevaa86bac2021-05-13 19:01:52 +010064
satayev333a1732021-05-17 21:35:26 +010065type SystemServerClasspathModule struct {
satayevaa86bac2021-05-13 19:01:52 +010066 android.ModuleBase
satayev333a1732021-05-17 21:35:26 +010067 android.ApexModuleBase
satayevaa86bac2021-05-13 19:01:52 +010068
69 ClasspathFragmentBase
satayev9366a052021-05-17 21:13:44 +010070
71 properties systemServerClasspathFragmentProperties
72}
73
satayev333a1732021-05-17 21:35:26 +010074func (s *SystemServerClasspathModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
75 return nil
76}
77
satayev9366a052021-05-17 21:13:44 +010078type systemServerClasspathFragmentProperties struct {
79 // The contents of this systemserverclasspath_fragment, 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
satayevaa86bac2021-05-13 19:01:52 +010083}
84
85func systemServerClasspathFactory() android.Module {
satayev333a1732021-05-17 21:35:26 +010086 m := &SystemServerClasspathModule{}
satayev9366a052021-05-17 21:13:44 +010087 m.AddProperties(&m.properties)
satayev333a1732021-05-17 21:35:26 +010088 android.InitApexModule(m)
satayevaa86bac2021-05-13 19:01:52 +010089 initClasspathFragment(m, SYSTEMSERVERCLASSPATH)
90 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
91 return m
92}
93
satayev333a1732021-05-17 21:35:26 +010094func (s *SystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
satayev9366a052021-05-17 21:13:44 +010095 if len(s.properties.Contents) == 0 {
96 ctx.PropertyErrorf("contents", "empty contents are not allowed")
97 }
98
satayev8fab6f82021-05-07 00:10:33 +010099 classpathJars := configuredJarListToClasspathJars(ctx, s.ClasspathFragmentToConfiguredJarList(ctx), s.classpathType)
100 s.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, classpathJars)
satayevaa86bac2021-05-13 19:01:52 +0100101}
102
satayev333a1732021-05-17 21:35:26 +0100103func (s *SystemServerClasspathModule) ClasspathFragmentToConfiguredJarList(ctx android.ModuleContext) android.ConfiguredJarList {
satayevaa86bac2021-05-13 19:01:52 +0100104 // TODO(satayev): populate with actual content
105 return android.EmptyConfiguredJarList()
106}
satayev9366a052021-05-17 21:13:44 +0100107
108type systemServerClasspathFragmentContentDependencyTag struct {
109 blueprint.BaseDependencyTag
110}
111
112// The tag used for the dependency between the systemserverclasspath_fragment module and its contents.
113var systemServerClasspathFragmentContentDepTag = systemServerClasspathFragmentContentDependencyTag{}
114
115func IsSystemServerClasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
116 return tag == systemServerClasspathFragmentContentDepTag
117}
118
satayev333a1732021-05-17 21:35:26 +0100119func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
satayev9366a052021-05-17 21:13:44 +0100120 module := ctx.Module()
121
122 for _, name := range s.properties.Contents {
123 ctx.AddDependency(module, systemServerClasspathFragmentContentDepTag, name)
124 }
125}