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