blob: 252c6151f635c9e9ab3997d7801a2f1cbaa83390 [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 Crossc33e5212021-05-25 18:16:02 -070020
satayev9366a052021-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)
satayevaa86bac2021-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
satayevaa86bac2021-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
satayevaa86bac2021-05-13 19:01:52 +010050func (p *platformSystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
satayevb3090502021-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
satayev142ed272021-06-15 16:21:17 +010056func (p *platformSystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
satayevb3090502021-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}
satayevaa86bac2021-05-13 19:01:52 +010060
satayev333a1732021-05-17 21:35:26 +010061type SystemServerClasspathModule struct {
satayevaa86bac2021-05-13 19:01:52 +010062 android.ModuleBase
satayev333a1732021-05-17 21:35:26 +010063 android.ApexModuleBase
satayevaa86bac2021-05-13 19:01:52 +010064
65 ClasspathFragmentBase
satayev9366a052021-05-17 21:13:44 +010066
67 properties systemServerClasspathFragmentProperties
braleeb0c1f0c2021-06-07 22:49:13 +080068
69 // Collect the module directory for IDE info in java/jdeps.go.
70 modulePaths []string
satayev9366a052021-05-17 21:13:44 +010071}
72
satayev333a1732021-05-17 21:35:26 +010073func (s *SystemServerClasspathModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
74 return nil
75}
76
satayev9366a052021-05-17 21:13:44 +010077type systemServerClasspathFragmentProperties struct {
78 // The contents of this systemserverclasspath_fragment, could be either java_library, or java_sdk_library.
79 //
80 // The order of this list matters as it is the order that is used in the SYSTEMSERVERCLASSPATH.
81 Contents []string
satayevaa86bac2021-05-13 19:01:52 +010082}
83
84func systemServerClasspathFactory() android.Module {
satayev333a1732021-05-17 21:35:26 +010085 m := &SystemServerClasspathModule{}
satayev9366a052021-05-17 21:13:44 +010086 m.AddProperties(&m.properties)
satayev333a1732021-05-17 21:35:26 +010087 android.InitApexModule(m)
satayevaa86bac2021-05-13 19:01:52 +010088 initClasspathFragment(m, SYSTEMSERVERCLASSPATH)
89 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
90 return m
91}
92
satayev333a1732021-05-17 21:35:26 +010093func (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
satayevb3090502021-06-15 17:49:10 +010098 configuredJars := s.configuredJars(ctx)
99 classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, s.classpathType)
100 s.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
braleeb0c1f0c2021-06-07 22:49:13 +0800101
102 // Collect the module directory for IDE info in java/jdeps.go.
103 s.modulePaths = append(s.modulePaths, ctx.ModuleDir())
satayevaa86bac2021-05-13 19:01:52 +0100104}
105
satayev142ed272021-06-15 16:21:17 +0100106func (s *SystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
satayev703c67a2021-05-20 21:33:41 +0100107 global := dexpreopt.GetGlobalConfig(ctx)
108
satayev1c564cc2021-05-25 19:50:30 +0100109 // Convert content names to their appropriate stems, in case a test library is overriding an actual boot jar
110 var stems []string
111 for _, name := range s.properties.Contents {
112 dep := ctx.GetDirectDepWithTag(name, systemServerClasspathFragmentContentDepTag)
113 if m, ok := dep.(ModuleWithStem); ok {
114 stems = append(stems, m.Stem())
115 } else {
116 ctx.PropertyErrorf("contents", "%v is not a ModuleWithStem", name)
117 }
118 }
119
satayev703c67a2021-05-20 21:33:41 +0100120 // Only create configs for updatable boot jars. Non-updatable system server jars must be part of the
121 // platform_systemserverclasspath's classpath proto config to guarantee that they come before any
122 // updatable jars at runtime.
satayev1c564cc2021-05-25 19:50:30 +0100123 return global.UpdatableSystemServerJars.Filter(stems)
satayevaa86bac2021-05-13 19:01:52 +0100124}
satayev9366a052021-05-17 21:13:44 +0100125
126type systemServerClasspathFragmentContentDependencyTag struct {
127 blueprint.BaseDependencyTag
128}
129
Colin Crossc33e5212021-05-25 18:16:02 -0700130// Contents of system server fragments in an apex are considered to be directly in the apex, as if
131// they were listed in java_libs.
132func (systemServerClasspathFragmentContentDependencyTag) CopyDirectlyInAnyApex() {}
133
134var _ android.CopyDirectlyInAnyApexTag = systemServerClasspathFragmentContentDepTag
135
satayev9366a052021-05-17 21:13:44 +0100136// The tag used for the dependency between the systemserverclasspath_fragment module and its contents.
137var systemServerClasspathFragmentContentDepTag = systemServerClasspathFragmentContentDependencyTag{}
138
139func IsSystemServerClasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
140 return tag == systemServerClasspathFragmentContentDepTag
141}
142
satayev333a1732021-05-17 21:35:26 +0100143func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
satayev9366a052021-05-17 21:13:44 +0100144 module := ctx.Module()
145
146 for _, name := range s.properties.Contents {
147 ctx.AddDependency(module, systemServerClasspathFragmentContentDepTag, name)
148 }
149}
braleeb0c1f0c2021-06-07 22:49:13 +0800150
151// Collect information for opening IDE project files in java/jdeps.go.
152func (s *SystemServerClasspathModule) IDEInfo(dpInfo *android.IdeInfo) {
153 dpInfo.Deps = append(dpInfo.Deps, s.properties.Contents...)
154 dpInfo.Paths = append(dpInfo.Paths, s.modulePaths...)
155}