satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 1 | // 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 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
satayev | 013485b | 2021-05-06 23:38:10 +0100 | [diff] [blame] | 19 | "android/soong/dexpreopt" |
Colin Cross | c33e521 | 2021-05-25 18:16:02 -0700 | [diff] [blame] | 20 | |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 21 | "github.com/google/blueprint" |
satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 22 | ) |
| 23 | |
| 24 | func init() { |
| 25 | registerSystemserverClasspathBuildComponents(android.InitRegistrationContext) |
| 26 | } |
| 27 | |
| 28 | func registerSystemserverClasspathBuildComponents(ctx android.RegistrationContext) { |
satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 29 | ctx.RegisterModuleType("platform_systemserverclasspath", platformSystemServerClasspathFactory) |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 30 | ctx.RegisterModuleType("systemserverclasspath_fragment", systemServerClasspathFactory) |
satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | type platformSystemServerClasspathModule struct { |
| 34 | android.ModuleBase |
| 35 | |
| 36 | ClasspathFragmentBase |
| 37 | } |
| 38 | |
| 39 | func platformSystemServerClasspathFactory() android.Module { |
| 40 | m := &platformSystemServerClasspathModule{} |
| 41 | initClasspathFragment(m, SYSTEMSERVERCLASSPATH) |
| 42 | android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 43 | return m |
| 44 | } |
| 45 | |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 46 | func (p *platformSystemServerClasspathModule) AndroidMkEntries() (entries []android.AndroidMkEntries) { |
| 47 | return p.classpathFragmentBase().androidMkEntries() |
satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 48 | } |
| 49 | |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 50 | func (p *platformSystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
satayev | 8fab6f8 | 2021-05-07 00:10:33 +0100 | [diff] [blame] | 51 | classpathJars := configuredJarListToClasspathJars(ctx, p.ClasspathFragmentToConfiguredJarList(ctx), p.classpathType) |
| 52 | p.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, classpathJars) |
satayev | 013485b | 2021-05-06 23:38:10 +0100 | [diff] [blame] | 53 | } |
| 54 | |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 55 | func (p *platformSystemServerClasspathModule) ClasspathFragmentToConfiguredJarList(ctx android.ModuleContext) android.ConfiguredJarList { |
satayev | 8fab6f8 | 2021-05-07 00:10:33 +0100 | [diff] [blame] | 56 | global := dexpreopt.GetGlobalConfig(ctx) |
satayev | 703c67a | 2021-05-20 21:33:41 +0100 | [diff] [blame] | 57 | return global.SystemServerJars |
satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 58 | } |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 59 | |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 60 | type SystemServerClasspathModule struct { |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 61 | android.ModuleBase |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 62 | android.ApexModuleBase |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 63 | |
| 64 | ClasspathFragmentBase |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 65 | |
| 66 | properties systemServerClasspathFragmentProperties |
bralee | b0c1f0c | 2021-06-07 22:49:13 +0800 | [diff] [blame^] | 67 | |
| 68 | // Collect the module directory for IDE info in java/jdeps.go. |
| 69 | modulePaths []string |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 70 | } |
| 71 | |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 72 | func (s *SystemServerClasspathModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { |
| 73 | return nil |
| 74 | } |
| 75 | |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 76 | type systemServerClasspathFragmentProperties struct { |
| 77 | // The contents of this systemserverclasspath_fragment, could be either java_library, or java_sdk_library. |
| 78 | // |
| 79 | // The order of this list matters as it is the order that is used in the SYSTEMSERVERCLASSPATH. |
| 80 | Contents []string |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | func systemServerClasspathFactory() android.Module { |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 84 | m := &SystemServerClasspathModule{} |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 85 | m.AddProperties(&m.properties) |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 86 | android.InitApexModule(m) |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 87 | initClasspathFragment(m, SYSTEMSERVERCLASSPATH) |
| 88 | android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 89 | return m |
| 90 | } |
| 91 | |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 92 | func (s *SystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 93 | if len(s.properties.Contents) == 0 { |
| 94 | ctx.PropertyErrorf("contents", "empty contents are not allowed") |
| 95 | } |
| 96 | |
satayev | 8fab6f8 | 2021-05-07 00:10:33 +0100 | [diff] [blame] | 97 | classpathJars := configuredJarListToClasspathJars(ctx, s.ClasspathFragmentToConfiguredJarList(ctx), s.classpathType) |
| 98 | s.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, classpathJars) |
bralee | b0c1f0c | 2021-06-07 22:49:13 +0800 | [diff] [blame^] | 99 | |
| 100 | // Collect the module directory for IDE info in java/jdeps.go. |
| 101 | s.modulePaths = append(s.modulePaths, ctx.ModuleDir()) |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 102 | } |
| 103 | |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 104 | func (s *SystemServerClasspathModule) ClasspathFragmentToConfiguredJarList(ctx android.ModuleContext) android.ConfiguredJarList { |
satayev | 703c67a | 2021-05-20 21:33:41 +0100 | [diff] [blame] | 105 | global := dexpreopt.GetGlobalConfig(ctx) |
| 106 | |
satayev | 1c564cc | 2021-05-25 19:50:30 +0100 | [diff] [blame] | 107 | // Convert content names to their appropriate stems, in case a test library is overriding an actual boot jar |
| 108 | var stems []string |
| 109 | for _, name := range s.properties.Contents { |
| 110 | dep := ctx.GetDirectDepWithTag(name, systemServerClasspathFragmentContentDepTag) |
| 111 | if m, ok := dep.(ModuleWithStem); ok { |
| 112 | stems = append(stems, m.Stem()) |
| 113 | } else { |
| 114 | ctx.PropertyErrorf("contents", "%v is not a ModuleWithStem", name) |
| 115 | } |
| 116 | } |
| 117 | |
satayev | 703c67a | 2021-05-20 21:33:41 +0100 | [diff] [blame] | 118 | // Only create configs for updatable boot jars. Non-updatable system server jars must be part of the |
| 119 | // platform_systemserverclasspath's classpath proto config to guarantee that they come before any |
| 120 | // updatable jars at runtime. |
satayev | 1c564cc | 2021-05-25 19:50:30 +0100 | [diff] [blame] | 121 | return global.UpdatableSystemServerJars.Filter(stems) |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 122 | } |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 123 | |
| 124 | type systemServerClasspathFragmentContentDependencyTag struct { |
| 125 | blueprint.BaseDependencyTag |
| 126 | } |
| 127 | |
Colin Cross | c33e521 | 2021-05-25 18:16:02 -0700 | [diff] [blame] | 128 | // Contents of system server fragments in an apex are considered to be directly in the apex, as if |
| 129 | // they were listed in java_libs. |
| 130 | func (systemServerClasspathFragmentContentDependencyTag) CopyDirectlyInAnyApex() {} |
| 131 | |
| 132 | var _ android.CopyDirectlyInAnyApexTag = systemServerClasspathFragmentContentDepTag |
| 133 | |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 134 | // The tag used for the dependency between the systemserverclasspath_fragment module and its contents. |
| 135 | var systemServerClasspathFragmentContentDepTag = systemServerClasspathFragmentContentDependencyTag{} |
| 136 | |
| 137 | func IsSystemServerClasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool { |
| 138 | return tag == systemServerClasspathFragmentContentDepTag |
| 139 | } |
| 140 | |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 141 | func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 142 | module := ctx.Module() |
| 143 | |
| 144 | for _, name := range s.properties.Contents { |
| 145 | ctx.AddDependency(module, systemServerClasspathFragmentContentDepTag, name) |
| 146 | } |
| 147 | } |
bralee | b0c1f0c | 2021-06-07 22:49:13 +0800 | [diff] [blame^] | 148 | |
| 149 | // Collect information for opening IDE project files in java/jdeps.go. |
| 150 | func (s *SystemServerClasspathModule) IDEInfo(dpInfo *android.IdeInfo) { |
| 151 | dpInfo.Deps = append(dpInfo.Deps, s.properties.Contents...) |
| 152 | dpInfo.Paths = append(dpInfo.Paths, s.modulePaths...) |
| 153 | } |