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 ( |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 18 | "fmt" |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 19 | "path/filepath" |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 20 | "strings" |
| 21 | |
| 22 | "android/soong/android" |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 23 | "android/soong/dexpreopt" |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 24 | "github.com/google/blueprint/proptools" |
Martin Stjernholm | b79c7f1 | 2021-03-17 00:26:25 +0000 | [diff] [blame] | 25 | |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 26 | "github.com/google/blueprint" |
| 27 | ) |
| 28 | |
| 29 | func init() { |
| 30 | RegisterBootImageBuildComponents(android.InitRegistrationContext) |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 31 | |
Paul Duffin | 4b64ba0 | 2021-03-29 11:02:53 +0100 | [diff] [blame] | 32 | // TODO(b/177892522): Remove after has been replaced by bootclasspath_fragments |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 33 | android.RegisterSdkMemberType(&bootImageMemberType{ |
| 34 | SdkMemberTypeBase: android.SdkMemberTypeBase{ |
| 35 | PropertyName: "boot_images", |
| 36 | SupportsSdk: true, |
| 37 | }, |
| 38 | }) |
Paul Duffin | 4b64ba0 | 2021-03-29 11:02:53 +0100 | [diff] [blame] | 39 | |
| 40 | android.RegisterSdkMemberType(&bootImageMemberType{ |
| 41 | SdkMemberTypeBase: android.SdkMemberTypeBase{ |
| 42 | PropertyName: "bootclasspath_fragments", |
| 43 | SupportsSdk: true, |
| 44 | }, |
| 45 | }) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | func RegisterBootImageBuildComponents(ctx android.RegistrationContext) { |
Paul Duffin | 4b64ba0 | 2021-03-29 11:02:53 +0100 | [diff] [blame] | 49 | // TODO(b/177892522): Remove after has been replaced by bootclasspath_fragment |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 50 | ctx.RegisterModuleType("boot_image", bootImageFactory) |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 51 | ctx.RegisterModuleType("prebuilt_boot_image", prebuiltBootImageFactory) |
Paul Duffin | 4b64ba0 | 2021-03-29 11:02:53 +0100 | [diff] [blame] | 52 | |
| 53 | ctx.RegisterModuleType("bootclasspath_fragment", bootImageFactory) |
| 54 | ctx.RegisterModuleType("prebuilt_bootclasspath_fragment", prebuiltBootImageFactory) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 57 | type bootclasspathFragmentContentDependencyTag struct { |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 58 | blueprint.BaseDependencyTag |
| 59 | } |
| 60 | |
| 61 | // Avoid having to make boot image content visible to the boot image. |
| 62 | // |
| 63 | // This is a temporary workaround to make it easier to migrate to boot image modules with proper |
| 64 | // dependencies. |
| 65 | // TODO(b/177892522): Remove this and add needed visibility. |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 66 | func (b bootclasspathFragmentContentDependencyTag) ExcludeFromVisibilityEnforcement() { |
| 67 | } |
| 68 | |
| 69 | // The bootclasspath_fragment contents must never depend on prebuilts. |
| 70 | func (b bootclasspathFragmentContentDependencyTag) ReplaceSourceWithPrebuilt() bool { |
| 71 | return false |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | // The tag used for the dependency between the boot image module and its contents. |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 75 | var bootclasspathFragmentContentDepTag = bootclasspathFragmentContentDependencyTag{} |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 76 | |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 77 | var _ android.ExcludeFromVisibilityEnforcementTag = bootclasspathFragmentContentDepTag |
| 78 | var _ android.ReplaceSourceWithPrebuilt = bootclasspathFragmentContentDepTag |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 79 | |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 80 | func IsBootclasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool { |
| 81 | return tag == bootclasspathFragmentContentDepTag |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 84 | type bootImageProperties struct { |
| 85 | // The name of the image this represents. |
| 86 | // |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 87 | // If specified then it must be one of "art" or "boot". |
Paul Duffin | 64be7bb | 2021-03-23 23:06:38 +0000 | [diff] [blame] | 88 | Image_name *string |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 89 | |
| 90 | // The contents of this boot image, could be either java_library, java_sdk_library, or boot_image. |
| 91 | // |
| 92 | // The order of this list matters as it is the order that is used in the bootclasspath. |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 93 | Contents []string |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 94 | |
| 95 | Hidden_api HiddenAPIFlagFileProperties |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | type BootImageModule struct { |
| 99 | android.ModuleBase |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 100 | android.ApexModuleBase |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 101 | android.SdkBase |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 102 | properties bootImageProperties |
| 103 | } |
| 104 | |
| 105 | func bootImageFactory() android.Module { |
| 106 | m := &BootImageModule{} |
| 107 | m.AddProperties(&m.properties) |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 108 | android.InitApexModule(m) |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 109 | android.InitSdkAwareModule(m) |
Martin Stjernholm | b79c7f1 | 2021-03-17 00:26:25 +0000 | [diff] [blame] | 110 | android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon) |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 111 | |
| 112 | // Perform some consistency checking to ensure that the configuration is correct. |
| 113 | android.AddLoadHook(m, func(ctx android.LoadHookContext) { |
| 114 | bootImageConsistencyCheck(ctx, m) |
| 115 | }) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 116 | return m |
| 117 | } |
| 118 | |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 119 | func bootImageConsistencyCheck(ctx android.EarlyModuleContext, m *BootImageModule) { |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 120 | contents := m.properties.Contents |
| 121 | if m.properties.Image_name == nil && len(contents) == 0 { |
| 122 | ctx.ModuleErrorf(`neither of the "image_name" and "contents" properties have been supplied, please supply exactly one`) |
| 123 | } |
| 124 | if m.properties.Image_name != nil && len(contents) != 0 { |
| 125 | ctx.ModuleErrorf(`both of the "image_name" and "contents" properties have been supplied, please supply exactly one`) |
| 126 | } |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame^] | 127 | |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 128 | imageName := proptools.String(m.properties.Image_name) |
| 129 | if imageName == "art" { |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame^] | 130 | // TODO(b/177892522): Prebuilts (versioned or not) should not use the image_name property. |
| 131 | if m.MemberName() != "" { |
| 132 | // The module is a versioned prebuilt so ignore it. This is done for a couple of reasons: |
| 133 | // 1. There is no way to use this at the moment so ignoring it is safe. |
| 134 | // 2. Attempting to initialize the contents property from the configuration will end up having |
| 135 | // the versioned prebuilt depending on the unversioned prebuilt. That will cause problems |
| 136 | // as the unversioned prebuilt could end up with an APEX variant created for the source |
| 137 | // APEX which will prevent it from having an APEX variant for the prebuilt APEX which in |
| 138 | // turn will prevent it from accessing the dex implementation jar from that which will |
| 139 | // break hidden API processing, amongst others. |
| 140 | return |
| 141 | } |
| 142 | |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 143 | // Get the configuration for the art apex jars. Do not use getImageConfig(ctx) here as this is |
| 144 | // too early in the Soong processing for that to work. |
| 145 | global := dexpreopt.GetGlobalConfig(ctx) |
| 146 | modules := global.ArtApexJars |
| 147 | |
| 148 | // Make sure that the apex specified in the configuration is consistent and is one for which |
| 149 | // this boot image is available. |
| 150 | jars := []string{} |
| 151 | commonApex := "" |
| 152 | for i := 0; i < modules.Len(); i++ { |
| 153 | apex := modules.Apex(i) |
| 154 | jar := modules.Jar(i) |
| 155 | if apex == "platform" { |
| 156 | ctx.ModuleErrorf("ArtApexJars is invalid as it requests a platform variant of %q", jar) |
| 157 | continue |
| 158 | } |
| 159 | if !m.AvailableFor(apex) { |
| 160 | ctx.ModuleErrorf("incompatible with ArtApexJars which expects this to be in apex %q but this is only in apexes %q", |
| 161 | apex, m.ApexAvailable()) |
| 162 | continue |
| 163 | } |
| 164 | if commonApex == "" { |
| 165 | commonApex = apex |
| 166 | } else if commonApex != apex { |
| 167 | ctx.ModuleErrorf("ArtApexJars configuration is inconsistent, expected all jars to be in the same apex but it specifies apex %q and %q", |
| 168 | commonApex, apex) |
| 169 | } |
| 170 | jars = append(jars, jar) |
| 171 | } |
| 172 | |
| 173 | // Store the jars in the Contents property so that they can be used to add dependencies. |
| 174 | m.properties.Contents = jars |
| 175 | } |
| 176 | } |
| 177 | |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 178 | var BootImageInfoProvider = blueprint.NewProvider(BootImageInfo{}) |
| 179 | |
| 180 | type BootImageInfo struct { |
| 181 | // The image config, internal to this module (and the dex_bootjars singleton). |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 182 | // |
| 183 | // Will be nil if the BootImageInfo has not been provided for a specific module. That can occur |
| 184 | // when SkipDexpreoptBootJars(ctx) returns true. |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 185 | imageConfig *bootImageConfig |
| 186 | } |
| 187 | |
| 188 | func (i BootImageInfo) Modules() android.ConfiguredJarList { |
| 189 | return i.imageConfig.modules |
| 190 | } |
| 191 | |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 192 | // Get a map from ArchType to the associated boot image's contents for Android. |
| 193 | // |
| 194 | // Extension boot images only return their own files, not the files of the boot images they extend. |
| 195 | func (i BootImageInfo) AndroidBootImageFilesByArchType() map[android.ArchType]android.OutputPaths { |
| 196 | files := map[android.ArchType]android.OutputPaths{} |
| 197 | if i.imageConfig != nil { |
| 198 | for _, variant := range i.imageConfig.variants { |
| 199 | // We also generate boot images for host (for testing), but we don't need those in the apex. |
| 200 | // TODO(b/177892522) - consider changing this to check Os.OsClass = android.Device |
| 201 | if variant.target.Os == android.Android { |
| 202 | files[variant.target.Arch.ArchType] = variant.imagesDeps |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | return files |
| 207 | } |
| 208 | |
| 209 | func (b *BootImageModule) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
| 210 | tag := ctx.OtherModuleDependencyTag(dep) |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 211 | if IsBootclasspathFragmentContentDepTag(tag) { |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 212 | // Boot image contents are automatically added to apex. |
| 213 | return true |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 214 | } |
Bob Badour | 07065cd | 2021-02-05 19:59:11 -0800 | [diff] [blame] | 215 | if android.IsMetaDependencyTag(tag) { |
| 216 | // Cross-cutting metadata dependencies are metadata. |
| 217 | return false |
| 218 | } |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 219 | panic(fmt.Errorf("boot_image module %q should not have a dependency on %q via tag %s", b, dep, android.PrettyPrintTag(tag))) |
| 220 | } |
| 221 | |
| 222 | func (b *BootImageModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { |
| 223 | return nil |
| 224 | } |
| 225 | |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 226 | // ComponentDepsMutator adds dependencies onto modules before any prebuilt modules without a |
| 227 | // corresponding source module are renamed. This means that adding a dependency using a name without |
| 228 | // a prebuilt_ prefix will always resolve to a source module and when using a name with that prefix |
| 229 | // it will always resolve to a prebuilt module. |
| 230 | func (b *BootImageModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { |
| 231 | module := ctx.Module() |
| 232 | _, isSourceModule := module.(*BootImageModule) |
| 233 | |
| 234 | for _, name := range b.properties.Contents { |
| 235 | // A bootclasspath_fragment must depend only on other source modules, while the |
| 236 | // prebuilt_bootclasspath_fragment must only depend on other prebuilt modules. |
Paul Duffin | a9dd6fa | 2021-04-22 17:25:57 +0100 | [diff] [blame] | 237 | // |
| 238 | // TODO(b/177892522) - avoid special handling of jacocoagent. |
| 239 | if !isSourceModule && name != "jacocoagent" { |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 240 | name = android.PrebuiltNameFromSource(name) |
| 241 | } |
| 242 | ctx.AddDependency(module, bootclasspathFragmentContentDepTag, name) |
| 243 | } |
| 244 | |
| 245 | } |
| 246 | |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 247 | func (b *BootImageModule) DepsMutator(ctx android.BottomUpMutatorContext) { |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 248 | |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 249 | if SkipDexpreoptBootJars(ctx) { |
| 250 | return |
| 251 | } |
| 252 | |
| 253 | // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The |
| 254 | // path is retrieved from the dependency by GetGlobalSoongConfig(ctx). |
| 255 | dexpreopt.RegisterToolDeps(ctx) |
| 256 | } |
| 257 | |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 258 | func (b *BootImageModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 259 | // Perform hidden API processing. |
| 260 | b.generateHiddenAPIBuildActions(ctx) |
| 261 | |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 262 | // Nothing to do if skipping the dexpreopt of boot image jars. |
| 263 | if SkipDexpreoptBootJars(ctx) { |
| 264 | return |
| 265 | } |
| 266 | |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 267 | // Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars |
| 268 | // GenerateSingletonBuildActions method as it cannot create it for itself. |
| 269 | dexpreopt.GetGlobalSoongConfig(ctx) |
| 270 | |
Paul Duffin | 64be7bb | 2021-03-23 23:06:38 +0000 | [diff] [blame] | 271 | imageConfig := b.getImageConfig(ctx) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 272 | if imageConfig == nil { |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 273 | return |
| 274 | } |
| 275 | |
| 276 | // Construct the boot image info from the config. |
| 277 | info := BootImageInfo{imageConfig: imageConfig} |
| 278 | |
| 279 | // Make it available for other modules. |
| 280 | ctx.SetProvider(BootImageInfoProvider, info) |
| 281 | } |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 282 | |
Paul Duffin | 64be7bb | 2021-03-23 23:06:38 +0000 | [diff] [blame] | 283 | func (b *BootImageModule) getImageConfig(ctx android.EarlyModuleContext) *bootImageConfig { |
| 284 | // Get a map of the image configs that are supported. |
| 285 | imageConfigs := genBootImageConfigs(ctx) |
| 286 | |
| 287 | // Retrieve the config for this image. |
| 288 | imageNamePtr := b.properties.Image_name |
| 289 | if imageNamePtr == nil { |
| 290 | return nil |
| 291 | } |
| 292 | |
| 293 | imageName := *imageNamePtr |
| 294 | imageConfig := imageConfigs[imageName] |
| 295 | if imageConfig == nil { |
| 296 | ctx.PropertyErrorf("image_name", "Unknown image name %q, expected one of %s", imageName, strings.Join(android.SortedStringKeys(imageConfigs), ", ")) |
| 297 | return nil |
| 298 | } |
| 299 | return imageConfig |
| 300 | } |
| 301 | |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 302 | // generateHiddenAPIBuildActions generates all the hidden API related build rules. |
| 303 | func (b *BootImageModule) generateHiddenAPIBuildActions(ctx android.ModuleContext) { |
| 304 | // Resolve the properties to paths. |
| 305 | flagFileInfo := b.properties.Hidden_api.hiddenAPIFlagFileInfo(ctx) |
| 306 | |
| 307 | // Store the information for use by platform_bootclasspath. |
| 308 | ctx.SetProvider(hiddenAPIFlagFileInfoProvider, flagFileInfo) |
| 309 | } |
| 310 | |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 311 | type bootImageMemberType struct { |
| 312 | android.SdkMemberTypeBase |
| 313 | } |
| 314 | |
| 315 | func (b *bootImageMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { |
| 316 | mctx.AddVariationDependencies(nil, dependencyTag, names...) |
| 317 | } |
| 318 | |
| 319 | func (b *bootImageMemberType) IsInstance(module android.Module) bool { |
| 320 | _, ok := module.(*BootImageModule) |
| 321 | return ok |
| 322 | } |
| 323 | |
| 324 | func (b *bootImageMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { |
Paul Duffin | 4b64ba0 | 2021-03-29 11:02:53 +0100 | [diff] [blame] | 325 | if b.PropertyName == "boot_images" { |
| 326 | return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_boot_image") |
| 327 | } else { |
| 328 | return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_bootclasspath_fragment") |
| 329 | } |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | func (b *bootImageMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { |
| 333 | return &bootImageSdkMemberProperties{} |
| 334 | } |
| 335 | |
| 336 | type bootImageSdkMemberProperties struct { |
| 337 | android.SdkMemberPropertiesBase |
| 338 | |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 339 | // The image name |
Paul Duffin | 64be7bb | 2021-03-23 23:06:38 +0000 | [diff] [blame] | 340 | Image_name *string |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 341 | |
| 342 | // Contents of the bootclasspath fragment |
| 343 | Contents []string |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 344 | |
| 345 | // Flag files by *hiddenAPIFlagFileCategory |
| 346 | Flag_files_by_category map[*hiddenAPIFlagFileCategory]android.Paths |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | func (b *bootImageSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { |
| 350 | module := variant.(*BootImageModule) |
| 351 | |
| 352 | b.Image_name = module.properties.Image_name |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 353 | if b.Image_name == nil { |
| 354 | // Only one of image_name or contents can be specified. However, if image_name is set then the |
| 355 | // contents property is updated to match the configuration used to create the corresponding |
| 356 | // boot image. Therefore, contents property is only copied if the image name is not specified. |
| 357 | b.Contents = module.properties.Contents |
| 358 | } |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 359 | |
| 360 | // Get the flag file information from the module. |
| 361 | mctx := ctx.SdkModuleContext() |
| 362 | flagFileInfo := mctx.OtherModuleProvider(module, hiddenAPIFlagFileInfoProvider).(hiddenAPIFlagFileInfo) |
| 363 | b.Flag_files_by_category = flagFileInfo.categoryToPaths |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | func (b *bootImageSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { |
Paul Duffin | 64be7bb | 2021-03-23 23:06:38 +0000 | [diff] [blame] | 367 | if b.Image_name != nil { |
| 368 | propertySet.AddProperty("image_name", *b.Image_name) |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 369 | } |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 370 | |
| 371 | if len(b.Contents) > 0 { |
| 372 | propertySet.AddPropertyWithTag("contents", b.Contents, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(true)) |
| 373 | } |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 374 | |
| 375 | builder := ctx.SnapshotBuilder() |
| 376 | if b.Flag_files_by_category != nil { |
| 377 | hiddenAPISet := propertySet.AddPropertySet("hidden_api") |
| 378 | for _, category := range hiddenAPIFlagFileCategories { |
| 379 | paths := b.Flag_files_by_category[category] |
| 380 | if len(paths) > 0 { |
| 381 | dests := []string{} |
| 382 | for _, p := range paths { |
| 383 | dest := filepath.Join("hiddenapi", p.Base()) |
| 384 | builder.CopyToSnapshot(p, dest) |
| 385 | dests = append(dests, dest) |
| 386 | } |
| 387 | hiddenAPISet.AddProperty(category.propertyName, dests) |
| 388 | } |
| 389 | } |
| 390 | } |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | var _ android.SdkMemberType = (*bootImageMemberType)(nil) |
| 394 | |
| 395 | // A prebuilt version of the boot image module. |
| 396 | // |
| 397 | // At the moment this is basically just a boot image module that can be used as a prebuilt. |
| 398 | // Eventually as more functionality is migrated into the boot image module from the singleton then |
| 399 | // this will diverge. |
| 400 | type prebuiltBootImageModule struct { |
| 401 | BootImageModule |
| 402 | prebuilt android.Prebuilt |
| 403 | } |
| 404 | |
| 405 | func (module *prebuiltBootImageModule) Prebuilt() *android.Prebuilt { |
| 406 | return &module.prebuilt |
| 407 | } |
| 408 | |
| 409 | func (module *prebuiltBootImageModule) Name() string { |
| 410 | return module.prebuilt.Name(module.ModuleBase.Name()) |
| 411 | } |
| 412 | |
| 413 | func prebuiltBootImageFactory() android.Module { |
| 414 | m := &prebuiltBootImageModule{} |
| 415 | m.AddProperties(&m.properties) |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 416 | // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs |
| 417 | // array. |
| 418 | android.InitPrebuiltModule(m, &[]string{"placeholder"}) |
| 419 | android.InitApexModule(m) |
| 420 | android.InitSdkAwareModule(m) |
Martin Stjernholm | b79c7f1 | 2021-03-17 00:26:25 +0000 | [diff] [blame] | 421 | android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon) |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 422 | |
| 423 | // Perform some consistency checking to ensure that the configuration is correct. |
| 424 | android.AddLoadHook(m, func(ctx android.LoadHookContext) { |
| 425 | bootImageConsistencyCheck(ctx, &m.BootImageModule) |
| 426 | }) |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 427 | return m |
| 428 | } |