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