blob: 4e65c056b138f5fe35118c1df06db74d887af6fd [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
70type systemServerClasspathModule struct {
71 android.ModuleBase
72
73 ClasspathFragmentBase
satayev9366a052021-05-17 21:13:44 +010074
75 properties systemServerClasspathFragmentProperties
76}
77
78type 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 {
86 m := &systemServerClasspathModule{}
satayev9366a052021-05-17 21:13:44 +010087 m.AddProperties(&m.properties)
satayevaa86bac2021-05-13 19:01:52 +010088 initClasspathFragment(m, SYSTEMSERVERCLASSPATH)
89 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
90 return m
91}
92
93func (s *systemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
satayev9366a052021-05-17 21:13:44 +010094 if len(s.properties.Contents) == 0 {
95 ctx.PropertyErrorf("contents", "empty contents are not allowed")
96 }
97
satayevaa86bac2021-05-13 19:01:52 +010098 s.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJarListToClasspathJars(ctx, s.ClasspathFragmentToConfiguredJarList(ctx)))
99}
100
101func (s *systemServerClasspathModule) ClasspathFragmentToConfiguredJarList(ctx android.ModuleContext) android.ConfiguredJarList {
102 // TODO(satayev): populate with actual content
103 return android.EmptyConfiguredJarList()
104}
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
117func (s *systemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
118 module := ctx.Module()
119
120 for _, name := range s.properties.Contents {
121 ctx.AddDependency(module, systemServerClasspathFragmentContentDepTag, name)
122 }
123}