Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 1 | // Copyright (C) 2021 The Android Open Source Project |
| 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 | "strings" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | "github.com/google/blueprint" |
| 22 | ) |
| 23 | |
| 24 | func init() { |
| 25 | RegisterBootImageBuildComponents(android.InitRegistrationContext) |
| 26 | } |
| 27 | |
| 28 | func RegisterBootImageBuildComponents(ctx android.RegistrationContext) { |
| 29 | ctx.RegisterModuleType("boot_image", bootImageFactory) |
| 30 | } |
| 31 | |
| 32 | type bootImageProperties struct { |
| 33 | // The name of the image this represents. |
| 34 | // |
| 35 | // Must be one of "art" or "boot". |
| 36 | Image_name string |
| 37 | } |
| 38 | |
| 39 | type BootImageModule struct { |
| 40 | android.ModuleBase |
| 41 | |
| 42 | properties bootImageProperties |
| 43 | } |
| 44 | |
| 45 | func bootImageFactory() android.Module { |
| 46 | m := &BootImageModule{} |
| 47 | m.AddProperties(&m.properties) |
| 48 | android.InitAndroidArchModule(m, android.HostAndDeviceDefault, android.MultilibCommon) |
| 49 | return m |
| 50 | } |
| 51 | |
| 52 | var BootImageInfoProvider = blueprint.NewProvider(BootImageInfo{}) |
| 53 | |
| 54 | type BootImageInfo struct { |
| 55 | // The image config, internal to this module (and the dex_bootjars singleton). |
| 56 | imageConfig *bootImageConfig |
| 57 | } |
| 58 | |
| 59 | func (i BootImageInfo) Modules() android.ConfiguredJarList { |
| 60 | return i.imageConfig.modules |
| 61 | } |
| 62 | |
| 63 | func (b *BootImageModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 64 | // Nothing to do if skipping the dexpreopt of boot image jars. |
| 65 | if SkipDexpreoptBootJars(ctx) { |
| 66 | return |
| 67 | } |
| 68 | |
| 69 | // Get a map of the image configs that are supported. |
| 70 | imageConfigs := genBootImageConfigs(ctx) |
| 71 | |
| 72 | // Retrieve the config for this image. |
| 73 | imageName := b.properties.Image_name |
| 74 | imageConfig := imageConfigs[imageName] |
| 75 | if imageConfig == nil { |
| 76 | ctx.PropertyErrorf("image_name", "Unknown image name %q, expected one of %s", imageName, strings.Join(android.SortedStringKeys(imageConfigs), ", ")) |
| 77 | return |
| 78 | } |
| 79 | |
| 80 | // Construct the boot image info from the config. |
| 81 | info := BootImageInfo{imageConfig: imageConfig} |
| 82 | |
| 83 | // Make it available for other modules. |
| 84 | ctx.SetProvider(BootImageInfoProvider, info) |
| 85 | } |