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 | 2d3da31 | 2021-05-06 12:02:27 +0100 | [diff] [blame] | 35 | PropertyName: "bootclasspath_fragments", |
| 36 | SupportsSdk: true, |
Paul Duffin | 4b64ba0 | 2021-03-29 11:02:53 +0100 | [diff] [blame] | 37 | }, |
| 38 | }) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 41 | func registerBootclasspathFragmentBuildComponents(ctx android.RegistrationContext) { |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 42 | ctx.RegisterModuleType("bootclasspath_fragment", bootclasspathFragmentFactory) |
| 43 | ctx.RegisterModuleType("prebuilt_bootclasspath_fragment", prebuiltBootclasspathFragmentFactory) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 46 | type bootclasspathFragmentContentDependencyTag struct { |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 47 | blueprint.BaseDependencyTag |
| 48 | } |
| 49 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 50 | // Avoid having to make bootclasspath_fragment content visible to the bootclasspath_fragment. |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 51 | // |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 52 | // This is a temporary workaround to make it easier to migrate to bootclasspath_fragment modules |
| 53 | // with proper dependencies. |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 54 | // TODO(b/177892522): Remove this and add needed visibility. |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 55 | func (b bootclasspathFragmentContentDependencyTag) ExcludeFromVisibilityEnforcement() { |
| 56 | } |
| 57 | |
| 58 | // The bootclasspath_fragment contents must never depend on prebuilts. |
| 59 | func (b bootclasspathFragmentContentDependencyTag) ReplaceSourceWithPrebuilt() bool { |
| 60 | return false |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Paul Duffin | e95b53a | 2021-04-23 20:41:23 +0100 | [diff] [blame] | 63 | // SdkMemberType causes dependencies added with this tag to be automatically added to the sdk as if |
Paul Duffin | a10bd3c | 2021-05-12 13:46:54 +0100 | [diff] [blame] | 64 | // they were specified using java_boot_libs or java_sdk_libs. |
| 65 | func (b bootclasspathFragmentContentDependencyTag) SdkMemberType(child android.Module) android.SdkMemberType { |
| 66 | // If the module is a java_sdk_library then treat it as if it was specified in the java_sdk_libs |
| 67 | // property, otherwise treat if it was specified in the java_boot_libs property. |
| 68 | if javaSdkLibrarySdkMemberType.IsInstance(child) { |
| 69 | return javaSdkLibrarySdkMemberType |
| 70 | } |
| 71 | |
Paul Duffin | e95b53a | 2021-04-23 20:41:23 +0100 | [diff] [blame] | 72 | return javaBootLibsSdkMemberType |
| 73 | } |
| 74 | |
| 75 | func (b bootclasspathFragmentContentDependencyTag) ExportMember() bool { |
| 76 | return true |
| 77 | } |
| 78 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 79 | // 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] | 80 | var bootclasspathFragmentContentDepTag = bootclasspathFragmentContentDependencyTag{} |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 81 | |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 82 | var _ android.ExcludeFromVisibilityEnforcementTag = bootclasspathFragmentContentDepTag |
| 83 | var _ android.ReplaceSourceWithPrebuilt = bootclasspathFragmentContentDepTag |
Paul Duffin | e95b53a | 2021-04-23 20:41:23 +0100 | [diff] [blame] | 84 | var _ android.SdkMemberTypeDependencyTag = bootclasspathFragmentContentDepTag |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 85 | |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 86 | func IsBootclasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool { |
| 87 | return tag == bootclasspathFragmentContentDepTag |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Paul Duffin | c7d1644 | 2021-04-23 13:55:49 +0100 | [diff] [blame] | 90 | // Properties that can be different when coverage is enabled. |
| 91 | type BootclasspathFragmentCoverageAffectedProperties struct { |
| 92 | // The contents of this bootclasspath_fragment, could be either java_library, or java_sdk_library. |
| 93 | // |
Paul Duffin | 34827d4 | 2021-05-13 21:25:05 +0100 | [diff] [blame] | 94 | // A java_sdk_library specified here will also be treated as if it was specified on the stub_libs |
| 95 | // property. |
| 96 | // |
Paul Duffin | c7d1644 | 2021-04-23 13:55:49 +0100 | [diff] [blame] | 97 | // The order of this list matters as it is the order that is used in the bootclasspath. |
| 98 | Contents []string |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 99 | |
| 100 | // The properties for specifying the API stubs provided by this fragment. |
| 101 | BootclasspathAPIProperties |
Paul Duffin | c7d1644 | 2021-04-23 13:55:49 +0100 | [diff] [blame] | 102 | } |
| 103 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 104 | type bootclasspathFragmentProperties struct { |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 105 | // The name of the image this represents. |
| 106 | // |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 107 | // If specified then it must be one of "art" or "boot". |
Paul Duffin | 64be7bb | 2021-03-23 23:06:38 +0000 | [diff] [blame] | 108 | Image_name *string |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 109 | |
Paul Duffin | c7d1644 | 2021-04-23 13:55:49 +0100 | [diff] [blame] | 110 | // Properties whose values need to differ with and without coverage. |
| 111 | BootclasspathFragmentCoverageAffectedProperties |
| 112 | Coverage BootclasspathFragmentCoverageAffectedProperties |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 113 | |
| 114 | Hidden_api HiddenAPIFlagFileProperties |
Paul Duffin | 70cfdff | 2021-05-15 09:10:42 +0100 | [diff] [blame^] | 115 | |
| 116 | // Properties that allow a fragment to depend on other fragments. This is needed for hidden API |
| 117 | // processing as it needs access to all the classes used by a fragment including those provided |
| 118 | // by other fragments. |
| 119 | BootclasspathFragmentsDepsProperties |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 122 | type BootclasspathFragmentModule struct { |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 123 | android.ModuleBase |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 124 | android.ApexModuleBase |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 125 | android.SdkBase |
satayev | 3db3547 | 2021-05-06 23:59:58 +0100 | [diff] [blame] | 126 | ClasspathFragmentBase |
| 127 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 128 | properties bootclasspathFragmentProperties |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 131 | // commonBootclasspathFragment defines the methods that are implemented by both source and prebuilt |
| 132 | // bootclasspath fragment modules. |
| 133 | type commonBootclasspathFragment interface { |
| 134 | // produceHiddenAPIAllFlagsFile produces the all-flags.csv and intermediate files. |
| 135 | // |
| 136 | // Updates the supplied flagFileInfo with the paths to the generated files set. |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 137 | produceHiddenAPIAllFlagsFile(ctx android.ModuleContext, contents []hiddenAPIModule, stubJarsByKind map[android.SdkKind]android.Paths, flagFileInfo *hiddenAPIFlagFileInfo) |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 138 | } |
| 139 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 140 | func bootclasspathFragmentFactory() android.Module { |
| 141 | m := &BootclasspathFragmentModule{} |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 142 | m.AddProperties(&m.properties) |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 143 | android.InitApexModule(m) |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 144 | android.InitSdkAwareModule(m) |
satayev | 3db3547 | 2021-05-06 23:59:58 +0100 | [diff] [blame] | 145 | initClasspathFragment(m, BOOTCLASSPATH) |
Martin Stjernholm | b79c7f1 | 2021-03-17 00:26:25 +0000 | [diff] [blame] | 146 | android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon) |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 147 | |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 148 | android.AddLoadHook(m, func(ctx android.LoadHookContext) { |
Paul Duffin | c7d1644 | 2021-04-23 13:55:49 +0100 | [diff] [blame] | 149 | // If code coverage has been enabled for the framework then append the properties with |
| 150 | // coverage specific properties. |
| 151 | if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") { |
| 152 | err := proptools.AppendProperties(&m.properties.BootclasspathFragmentCoverageAffectedProperties, &m.properties.Coverage, nil) |
| 153 | if err != nil { |
| 154 | ctx.PropertyErrorf("coverage", "error trying to append coverage specific properties: %s", err) |
| 155 | return |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | // Initialize the contents property from the image_name. |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 160 | bootclasspathFragmentInitContentsFromImage(ctx, m) |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 161 | }) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 162 | return m |
| 163 | } |
| 164 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 165 | // bootclasspathFragmentInitContentsFromImage will initialize the contents property from the image_name if |
| 166 | // necessary. |
| 167 | func bootclasspathFragmentInitContentsFromImage(ctx android.EarlyModuleContext, m *BootclasspathFragmentModule) { |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 168 | contents := m.properties.Contents |
| 169 | if m.properties.Image_name == nil && len(contents) == 0 { |
| 170 | ctx.ModuleErrorf(`neither of the "image_name" and "contents" properties have been supplied, please supply exactly one`) |
| 171 | } |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 172 | |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 173 | imageName := proptools.String(m.properties.Image_name) |
| 174 | if imageName == "art" { |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 175 | // TODO(b/177892522): Prebuilts (versioned or not) should not use the image_name property. |
Paul Duffin | 0c2e083 | 2021-04-28 00:39:52 +0100 | [diff] [blame] | 176 | if android.IsModuleInVersionedSdk(m) { |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 177 | // The module is a versioned prebuilt so ignore it. This is done for a couple of reasons: |
| 178 | // 1. There is no way to use this at the moment so ignoring it is safe. |
| 179 | // 2. Attempting to initialize the contents property from the configuration will end up having |
| 180 | // the versioned prebuilt depending on the unversioned prebuilt. That will cause problems |
| 181 | // as the unversioned prebuilt could end up with an APEX variant created for the source |
| 182 | // APEX which will prevent it from having an APEX variant for the prebuilt APEX which in |
| 183 | // turn will prevent it from accessing the dex implementation jar from that which will |
| 184 | // break hidden API processing, amongst others. |
| 185 | return |
| 186 | } |
| 187 | |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 188 | // Get the configuration for the art apex jars. Do not use getImageConfig(ctx) here as this is |
| 189 | // too early in the Soong processing for that to work. |
| 190 | global := dexpreopt.GetGlobalConfig(ctx) |
| 191 | modules := global.ArtApexJars |
| 192 | |
| 193 | // Make sure that the apex specified in the configuration is consistent and is one for which |
| 194 | // this boot image is available. |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 195 | commonApex := "" |
| 196 | for i := 0; i < modules.Len(); i++ { |
| 197 | apex := modules.Apex(i) |
| 198 | jar := modules.Jar(i) |
| 199 | if apex == "platform" { |
| 200 | ctx.ModuleErrorf("ArtApexJars is invalid as it requests a platform variant of %q", jar) |
| 201 | continue |
| 202 | } |
| 203 | if !m.AvailableFor(apex) { |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 204 | ctx.ModuleErrorf("ArtApexJars configuration incompatible with this module, ArtApexJars expects this to be in apex %q but this is only in apexes %q", |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 205 | apex, m.ApexAvailable()) |
| 206 | continue |
| 207 | } |
| 208 | if commonApex == "" { |
| 209 | commonApex = apex |
| 210 | } else if commonApex != apex { |
| 211 | ctx.ModuleErrorf("ArtApexJars configuration is inconsistent, expected all jars to be in the same apex but it specifies apex %q and %q", |
| 212 | commonApex, apex) |
| 213 | } |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 216 | if len(contents) != 0 { |
| 217 | // Nothing to do. |
| 218 | return |
| 219 | } |
| 220 | |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 221 | // 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] | 222 | m.properties.Contents = modules.CopyOfJars() |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | // bootclasspathImageNameContentsConsistencyCheck checks that the configuration that applies to this |
| 227 | // module (if any) matches the contents. |
| 228 | // |
| 229 | // This should be a noop as if image_name="art" then the contents will be set from the ArtApexJars |
| 230 | // config by bootclasspathFragmentInitContentsFromImage so it will be guaranteed to match. However, |
| 231 | // in future this will not be the case. |
| 232 | func (b *BootclasspathFragmentModule) bootclasspathImageNameContentsConsistencyCheck(ctx android.BaseModuleContext) { |
| 233 | imageName := proptools.String(b.properties.Image_name) |
| 234 | if imageName == "art" { |
| 235 | // TODO(b/177892522): Prebuilts (versioned or not) should not use the image_name property. |
Paul Duffin | 0c2e083 | 2021-04-28 00:39:52 +0100 | [diff] [blame] | 236 | if android.IsModuleInVersionedSdk(b) { |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 237 | // The module is a versioned prebuilt so ignore it. This is done for a couple of reasons: |
| 238 | // 1. There is no way to use this at the moment so ignoring it is safe. |
| 239 | // 2. Attempting to initialize the contents property from the configuration will end up having |
| 240 | // the versioned prebuilt depending on the unversioned prebuilt. That will cause problems |
| 241 | // as the unversioned prebuilt could end up with an APEX variant created for the source |
| 242 | // APEX which will prevent it from having an APEX variant for the prebuilt APEX which in |
| 243 | // turn will prevent it from accessing the dex implementation jar from that which will |
| 244 | // break hidden API processing, amongst others. |
| 245 | return |
| 246 | } |
| 247 | |
| 248 | // Get the configuration for the art apex jars. |
| 249 | modules := b.getImageConfig(ctx).modules |
| 250 | configuredJars := modules.CopyOfJars() |
| 251 | |
| 252 | // Skip the check if the configured jars list is empty as that is a common configuration when |
| 253 | // building targets that do not result in a system image. |
| 254 | if len(configuredJars) == 0 { |
| 255 | return |
| 256 | } |
| 257 | |
| 258 | contents := b.properties.Contents |
| 259 | if !reflect.DeepEqual(configuredJars, contents) { |
| 260 | ctx.ModuleErrorf("inconsistency in specification of contents. ArtApexJars configuration specifies %#v, contents property specifies %#v", |
| 261 | configuredJars, contents) |
| 262 | } |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | |
Paul Duffin | e946b32 | 2021-04-25 23:04:00 +0100 | [diff] [blame] | 266 | var BootclasspathFragmentApexContentInfoProvider = blueprint.NewProvider(BootclasspathFragmentApexContentInfo{}) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 267 | |
Paul Duffin | e946b32 | 2021-04-25 23:04:00 +0100 | [diff] [blame] | 268 | // BootclasspathFragmentApexContentInfo contains the bootclasspath_fragments contributions to the |
| 269 | // apex contents. |
| 270 | type BootclasspathFragmentApexContentInfo struct { |
satayev | 3db3547 | 2021-05-06 23:59:58 +0100 | [diff] [blame] | 271 | // ClasspathFragmentProtoOutput is an output path for the generated classpaths.proto config of this module. |
| 272 | // |
| 273 | // The file should be copied to a relevant place on device, see ClasspathFragmentProtoInstallDir |
| 274 | // for more details. |
| 275 | ClasspathFragmentProtoOutput android.OutputPath |
| 276 | |
| 277 | // ClasspathFragmentProtoInstallDir contains information about on device location for the generated classpaths.proto file. |
| 278 | // |
| 279 | // The path encodes expected sub-location within partitions, i.e. etc/classpaths/<proto-file>, |
| 280 | // for ClasspathFragmentProtoOutput. To get sub-location, instead of the full output / make path |
| 281 | // use android.InstallPath#Rel(). |
| 282 | // |
| 283 | // This is only relevant for APEX modules as they perform their own installation; while regular |
| 284 | // system files are installed via ClasspathFragmentBase#androidMkEntries(). |
| 285 | ClasspathFragmentProtoInstallDir android.InstallPath |
| 286 | |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 287 | // The image config, internal to this module (and the dex_bootjars singleton). |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 288 | // |
Paul Duffin | e946b32 | 2021-04-25 23:04:00 +0100 | [diff] [blame] | 289 | // 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] | 290 | // when SkipDexpreoptBootJars(ctx) returns true. |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 291 | imageConfig *bootImageConfig |
| 292 | } |
| 293 | |
Paul Duffin | e946b32 | 2021-04-25 23:04:00 +0100 | [diff] [blame] | 294 | func (i BootclasspathFragmentApexContentInfo) Modules() android.ConfiguredJarList { |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 295 | return i.imageConfig.modules |
| 296 | } |
| 297 | |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 298 | // Get a map from ArchType to the associated boot image's contents for Android. |
| 299 | // |
| 300 | // 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] | 301 | func (i BootclasspathFragmentApexContentInfo) AndroidBootImageFilesByArchType() map[android.ArchType]android.OutputPaths { |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 302 | files := map[android.ArchType]android.OutputPaths{} |
| 303 | if i.imageConfig != nil { |
| 304 | for _, variant := range i.imageConfig.variants { |
| 305 | // We also generate boot images for host (for testing), but we don't need those in the apex. |
| 306 | // TODO(b/177892522) - consider changing this to check Os.OsClass = android.Device |
| 307 | if variant.target.Os == android.Android { |
| 308 | files[variant.target.Arch.ArchType] = variant.imagesDeps |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | return files |
| 313 | } |
| 314 | |
Paul Duffin | 190fdef | 2021-04-26 10:33:59 +0100 | [diff] [blame] | 315 | // DexBootJarPathForContentModule returns the path to the dex boot jar for specified module. |
| 316 | // |
| 317 | // The dex boot jar is one which has had hidden API encoding performed on it. |
| 318 | func (i BootclasspathFragmentApexContentInfo) DexBootJarPathForContentModule(module android.Module) android.Path { |
| 319 | j := module.(UsesLibraryDependency) |
| 320 | dexJar := j.DexJarBuildPath() |
| 321 | return dexJar |
| 322 | } |
| 323 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 324 | func (b *BootclasspathFragmentModule) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 325 | tag := ctx.OtherModuleDependencyTag(dep) |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 326 | if IsBootclasspathFragmentContentDepTag(tag) { |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 327 | // Boot image contents are automatically added to apex. |
| 328 | return true |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 329 | } |
Bob Badour | 07065cd | 2021-02-05 19:59:11 -0800 | [diff] [blame] | 330 | if android.IsMetaDependencyTag(tag) { |
| 331 | // Cross-cutting metadata dependencies are metadata. |
| 332 | return false |
| 333 | } |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 334 | panic(fmt.Errorf("boot_image module %q should not have a dependency on %q via tag %s", b, dep, android.PrettyPrintTag(tag))) |
| 335 | } |
| 336 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 337 | func (b *BootclasspathFragmentModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 338 | return nil |
| 339 | } |
| 340 | |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 341 | // ComponentDepsMutator adds dependencies onto modules before any prebuilt modules without a |
| 342 | // corresponding source module are renamed. This means that adding a dependency using a name without |
| 343 | // a prebuilt_ prefix will always resolve to a source module and when using a name with that prefix |
| 344 | // it will always resolve to a prebuilt module. |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 345 | func (b *BootclasspathFragmentModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 346 | module := ctx.Module() |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 347 | _, isSourceModule := module.(*BootclasspathFragmentModule) |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 348 | |
| 349 | for _, name := range b.properties.Contents { |
| 350 | // A bootclasspath_fragment must depend only on other source modules, while the |
| 351 | // prebuilt_bootclasspath_fragment must only depend on other prebuilt modules. |
Paul Duffin | a9dd6fa | 2021-04-22 17:25:57 +0100 | [diff] [blame] | 352 | // |
| 353 | // TODO(b/177892522) - avoid special handling of jacocoagent. |
| 354 | if !isSourceModule && name != "jacocoagent" { |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 355 | name = android.PrebuiltNameFromSource(name) |
| 356 | } |
| 357 | ctx.AddDependency(module, bootclasspathFragmentContentDepTag, name) |
| 358 | } |
| 359 | |
| 360 | } |
| 361 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 362 | func (b *BootclasspathFragmentModule) DepsMutator(ctx android.BottomUpMutatorContext) { |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 363 | // Add dependencies onto all the modules that provide the API stubs for classes on this |
| 364 | // bootclasspath fragment. |
| 365 | hiddenAPIAddStubLibDependencies(ctx, b.properties.sdkKindToStubLibs()) |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 366 | |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 367 | if SkipDexpreoptBootJars(ctx) { |
| 368 | return |
| 369 | } |
| 370 | |
| 371 | // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The |
| 372 | // path is retrieved from the dependency by GetGlobalSoongConfig(ctx). |
| 373 | dexpreopt.RegisterToolDeps(ctx) |
| 374 | } |
| 375 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 376 | func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 377 | // Only perform a consistency check if this module is the active module. That will prevent an |
| 378 | // unused prebuilt that was created without instrumentation from breaking an instrumentation |
| 379 | // build. |
| 380 | if isActiveModule(ctx.Module()) { |
| 381 | b.bootclasspathImageNameContentsConsistencyCheck(ctx) |
| 382 | } |
| 383 | |
satayev | 3db3547 | 2021-05-06 23:59:58 +0100 | [diff] [blame] | 384 | // Generate classpaths.proto config |
| 385 | b.generateClasspathProtoBuildActions(ctx) |
| 386 | |
Paul Duffin | 7ebebfd | 2021-04-27 19:36:57 +0100 | [diff] [blame] | 387 | // Gather the bootclasspath fragment's contents. |
| 388 | var contents []android.Module |
| 389 | ctx.VisitDirectDeps(func(module android.Module) { |
| 390 | tag := ctx.OtherModuleDependencyTag(module) |
| 391 | if IsBootclasspathFragmentContentDepTag(tag) { |
Paul Duffin | 79fd3d7 | 2021-05-14 16:14:17 +0100 | [diff] [blame] | 392 | contents = append(contents, module) |
Paul Duffin | 7ebebfd | 2021-04-27 19:36:57 +0100 | [diff] [blame] | 393 | } |
| 394 | }) |
| 395 | |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 396 | // Perform hidden API processing. |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 397 | b.generateHiddenAPIBuildActions(ctx, contents) |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 398 | |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 399 | // Construct the boot image info from the config. |
satayev | 3db3547 | 2021-05-06 23:59:58 +0100 | [diff] [blame] | 400 | info := BootclasspathFragmentApexContentInfo{ |
| 401 | ClasspathFragmentProtoInstallDir: b.classpathFragmentBase().installDirPath, |
| 402 | ClasspathFragmentProtoOutput: b.classpathFragmentBase().outputFilepath, |
| 403 | imageConfig: nil, |
| 404 | } |
| 405 | |
| 406 | if !SkipDexpreoptBootJars(ctx) { |
| 407 | // Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars |
| 408 | // GenerateSingletonBuildActions method as it cannot create it for itself. |
| 409 | dexpreopt.GetGlobalSoongConfig(ctx) |
| 410 | info.imageConfig = b.getImageConfig(ctx) |
Paul Duffin | 7ebebfd | 2021-04-27 19:36:57 +0100 | [diff] [blame] | 411 | |
| 412 | // Only generate the boot image if the configuration does not skip it. |
| 413 | b.generateBootImageBuildActions(ctx, contents) |
satayev | 3db3547 | 2021-05-06 23:59:58 +0100 | [diff] [blame] | 414 | } |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 415 | |
| 416 | // Make it available for other modules. |
Paul Duffin | e946b32 | 2021-04-25 23:04:00 +0100 | [diff] [blame] | 417 | ctx.SetProvider(BootclasspathFragmentApexContentInfoProvider, info) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 418 | } |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 419 | |
satayev | 3db3547 | 2021-05-06 23:59:58 +0100 | [diff] [blame] | 420 | // generateClasspathProtoBuildActions generates all required build actions for classpath.proto config |
| 421 | func (b *BootclasspathFragmentModule) generateClasspathProtoBuildActions(ctx android.ModuleContext) { |
| 422 | var classpathJars []classpathJar |
| 423 | if "art" == proptools.String(b.properties.Image_name) { |
| 424 | // ART and platform boot jars must have a corresponding entry in DEX2OATBOOTCLASSPATH |
| 425 | classpathJars = configuredJarListToClasspathJars(ctx, b.ClasspathFragmentToConfiguredJarList(ctx), BOOTCLASSPATH, DEX2OATBOOTCLASSPATH) |
| 426 | } else { |
| 427 | classpathJars = configuredJarListToClasspathJars(ctx, b.ClasspathFragmentToConfiguredJarList(ctx), b.classpathType) |
| 428 | } |
| 429 | b.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, classpathJars) |
| 430 | } |
| 431 | |
| 432 | func (b *BootclasspathFragmentModule) ClasspathFragmentToConfiguredJarList(ctx android.ModuleContext) android.ConfiguredJarList { |
| 433 | // TODO(satayev): populate with actual content |
| 434 | return android.EmptyConfiguredJarList() |
| 435 | } |
| 436 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 437 | func (b *BootclasspathFragmentModule) getImageConfig(ctx android.EarlyModuleContext) *bootImageConfig { |
Paul Duffin | 64be7bb | 2021-03-23 23:06:38 +0000 | [diff] [blame] | 438 | // Get a map of the image configs that are supported. |
| 439 | imageConfigs := genBootImageConfigs(ctx) |
| 440 | |
| 441 | // Retrieve the config for this image. |
| 442 | imageNamePtr := b.properties.Image_name |
| 443 | if imageNamePtr == nil { |
| 444 | return nil |
| 445 | } |
| 446 | |
| 447 | imageName := *imageNamePtr |
| 448 | imageConfig := imageConfigs[imageName] |
| 449 | if imageConfig == nil { |
| 450 | ctx.PropertyErrorf("image_name", "Unknown image name %q, expected one of %s", imageName, strings.Join(android.SortedStringKeys(imageConfigs), ", ")) |
| 451 | return nil |
| 452 | } |
| 453 | return imageConfig |
| 454 | } |
| 455 | |
Paul Duffin | 70cfdff | 2021-05-15 09:10:42 +0100 | [diff] [blame^] | 456 | // canPerformHiddenAPIProcessing determines whether hidden API processing should be performed. |
| 457 | // |
| 458 | // A temporary workaround to avoid existing bootclasspath_fragments that do not provide the |
| 459 | // appropriate information needed for hidden API processing breaking the build. |
| 460 | // TODO(b/179354495): Remove this workaround. |
| 461 | func (b *BootclasspathFragmentModule) canPerformHiddenAPIProcessing(ctx android.ModuleContext) bool { |
| 462 | // Hidden API processing is always enabled in tests. |
| 463 | if ctx.Config().TestProductVariables != nil { |
| 464 | return true |
| 465 | } |
| 466 | // A module that has fragments should have access to the information it needs in order to perform |
| 467 | // hidden API processing. |
| 468 | if len(b.properties.Fragments) != 0 { |
| 469 | return true |
| 470 | } |
| 471 | |
| 472 | // The art bootclasspath fragment does not depend on any other fragments but already supports |
| 473 | // hidden API processing. |
| 474 | imageName := proptools.String(b.properties.Image_name) |
| 475 | if imageName == "art" { |
| 476 | return true |
| 477 | } |
| 478 | |
| 479 | // Disable it for everything else. |
| 480 | return false |
| 481 | } |
| 482 | |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 483 | // generateHiddenAPIBuildActions generates all the hidden API related build rules. |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 484 | func (b *BootclasspathFragmentModule) generateHiddenAPIBuildActions(ctx android.ModuleContext, contents []android.Module) { |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 485 | |
Paul Duffin | 70cfdff | 2021-05-15 09:10:42 +0100 | [diff] [blame^] | 486 | // A temporary workaround to avoid existing bootclasspath_fragments that do not provide the |
| 487 | // appropriate information needed for hidden API processing breaking the build. |
| 488 | if !b.canPerformHiddenAPIProcessing(ctx) { |
| 489 | // Nothing to do. |
| 490 | return |
| 491 | } |
| 492 | |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 493 | // Convert the kind specific lists of modules into kind specific lists of jars. |
Paul Duffin | 34827d4 | 2021-05-13 21:25:05 +0100 | [diff] [blame] | 494 | stubJarsByKind := hiddenAPIGatherStubLibDexJarPaths(ctx, contents) |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 495 | |
Paul Duffin | 70cfdff | 2021-05-15 09:10:42 +0100 | [diff] [blame^] | 496 | // Performing hidden API processing without stubs is not supported and it is unlikely to ever be |
| 497 | // required as the whole point of adding something to the bootclasspath fragment is to add it to |
| 498 | // the bootclasspath in order to be used by something else in the system. Without any stubs it |
| 499 | // cannot do that. |
| 500 | if len(stubJarsByKind) == 0 { |
| 501 | return |
| 502 | } |
| 503 | |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 504 | // Store the information for use by other modules. |
| 505 | bootclasspathApiInfo := bootclasspathApiInfo{stubJarsByKind: stubJarsByKind} |
| 506 | ctx.SetProvider(bootclasspathApiInfoProvider, bootclasspathApiInfo) |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 507 | |
| 508 | // Resolve the properties to paths. |
| 509 | flagFileInfo := b.properties.Hidden_api.hiddenAPIFlagFileInfo(ctx) |
| 510 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 511 | hiddenAPIModules := gatherHiddenAPIModuleFromContents(ctx, contents) |
| 512 | |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 513 | // Delegate the production of the hidden API all flags file to a module type specific method. |
| 514 | common := ctx.Module().(commonBootclasspathFragment) |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 515 | common.produceHiddenAPIAllFlagsFile(ctx, hiddenAPIModules, stubJarsByKind, &flagFileInfo) |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 516 | |
| 517 | // Store the information for use by platform_bootclasspath. |
| 518 | ctx.SetProvider(hiddenAPIFlagFileInfoProvider, flagFileInfo) |
| 519 | } |
| 520 | |
| 521 | // produceHiddenAPIAllFlagsFile produces the hidden API all-flags.csv file (and supporting files) |
| 522 | // for the fragment. |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 523 | func (b *BootclasspathFragmentModule) produceHiddenAPIAllFlagsFile(ctx android.ModuleContext, contents []hiddenAPIModule, stubJarsByKind map[android.SdkKind]android.Paths, flagFileInfo *hiddenAPIFlagFileInfo) { |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 524 | // Generate the rules to create the hidden API flags and update the supplied flagFileInfo with the |
| 525 | // paths to the created files. |
| 526 | hiddenAPIGenerateAllFlagsForBootclasspathFragment(ctx, contents, stubJarsByKind, flagFileInfo) |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 527 | } |
| 528 | |
Paul Duffin | 7ebebfd | 2021-04-27 19:36:57 +0100 | [diff] [blame] | 529 | // generateBootImageBuildActions generates ninja rules to create the boot image if required for this |
| 530 | // module. |
| 531 | func (b *BootclasspathFragmentModule) generateBootImageBuildActions(ctx android.ModuleContext, contents []android.Module) { |
| 532 | global := dexpreopt.GetGlobalConfig(ctx) |
| 533 | if !shouldBuildBootImages(ctx.Config(), global) { |
| 534 | return |
| 535 | } |
| 536 | |
| 537 | // Bootclasspath fragment modules that are not preferred do not produce a boot image. |
| 538 | if !isActiveModule(ctx.Module()) { |
| 539 | return |
| 540 | } |
| 541 | |
| 542 | // Bootclasspath fragment modules that have no image_name property do not produce a boot image. |
| 543 | imageConfig := b.getImageConfig(ctx) |
| 544 | if imageConfig == nil { |
| 545 | return |
| 546 | } |
| 547 | |
| 548 | // Bootclasspath fragment modules that are for the platform do not produce a boot image. |
| 549 | apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 550 | if apexInfo.IsForPlatform() { |
| 551 | return |
| 552 | } |
| 553 | |
| 554 | // Bootclasspath fragment modules that are versioned do not produce a boot image. |
| 555 | if android.IsModuleInVersionedSdk(ctx.Module()) { |
| 556 | return |
| 557 | } |
| 558 | |
| 559 | // Copy the dex jars of this fragment's content modules to their predefined locations. |
| 560 | copyBootJarsToPredefinedLocations(ctx, contents, imageConfig.modules, imageConfig.dexPaths) |
Paul Duffin | 2fc82ad | 2021-04-29 23:36:12 +0100 | [diff] [blame] | 561 | |
| 562 | // Build a profile for the image config and then use that to build the boot image. |
| 563 | profile := bootImageProfileRule(ctx, imageConfig) |
| 564 | buildBootImage(ctx, imageConfig, profile) |
Paul Duffin | 7ebebfd | 2021-04-27 19:36:57 +0100 | [diff] [blame] | 565 | } |
| 566 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 567 | type bootclasspathFragmentMemberType struct { |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 568 | android.SdkMemberTypeBase |
| 569 | } |
| 570 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 571 | func (b *bootclasspathFragmentMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 572 | mctx.AddVariationDependencies(nil, dependencyTag, names...) |
| 573 | } |
| 574 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 575 | func (b *bootclasspathFragmentMemberType) IsInstance(module android.Module) bool { |
| 576 | _, ok := module.(*BootclasspathFragmentModule) |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 577 | return ok |
| 578 | } |
| 579 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 580 | func (b *bootclasspathFragmentMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { |
Paul Duffin | 4b64ba0 | 2021-03-29 11:02:53 +0100 | [diff] [blame] | 581 | if b.PropertyName == "boot_images" { |
| 582 | return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_boot_image") |
| 583 | } else { |
| 584 | return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_bootclasspath_fragment") |
| 585 | } |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 586 | } |
| 587 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 588 | func (b *bootclasspathFragmentMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { |
| 589 | return &bootclasspathFragmentSdkMemberProperties{} |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 590 | } |
| 591 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 592 | type bootclasspathFragmentSdkMemberProperties struct { |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 593 | android.SdkMemberPropertiesBase |
| 594 | |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 595 | // The image name |
Paul Duffin | 64be7bb | 2021-03-23 23:06:38 +0000 | [diff] [blame] | 596 | Image_name *string |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 597 | |
| 598 | // Contents of the bootclasspath fragment |
| 599 | Contents []string |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 600 | |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 601 | // Stub_libs properties. |
| 602 | Stub_libs []string |
| 603 | Core_platform_stub_libs []string |
| 604 | |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 605 | // Flag files by *hiddenAPIFlagFileCategory |
| 606 | Flag_files_by_category map[*hiddenAPIFlagFileCategory]android.Paths |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 607 | |
| 608 | // The path to the generated stub-flags.csv file. |
| 609 | Stub_flags_path android.OptionalPath |
| 610 | |
| 611 | // The path to the generated annotation-flags.csv file. |
| 612 | Annotation_flags_path android.OptionalPath |
| 613 | |
| 614 | // The path to the generated metadata.csv file. |
| 615 | Metadata_path android.OptionalPath |
| 616 | |
| 617 | // The path to the generated index.csv file. |
| 618 | Index_path android.OptionalPath |
| 619 | |
| 620 | // The path to the generated all-flags.csv file. |
| 621 | All_flags_path android.OptionalPath |
| 622 | } |
| 623 | |
| 624 | func pathsToOptionalPath(paths android.Paths) android.OptionalPath { |
| 625 | switch len(paths) { |
| 626 | case 0: |
| 627 | return android.OptionalPath{} |
| 628 | case 1: |
| 629 | return android.OptionalPathForPath(paths[0]) |
| 630 | default: |
| 631 | panic(fmt.Errorf("expected 0 or 1 paths, found %q", paths)) |
| 632 | } |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 633 | } |
| 634 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 635 | func (b *bootclasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { |
| 636 | module := variant.(*BootclasspathFragmentModule) |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 637 | |
| 638 | b.Image_name = module.properties.Image_name |
Paul Duffin | 2dc665b | 2021-04-23 16:58:51 +0100 | [diff] [blame] | 639 | b.Contents = module.properties.Contents |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 640 | |
| 641 | // Get the flag file information from the module. |
| 642 | mctx := ctx.SdkModuleContext() |
| 643 | flagFileInfo := mctx.OtherModuleProvider(module, hiddenAPIFlagFileInfoProvider).(hiddenAPIFlagFileInfo) |
| 644 | b.Flag_files_by_category = flagFileInfo.categoryToPaths |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 645 | |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 646 | // Copy all the generated file paths. |
| 647 | b.Stub_flags_path = pathsToOptionalPath(flagFileInfo.StubFlagsPaths) |
| 648 | b.Annotation_flags_path = pathsToOptionalPath(flagFileInfo.AnnotationFlagsPaths) |
| 649 | b.Metadata_path = pathsToOptionalPath(flagFileInfo.MetadataPaths) |
| 650 | b.Index_path = pathsToOptionalPath(flagFileInfo.IndexPaths) |
| 651 | b.All_flags_path = pathsToOptionalPath(flagFileInfo.AllFlagsPaths) |
| 652 | |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 653 | // Copy stub_libs properties. |
| 654 | b.Stub_libs = module.properties.Api.Stub_libs |
| 655 | b.Core_platform_stub_libs = module.properties.Core_platform_api.Stub_libs |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 656 | } |
| 657 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 658 | func (b *bootclasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { |
Paul Duffin | 64be7bb | 2021-03-23 23:06:38 +0000 | [diff] [blame] | 659 | if b.Image_name != nil { |
| 660 | propertySet.AddProperty("image_name", *b.Image_name) |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 661 | } |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 662 | |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 663 | builder := ctx.SnapshotBuilder() |
| 664 | requiredMemberDependency := builder.SdkMemberReferencePropertyTag(true) |
| 665 | |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 666 | if len(b.Contents) > 0 { |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 667 | propertySet.AddPropertyWithTag("contents", b.Contents, requiredMemberDependency) |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 668 | } |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 669 | |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 670 | if len(b.Stub_libs) > 0 { |
| 671 | apiPropertySet := propertySet.AddPropertySet("api") |
| 672 | apiPropertySet.AddPropertyWithTag("stub_libs", b.Stub_libs, requiredMemberDependency) |
| 673 | } |
| 674 | if len(b.Core_platform_stub_libs) > 0 { |
| 675 | corePlatformApiPropertySet := propertySet.AddPropertySet("core_platform_api") |
| 676 | corePlatformApiPropertySet.AddPropertyWithTag("stub_libs", b.Core_platform_stub_libs, requiredMemberDependency) |
| 677 | } |
| 678 | |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 679 | hiddenAPISet := propertySet.AddPropertySet("hidden_api") |
| 680 | hiddenAPIDir := "hiddenapi" |
| 681 | |
| 682 | // Copy manually curated flag files specified on the bootclasspath_fragment. |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 683 | if b.Flag_files_by_category != nil { |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 684 | for _, category := range hiddenAPIFlagFileCategories { |
| 685 | paths := b.Flag_files_by_category[category] |
| 686 | if len(paths) > 0 { |
| 687 | dests := []string{} |
| 688 | for _, p := range paths { |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 689 | dest := filepath.Join(hiddenAPIDir, p.Base()) |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 690 | builder.CopyToSnapshot(p, dest) |
| 691 | dests = append(dests, dest) |
| 692 | } |
| 693 | hiddenAPISet.AddProperty(category.propertyName, dests) |
| 694 | } |
| 695 | } |
| 696 | } |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 697 | |
| 698 | copyOptionalPath := func(path android.OptionalPath, property string) { |
| 699 | if path.Valid() { |
| 700 | p := path.Path() |
| 701 | dest := filepath.Join(hiddenAPIDir, p.Base()) |
| 702 | builder.CopyToSnapshot(p, dest) |
| 703 | hiddenAPISet.AddProperty(property, dest) |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | // Copy all the generated files, if available. |
| 708 | copyOptionalPath(b.Stub_flags_path, "stub_flags") |
| 709 | copyOptionalPath(b.Annotation_flags_path, "annotation_flags") |
| 710 | copyOptionalPath(b.Metadata_path, "metadata") |
| 711 | copyOptionalPath(b.Index_path, "index") |
| 712 | copyOptionalPath(b.All_flags_path, "all_flags") |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 713 | } |
| 714 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 715 | var _ android.SdkMemberType = (*bootclasspathFragmentMemberType)(nil) |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 716 | |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 717 | // prebuiltBootclasspathFragmentProperties contains additional prebuilt_bootclasspath_fragment |
| 718 | // specific properties. |
| 719 | type prebuiltBootclasspathFragmentProperties struct { |
| 720 | Hidden_api struct { |
| 721 | // The path to the stub-flags.csv file created by the bootclasspath_fragment. |
| 722 | Stub_flags *string `android:"path"` |
| 723 | |
| 724 | // The path to the annotation-flags.csv file created by the bootclasspath_fragment. |
| 725 | Annotation_flags *string `android:"path"` |
| 726 | |
| 727 | // The path to the metadata.csv file created by the bootclasspath_fragment. |
| 728 | Metadata *string `android:"path"` |
| 729 | |
| 730 | // The path to the index.csv file created by the bootclasspath_fragment. |
| 731 | Index *string `android:"path"` |
| 732 | |
| 733 | // The path to the all-flags.csv file created by the bootclasspath_fragment. |
| 734 | All_flags *string `android:"path"` |
| 735 | } |
| 736 | } |
| 737 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 738 | // A prebuilt version of the bootclasspath_fragment module. |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 739 | // |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 740 | // At the moment this is basically just a bootclasspath_fragment module that can be used as a |
| 741 | // prebuilt. Eventually as more functionality is migrated into the bootclasspath_fragment module |
| 742 | // type from the various singletons then this will diverge. |
| 743 | type prebuiltBootclasspathFragmentModule struct { |
| 744 | BootclasspathFragmentModule |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 745 | prebuilt android.Prebuilt |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 746 | |
| 747 | // Additional prebuilt specific properties. |
| 748 | prebuiltProperties prebuiltBootclasspathFragmentProperties |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 749 | } |
| 750 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 751 | func (module *prebuiltBootclasspathFragmentModule) Prebuilt() *android.Prebuilt { |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 752 | return &module.prebuilt |
| 753 | } |
| 754 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 755 | func (module *prebuiltBootclasspathFragmentModule) Name() string { |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 756 | return module.prebuilt.Name(module.ModuleBase.Name()) |
| 757 | } |
| 758 | |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 759 | // produceHiddenAPIAllFlagsFile returns a path to the prebuilt all-flags.csv or nil if none is |
| 760 | // specified. |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 761 | func (module *prebuiltBootclasspathFragmentModule) produceHiddenAPIAllFlagsFile(ctx android.ModuleContext, contents []hiddenAPIModule, stubJarsByKind map[android.SdkKind]android.Paths, flagFileInfo *hiddenAPIFlagFileInfo) { |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 762 | pathsForOptionalSrc := func(src *string) android.Paths { |
| 763 | if src == nil { |
| 764 | // TODO(b/179354495): Fail if this is not provided once prebuilts have been updated. |
| 765 | return nil |
| 766 | } |
| 767 | return android.Paths{android.PathForModuleSrc(ctx, *src)} |
| 768 | } |
| 769 | |
| 770 | flagFileInfo.StubFlagsPaths = pathsForOptionalSrc(module.prebuiltProperties.Hidden_api.Stub_flags) |
| 771 | flagFileInfo.AnnotationFlagsPaths = pathsForOptionalSrc(module.prebuiltProperties.Hidden_api.Annotation_flags) |
| 772 | flagFileInfo.MetadataPaths = pathsForOptionalSrc(module.prebuiltProperties.Hidden_api.Metadata) |
| 773 | flagFileInfo.IndexPaths = pathsForOptionalSrc(module.prebuiltProperties.Hidden_api.Index) |
| 774 | flagFileInfo.AllFlagsPaths = pathsForOptionalSrc(module.prebuiltProperties.Hidden_api.All_flags) |
| 775 | } |
| 776 | |
| 777 | var _ commonBootclasspathFragment = (*prebuiltBootclasspathFragmentModule)(nil) |
| 778 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 779 | func prebuiltBootclasspathFragmentFactory() android.Module { |
| 780 | m := &prebuiltBootclasspathFragmentModule{} |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 781 | m.AddProperties(&m.properties, &m.prebuiltProperties) |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 782 | // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs |
| 783 | // array. |
| 784 | android.InitPrebuiltModule(m, &[]string{"placeholder"}) |
| 785 | android.InitApexModule(m) |
| 786 | android.InitSdkAwareModule(m) |
Martin Stjernholm | b79c7f1 | 2021-03-17 00:26:25 +0000 | [diff] [blame] | 787 | android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon) |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 788 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 789 | // Initialize the contents property from the image_name. |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 790 | android.AddLoadHook(m, func(ctx android.LoadHookContext) { |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 791 | bootclasspathFragmentInitContentsFromImage(ctx, &m.BootclasspathFragmentModule) |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 792 | }) |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 793 | return m |
| 794 | } |