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" |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 20 | "github.com/google/blueprint" |
satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 21 | ) |
| 22 | |
| 23 | func init() { |
| 24 | registerSystemserverClasspathBuildComponents(android.InitRegistrationContext) |
| 25 | } |
| 26 | |
| 27 | func registerSystemserverClasspathBuildComponents(ctx android.RegistrationContext) { |
satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 28 | ctx.RegisterModuleType("platform_systemserverclasspath", platformSystemServerClasspathFactory) |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 29 | ctx.RegisterModuleType("systemserverclasspath_fragment", systemServerClasspathFactory) |
satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | type platformSystemServerClasspathModule struct { |
| 33 | android.ModuleBase |
| 34 | |
| 35 | ClasspathFragmentBase |
| 36 | } |
| 37 | |
| 38 | func platformSystemServerClasspathFactory() android.Module { |
| 39 | m := &platformSystemServerClasspathModule{} |
| 40 | initClasspathFragment(m, SYSTEMSERVERCLASSPATH) |
| 41 | android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 42 | return m |
| 43 | } |
| 44 | |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 45 | func (p *platformSystemServerClasspathModule) AndroidMkEntries() (entries []android.AndroidMkEntries) { |
| 46 | return p.classpathFragmentBase().androidMkEntries() |
satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 47 | } |
| 48 | |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 49 | func (p *platformSystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 50 | configuredJars := configuredJarListToClasspathJars(ctx, p.ClasspathFragmentToConfiguredJarList(ctx), p.classpathType) |
| 51 | p.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars) |
satayev | 013485b | 2021-05-06 23:38:10 +0100 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | var platformSystemServerClasspathKey = android.NewOnceKey("platform_systemserverclasspath") |
| 55 | |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 56 | func (p *platformSystemServerClasspathModule) ClasspathFragmentToConfiguredJarList(ctx android.ModuleContext) android.ConfiguredJarList { |
satayev | 013485b | 2021-05-06 23:38:10 +0100 | [diff] [blame] | 57 | 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) |
satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 68 | } |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 69 | |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame^] | 70 | type SystemServerClasspathModule struct { |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 71 | android.ModuleBase |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame^] | 72 | android.ApexModuleBase |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 73 | |
| 74 | ClasspathFragmentBase |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 75 | |
| 76 | properties systemServerClasspathFragmentProperties |
| 77 | } |
| 78 | |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame^] | 79 | func (s *SystemServerClasspathModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { |
| 80 | return nil |
| 81 | } |
| 82 | |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 83 | type systemServerClasspathFragmentProperties struct { |
| 84 | // The contents of this systemserverclasspath_fragment, could be either java_library, or java_sdk_library. |
| 85 | // |
| 86 | // The order of this list matters as it is the order that is used in the SYSTEMSERVERCLASSPATH. |
| 87 | Contents []string |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | func systemServerClasspathFactory() android.Module { |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame^] | 91 | m := &SystemServerClasspathModule{} |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 92 | m.AddProperties(&m.properties) |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame^] | 93 | android.InitApexModule(m) |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 94 | initClasspathFragment(m, SYSTEMSERVERCLASSPATH) |
| 95 | android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 96 | return m |
| 97 | } |
| 98 | |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame^] | 99 | func (s *SystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 100 | if len(s.properties.Contents) == 0 { |
| 101 | ctx.PropertyErrorf("contents", "empty contents are not allowed") |
| 102 | } |
| 103 | |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 104 | s.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJarListToClasspathJars(ctx, s.ClasspathFragmentToConfiguredJarList(ctx))) |
| 105 | } |
| 106 | |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame^] | 107 | func (s *SystemServerClasspathModule) ClasspathFragmentToConfiguredJarList(ctx android.ModuleContext) android.ConfiguredJarList { |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 108 | // TODO(satayev): populate with actual content |
| 109 | return android.EmptyConfiguredJarList() |
| 110 | } |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 111 | |
| 112 | type systemServerClasspathFragmentContentDependencyTag struct { |
| 113 | blueprint.BaseDependencyTag |
| 114 | } |
| 115 | |
| 116 | // The tag used for the dependency between the systemserverclasspath_fragment module and its contents. |
| 117 | var systemServerClasspathFragmentContentDepTag = systemServerClasspathFragmentContentDependencyTag{} |
| 118 | |
| 119 | func IsSystemServerClasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool { |
| 120 | return tag == systemServerClasspathFragmentContentDepTag |
| 121 | } |
| 122 | |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame^] | 123 | func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 124 | module := ctx.Module() |
| 125 | |
| 126 | for _, name := range s.properties.Contents { |
| 127 | ctx.AddDependency(module, systemServerClasspathFragmentContentDepTag, name) |
| 128 | } |
| 129 | } |