Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +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" |
| 19 | "android/soong/dexpreopt" |
| 20 | ) |
| 21 | |
| 22 | func init() { |
| 23 | registerPlatformBootclasspathBuildComponents(android.InitRegistrationContext) |
| 24 | } |
| 25 | |
| 26 | func registerPlatformBootclasspathBuildComponents(ctx android.RegistrationContext) { |
| 27 | ctx.RegisterModuleType("platform_bootclasspath", platformBootclasspathFactory) |
| 28 | } |
| 29 | |
| 30 | type platformBootclasspathModule struct { |
| 31 | android.ModuleBase |
| 32 | } |
| 33 | |
| 34 | func platformBootclasspathFactory() android.Module { |
| 35 | m := &platformBootclasspathModule{} |
| 36 | android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 37 | return m |
| 38 | } |
| 39 | |
| 40 | func (b *platformBootclasspathModule) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 41 | if SkipDexpreoptBootJars(ctx) { |
| 42 | return |
| 43 | } |
| 44 | |
| 45 | // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The |
| 46 | // path is retrieved from the dependency by GetGlobalSoongConfig(ctx). |
| 47 | dexpreopt.RegisterToolDeps(ctx) |
| 48 | } |
| 49 | |
| 50 | func (b *platformBootclasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 51 | // Nothing to do if skipping the dexpreopt of boot image jars. |
| 52 | if SkipDexpreoptBootJars(ctx) { |
| 53 | return |
| 54 | } |
| 55 | |
| 56 | // Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars |
| 57 | // GenerateSingletonBuildActions method as it cannot create it for itself. |
| 58 | dexpreopt.GetGlobalSoongConfig(ctx) |
| 59 | |
| 60 | imageConfig := b.getImageConfig(ctx) |
| 61 | if imageConfig == nil { |
| 62 | return |
| 63 | } |
| 64 | |
| 65 | // Construct the boot image info from the config. |
| 66 | info := BootImageInfo{imageConfig: imageConfig} |
| 67 | |
| 68 | // Make it available for other modules. |
| 69 | ctx.SetProvider(BootImageInfoProvider, info) |
| 70 | } |
| 71 | |
| 72 | func (b *platformBootclasspathModule) getImageConfig(ctx android.EarlyModuleContext) *bootImageConfig { |
| 73 | return defaultBootImageConfig(ctx) |
| 74 | } |