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 | b309050 | 2021-06-15 17:49:10 +0100 | [diff] [blame] | 51 | configuredJars := p.configuredJars(ctx) |
| 52 | classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, p.classpathType) |
| 53 | p.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars) |
satayev | 013485b | 2021-05-06 23:38:10 +0100 | [diff] [blame] | 54 | } |
| 55 | |
satayev | 142ed27 | 2021-06-15 16:21:17 +0100 | [diff] [blame] | 56 | func (p *platformSystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList { |
satayev | b309050 | 2021-06-15 17:49:10 +0100 | [diff] [blame] | 57 | // TODO(satayev): include any apex jars that don't populate their classpath proto config. |
| 58 | return dexpreopt.GetGlobalConfig(ctx).SystemServerJars |
satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 59 | } |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 60 | |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 61 | type SystemServerClasspathModule struct { |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 62 | android.ModuleBase |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 63 | android.ApexModuleBase |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 64 | |
| 65 | ClasspathFragmentBase |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 66 | |
| 67 | properties systemServerClasspathFragmentProperties |
bralee | b0c1f0c | 2021-06-07 22:49:13 +0800 | [diff] [blame] | 68 | |
| 69 | // Collect the module directory for IDE info in java/jdeps.go. |
| 70 | modulePaths []string |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 71 | } |
| 72 | |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 73 | func (s *SystemServerClasspathModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { |
| 74 | return nil |
| 75 | } |
| 76 | |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 77 | type 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 |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | func systemServerClasspathFactory() android.Module { |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 85 | m := &SystemServerClasspathModule{} |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 86 | m.AddProperties(&m.properties) |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 87 | android.InitApexModule(m) |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 88 | initClasspathFragment(m, SYSTEMSERVERCLASSPATH) |
| 89 | android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 90 | return m |
| 91 | } |
| 92 | |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 93 | func (s *SystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 94 | if len(s.properties.Contents) == 0 { |
| 95 | ctx.PropertyErrorf("contents", "empty contents are not allowed") |
| 96 | } |
| 97 | |
satayev | b309050 | 2021-06-15 17:49:10 +0100 | [diff] [blame] | 98 | configuredJars := s.configuredJars(ctx) |
| 99 | classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, s.classpathType) |
| 100 | s.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars) |
bralee | b0c1f0c | 2021-06-07 22:49:13 +0800 | [diff] [blame] | 101 | |
| 102 | // Collect the module directory for IDE info in java/jdeps.go. |
| 103 | s.modulePaths = append(s.modulePaths, ctx.ModuleDir()) |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 104 | } |
| 105 | |
satayev | 142ed27 | 2021-06-15 16:21:17 +0100 | [diff] [blame] | 106 | func (s *SystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList { |
satayev | 703c67a | 2021-05-20 21:33:41 +0100 | [diff] [blame] | 107 | global := dexpreopt.GetGlobalConfig(ctx) |
| 108 | |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 109 | possibleUpdatableModules := gatherPossibleApexModuleNamesAndStems(ctx, s.properties.Contents, systemServerClasspathFragmentContentDepTag) |
satayev | d34eb0c | 2021-08-06 13:20:28 +0100 | [diff] [blame] | 110 | jars, unknown := global.ApexSystemServerJars.Filter(possibleUpdatableModules) |
| 111 | // TODO(satayev): remove geotz ssc_fragment, since geotz is not part of SSCP anymore. |
| 112 | _, unknown = android.RemoveFromList("geotz", unknown) |
| 113 | |
| 114 | // For non test apexes, make sure that all contents are actually declared in make. |
| 115 | if global.ApexSystemServerJars.Len() > 0 && len(unknown) > 0 { |
| 116 | ctx.ModuleErrorf("%s in contents must also be declared in PRODUCT_UPDATABLE_SYSTEM_SERVER_JARS", unknown) |
| 117 | } |
| 118 | |
| 119 | return jars |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 120 | } |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 121 | |
| 122 | type systemServerClasspathFragmentContentDependencyTag struct { |
| 123 | blueprint.BaseDependencyTag |
| 124 | } |
| 125 | |
Paul Duffin | 25322e4 | 2021-09-07 14:52:48 +0100 | [diff] [blame^] | 126 | // The systemserverclasspath_fragment contents must never depend on prebuilts. |
| 127 | func (systemServerClasspathFragmentContentDependencyTag) ReplaceSourceWithPrebuilt() bool { |
| 128 | return false |
| 129 | } |
| 130 | |
Colin Cross | c33e521 | 2021-05-25 18:16:02 -0700 | [diff] [blame] | 131 | // Contents of system server fragments in an apex are considered to be directly in the apex, as if |
| 132 | // they were listed in java_libs. |
| 133 | func (systemServerClasspathFragmentContentDependencyTag) CopyDirectlyInAnyApex() {} |
| 134 | |
Paul Duffin | 25322e4 | 2021-09-07 14:52:48 +0100 | [diff] [blame^] | 135 | var _ android.ReplaceSourceWithPrebuilt = systemServerClasspathFragmentContentDepTag |
Colin Cross | c33e521 | 2021-05-25 18:16:02 -0700 | [diff] [blame] | 136 | var _ android.CopyDirectlyInAnyApexTag = systemServerClasspathFragmentContentDepTag |
| 137 | |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 138 | // The tag used for the dependency between the systemserverclasspath_fragment module and its contents. |
| 139 | var systemServerClasspathFragmentContentDepTag = systemServerClasspathFragmentContentDependencyTag{} |
| 140 | |
| 141 | func IsSystemServerClasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool { |
| 142 | return tag == systemServerClasspathFragmentContentDepTag |
| 143 | } |
| 144 | |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 145 | func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 146 | module := ctx.Module() |
| 147 | |
| 148 | for _, name := range s.properties.Contents { |
| 149 | ctx.AddDependency(module, systemServerClasspathFragmentContentDepTag, name) |
| 150 | } |
| 151 | } |
bralee | b0c1f0c | 2021-06-07 22:49:13 +0800 | [diff] [blame] | 152 | |
| 153 | // Collect information for opening IDE project files in java/jdeps.go. |
| 154 | func (s *SystemServerClasspathModule) IDEInfo(dpInfo *android.IdeInfo) { |
| 155 | dpInfo.Deps = append(dpInfo.Deps, s.properties.Contents...) |
| 156 | dpInfo.Paths = append(dpInfo.Paths, s.modulePaths...) |
| 157 | } |