platform_bootclasspath.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. // Copyright 2021 Google Inc. All rights reserved.
  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. package java
  15. import (
  16. "fmt"
  17. "android/soong/android"
  18. "android/soong/dexpreopt"
  19. )
  20. func init() {
  21. registerPlatformBootclasspathBuildComponents(android.InitRegistrationContext)
  22. }
  23. func registerPlatformBootclasspathBuildComponents(ctx android.RegistrationContext) {
  24. ctx.RegisterParallelSingletonModuleType("platform_bootclasspath", platformBootclasspathFactory)
  25. }
  26. // The tags used for the dependencies between the platform bootclasspath and any configured boot
  27. // jars.
  28. var (
  29. platformBootclasspathArtBootJarDepTag = bootclasspathDependencyTag{name: "art-boot-jar"}
  30. platformBootclasspathBootJarDepTag = bootclasspathDependencyTag{name: "platform-boot-jar"}
  31. platformBootclasspathApexBootJarDepTag = bootclasspathDependencyTag{name: "apex-boot-jar"}
  32. )
  33. type platformBootclasspathModule struct {
  34. android.SingletonModuleBase
  35. ClasspathFragmentBase
  36. properties platformBootclasspathProperties
  37. // The apex:module pairs obtained from the configured modules.
  38. configuredModules []android.Module
  39. // The apex:module pairs obtained from the fragments.
  40. fragments []android.Module
  41. // Path to the monolithic hiddenapi-flags.csv file.
  42. hiddenAPIFlagsCSV android.OutputPath
  43. // Path to the monolithic hiddenapi-index.csv file.
  44. hiddenAPIIndexCSV android.OutputPath
  45. // Path to the monolithic hiddenapi-unsupported.csv file.
  46. hiddenAPIMetadataCSV android.OutputPath
  47. }
  48. type platformBootclasspathProperties struct {
  49. BootclasspathFragmentsDepsProperties
  50. HiddenAPIFlagFileProperties
  51. }
  52. func platformBootclasspathFactory() android.SingletonModule {
  53. m := &platformBootclasspathModule{}
  54. m.AddProperties(&m.properties)
  55. initClasspathFragment(m, BOOTCLASSPATH)
  56. android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
  57. return m
  58. }
  59. var _ android.OutputFileProducer = (*platformBootclasspathModule)(nil)
  60. func (b *platformBootclasspathModule) AndroidMkEntries() (entries []android.AndroidMkEntries) {
  61. entries = append(entries, android.AndroidMkEntries{
  62. Class: "FAKE",
  63. // Need at least one output file in order for this to take effect.
  64. OutputFile: android.OptionalPathForPath(b.hiddenAPIFlagsCSV),
  65. Include: "$(BUILD_PHONY_PACKAGE)",
  66. })
  67. entries = append(entries, b.classpathFragmentBase().androidMkEntries()...)
  68. return
  69. }
  70. // Make the hidden API files available from the platform-bootclasspath module.
  71. func (b *platformBootclasspathModule) OutputFiles(tag string) (android.Paths, error) {
  72. switch tag {
  73. case "hiddenapi-flags.csv":
  74. return android.Paths{b.hiddenAPIFlagsCSV}, nil
  75. case "hiddenapi-index.csv":
  76. return android.Paths{b.hiddenAPIIndexCSV}, nil
  77. case "hiddenapi-metadata.csv":
  78. return android.Paths{b.hiddenAPIMetadataCSV}, nil
  79. }
  80. return nil, fmt.Errorf("unknown tag %s", tag)
  81. }
  82. func (b *platformBootclasspathModule) DepsMutator(ctx android.BottomUpMutatorContext) {
  83. b.hiddenAPIDepsMutator(ctx)
  84. if !dexpreopt.IsDex2oatNeeded(ctx) {
  85. return
  86. }
  87. // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The
  88. // path is retrieved from the dependency by GetGlobalSoongConfig(ctx).
  89. dexpreopt.RegisterToolDeps(ctx)
  90. }
  91. func (b *platformBootclasspathModule) hiddenAPIDepsMutator(ctx android.BottomUpMutatorContext) {
  92. if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
  93. return
  94. }
  95. // Add dependencies onto the stub lib modules.
  96. apiLevelToStubLibModules := hiddenAPIComputeMonolithicStubLibModules(ctx.Config())
  97. hiddenAPIAddStubLibDependencies(ctx, apiLevelToStubLibModules)
  98. }
  99. func (b *platformBootclasspathModule) BootclasspathDepsMutator(ctx android.BottomUpMutatorContext) {
  100. // Add dependencies on all the modules configured in the "art" boot image.
  101. artImageConfig := genBootImageConfigs(ctx)[artBootImageName]
  102. addDependenciesOntoBootImageModules(ctx, artImageConfig.modules, platformBootclasspathArtBootJarDepTag)
  103. // Add dependencies on all the non-updatable module configured in the "boot" boot image. That does
  104. // not include modules configured in the "art" boot image.
  105. addDependenciesOntoBootImageModules(ctx, b.platformJars(ctx), platformBootclasspathBootJarDepTag)
  106. // Add dependencies on all the apex jars.
  107. apexJars := dexpreopt.GetGlobalConfig(ctx).ApexBootJars
  108. addDependenciesOntoBootImageModules(ctx, apexJars, platformBootclasspathApexBootJarDepTag)
  109. // Add dependencies on all the fragments.
  110. b.properties.BootclasspathFragmentsDepsProperties.addDependenciesOntoFragments(ctx)
  111. }
  112. func addDependenciesOntoBootImageModules(ctx android.BottomUpMutatorContext, modules android.ConfiguredJarList, tag bootclasspathDependencyTag) {
  113. for i := 0; i < modules.Len(); i++ {
  114. apex := modules.Apex(i)
  115. name := modules.Jar(i)
  116. addDependencyOntoApexModulePair(ctx, apex, name, tag)
  117. }
  118. }
  119. // GenerateSingletonBuildActions does nothing and must never do anything.
  120. //
  121. // This module only implements android.SingletonModule so that it can implement
  122. // android.SingletonMakeVarsProvider.
  123. func (b *platformBootclasspathModule) GenerateSingletonBuildActions(android.SingletonContext) {
  124. // Keep empty
  125. }
  126. func (d *platformBootclasspathModule) MakeVars(ctx android.MakeVarsContext) {
  127. d.generateHiddenApiMakeVars(ctx)
  128. }
  129. func (b *platformBootclasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
  130. // Gather all the dependencies from the art, platform, and apex boot jars.
  131. artModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathArtBootJarDepTag)
  132. platformModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathBootJarDepTag)
  133. apexModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathApexBootJarDepTag)
  134. // Concatenate them all, in order as they would appear on the bootclasspath.
  135. var allModules []android.Module
  136. allModules = append(allModules, artModules...)
  137. allModules = append(allModules, platformModules...)
  138. allModules = append(allModules, apexModules...)
  139. b.configuredModules = allModules
  140. // Gather all the fragments dependencies.
  141. b.fragments = gatherApexModulePairDepsWithTag(ctx, bootclasspathFragmentDepTag)
  142. // Check the configuration of the boot modules.
  143. // ART modules are checked by the art-bootclasspath-fragment.
  144. b.checkPlatformModules(ctx, platformModules)
  145. b.checkApexModules(ctx, apexModules)
  146. b.generateClasspathProtoBuildActions(ctx)
  147. bootDexJarByModule := b.generateHiddenAPIBuildActions(ctx, b.configuredModules, b.fragments)
  148. buildRuleForBootJarsPackageCheck(ctx, bootDexJarByModule)
  149. b.generateBootImageBuildActions(ctx)
  150. b.copyApexBootJarsForAppsDexpreopt(ctx, apexModules)
  151. }
  152. // Generate classpaths.proto config
  153. func (b *platformBootclasspathModule) generateClasspathProtoBuildActions(ctx android.ModuleContext) {
  154. configuredJars := b.configuredJars(ctx)
  155. // ART and platform boot jars must have a corresponding entry in DEX2OATBOOTCLASSPATH
  156. classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, BOOTCLASSPATH, DEX2OATBOOTCLASSPATH)
  157. b.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
  158. }
  159. func (b *platformBootclasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
  160. // Include all non APEX jars
  161. jars := b.platformJars(ctx)
  162. // Include jars from APEXes that don't populate their classpath proto config.
  163. remainingJars := dexpreopt.GetGlobalConfig(ctx).ApexBootJars
  164. for _, fragment := range b.fragments {
  165. info := ctx.OtherModuleProvider(fragment, ClasspathFragmentProtoContentInfoProvider).(ClasspathFragmentProtoContentInfo)
  166. if info.ClasspathFragmentProtoGenerated {
  167. remainingJars = remainingJars.RemoveList(info.ClasspathFragmentProtoContents)
  168. }
  169. }
  170. for i := 0; i < remainingJars.Len(); i++ {
  171. jars = jars.Append(remainingJars.Apex(i), remainingJars.Jar(i))
  172. }
  173. return jars
  174. }
  175. func (b *platformBootclasspathModule) platformJars(ctx android.PathContext) android.ConfiguredJarList {
  176. return defaultBootImageConfig(ctx).modules.RemoveList(artBootImageConfig(ctx).modules)
  177. }
  178. // checkPlatformModules ensures that the non-updatable modules supplied are not part of an
  179. // apex module.
  180. func (b *platformBootclasspathModule) checkPlatformModules(ctx android.ModuleContext, modules []android.Module) {
  181. // TODO(satayev): change this check to only allow core-icu4j, all apex jars should not be here.
  182. for _, m := range modules {
  183. apexInfo := ctx.OtherModuleProvider(m, android.ApexInfoProvider).(android.ApexInfo)
  184. fromUpdatableApex := apexInfo.Updatable
  185. if fromUpdatableApex {
  186. // error: this jar is part of an updatable apex
  187. ctx.ModuleErrorf("module %q from updatable apexes %q is not allowed in the platform bootclasspath", ctx.OtherModuleName(m), apexInfo.InApexVariants)
  188. } else {
  189. // ok: this jar is part of the platform or a non-updatable apex
  190. }
  191. }
  192. }
  193. // checkApexModules ensures that the apex modules supplied are not from the platform.
  194. func (b *platformBootclasspathModule) checkApexModules(ctx android.ModuleContext, modules []android.Module) {
  195. for _, m := range modules {
  196. apexInfo := ctx.OtherModuleProvider(m, android.ApexInfoProvider).(android.ApexInfo)
  197. fromUpdatableApex := apexInfo.Updatable
  198. if fromUpdatableApex {
  199. // ok: this jar is part of an updatable apex
  200. } else {
  201. name := ctx.OtherModuleName(m)
  202. if apexInfo.IsForPlatform() {
  203. // If AlwaysUsePrebuiltSdks() returns true then it is possible that the updatable list will
  204. // include platform variants of a prebuilt module due to workarounds elsewhere. In that case
  205. // do not treat this as an error.
  206. // TODO(b/179354495): Always treat this as an error when migration to bootclasspath_fragment
  207. // modules is complete.
  208. if !ctx.Config().AlwaysUsePrebuiltSdks() {
  209. // error: this jar is part of the platform
  210. ctx.ModuleErrorf("module %q from platform is not allowed in the apex boot jars list", name)
  211. }
  212. } else {
  213. // TODO(b/177892522): Treat this as an error.
  214. // Cannot do that at the moment because framework-wifi and framework-tethering are in the
  215. // PRODUCT_APEX_BOOT_JARS but not marked as updatable in AOSP.
  216. }
  217. }
  218. }
  219. }
  220. // generateHiddenAPIBuildActions generates all the hidden API related build rules.
  221. func (b *platformBootclasspathModule) generateHiddenAPIBuildActions(ctx android.ModuleContext, modules []android.Module, fragments []android.Module) bootDexJarByModule {
  222. // Save the paths to the monolithic files for retrieval via OutputFiles().
  223. b.hiddenAPIFlagsCSV = hiddenAPISingletonPaths(ctx).flags
  224. b.hiddenAPIIndexCSV = hiddenAPISingletonPaths(ctx).index
  225. b.hiddenAPIMetadataCSV = hiddenAPISingletonPaths(ctx).metadata
  226. bootDexJarByModule := extractBootDexJarsFromModules(ctx, modules)
  227. // Don't run any hiddenapi rules if UNSAFE_DISABLE_HIDDENAPI_FLAGS=true. This is a performance
  228. // optimization that can be used to reduce the incremental build time but as its name suggests it
  229. // can be unsafe to use, e.g. when the changes affect anything that goes on the bootclasspath.
  230. if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
  231. paths := android.OutputPaths{b.hiddenAPIFlagsCSV, b.hiddenAPIIndexCSV, b.hiddenAPIMetadataCSV}
  232. for _, path := range paths {
  233. ctx.Build(pctx, android.BuildParams{
  234. Rule: android.Touch,
  235. Output: path,
  236. })
  237. }
  238. return bootDexJarByModule
  239. }
  240. // Construct a list of ClasspathElement objects from the modules and fragments.
  241. classpathElements := CreateClasspathElements(ctx, modules, fragments)
  242. monolithicInfo := b.createAndProvideMonolithicHiddenAPIInfo(ctx, classpathElements)
  243. // Extract the classes jars only from those libraries that do not have corresponding fragments as
  244. // the fragments will have already provided the flags that are needed.
  245. classesJars := monolithicInfo.ClassesJars
  246. // Create the input to pass to buildRuleToGenerateHiddenAPIStubFlagsFile
  247. input := newHiddenAPIFlagInput()
  248. // Gather stub library information from the dependencies on modules provided by
  249. // hiddenAPIComputeMonolithicStubLibModules.
  250. input.gatherStubLibInfo(ctx, nil)
  251. // Use the flag files from this module and all the fragments.
  252. input.FlagFilesByCategory = monolithicInfo.FlagsFilesByCategory
  253. // Generate the monolithic stub-flags.csv file.
  254. stubFlags := hiddenAPISingletonPaths(ctx).stubFlags
  255. buildRuleToGenerateHiddenAPIStubFlagsFile(ctx, "platform-bootclasspath-monolithic-hiddenapi-stub-flags", "monolithic hidden API stub flags", stubFlags, bootDexJarByModule.bootDexJars(), input, monolithicInfo.StubFlagSubsets)
  256. // Generate the annotation-flags.csv file from all the module annotations.
  257. annotationFlags := android.PathForModuleOut(ctx, "hiddenapi-monolithic", "annotation-flags-from-classes.csv")
  258. buildRuleToGenerateAnnotationFlags(ctx, "intermediate hidden API flags", classesJars, stubFlags, annotationFlags)
  259. // Generate the monolithic hiddenapi-flags.csv file.
  260. //
  261. // Use annotation flags generated directly from the classes jars as well as annotation flag files
  262. // provided by prebuilts.
  263. allAnnotationFlagFiles := android.Paths{annotationFlags}
  264. allAnnotationFlagFiles = append(allAnnotationFlagFiles, monolithicInfo.AnnotationFlagsPaths...)
  265. allFlags := hiddenAPISingletonPaths(ctx).flags
  266. buildRuleToGenerateHiddenApiFlags(ctx, "hiddenAPIFlagsFile", "monolithic hidden API flags", allFlags, stubFlags, allAnnotationFlagFiles, monolithicInfo.FlagsFilesByCategory, monolithicInfo.FlagSubsets, android.OptionalPath{})
  267. // Generate an intermediate monolithic hiddenapi-metadata.csv file directly from the annotations
  268. // in the source code.
  269. intermediateMetadataCSV := android.PathForModuleOut(ctx, "hiddenapi-monolithic", "metadata-from-classes.csv")
  270. buildRuleToGenerateMetadata(ctx, "intermediate hidden API metadata", classesJars, stubFlags, intermediateMetadataCSV)
  271. // Generate the monolithic hiddenapi-metadata.csv file.
  272. //
  273. // Use metadata files generated directly from the classes jars as well as metadata files provided
  274. // by prebuilts.
  275. //
  276. // This has the side effect of ensuring that the output file uses | quotes just in case that is
  277. // important for the tools that consume the metadata file.
  278. allMetadataFlagFiles := android.Paths{intermediateMetadataCSV}
  279. allMetadataFlagFiles = append(allMetadataFlagFiles, monolithicInfo.MetadataPaths...)
  280. metadataCSV := hiddenAPISingletonPaths(ctx).metadata
  281. b.buildRuleMergeCSV(ctx, "monolithic hidden API metadata", allMetadataFlagFiles, metadataCSV)
  282. // Generate an intermediate monolithic hiddenapi-index.csv file directly from the CSV files in the
  283. // classes jars.
  284. intermediateIndexCSV := android.PathForModuleOut(ctx, "hiddenapi-monolithic", "index-from-classes.csv")
  285. buildRuleToGenerateIndex(ctx, "intermediate hidden API index", classesJars, intermediateIndexCSV)
  286. // Generate the monolithic hiddenapi-index.csv file.
  287. //
  288. // Use index files generated directly from the classes jars as well as index files provided
  289. // by prebuilts.
  290. allIndexFlagFiles := android.Paths{intermediateIndexCSV}
  291. allIndexFlagFiles = append(allIndexFlagFiles, monolithicInfo.IndexPaths...)
  292. indexCSV := hiddenAPISingletonPaths(ctx).index
  293. b.buildRuleMergeCSV(ctx, "monolithic hidden API index", allIndexFlagFiles, indexCSV)
  294. return bootDexJarByModule
  295. }
  296. // createAndProvideMonolithicHiddenAPIInfo creates a MonolithicHiddenAPIInfo and provides it for
  297. // testing.
  298. func (b *platformBootclasspathModule) createAndProvideMonolithicHiddenAPIInfo(ctx android.ModuleContext, classpathElements ClasspathElements) MonolithicHiddenAPIInfo {
  299. // Create a temporary input structure in which to collate information provided directly by this
  300. // module, either through properties or direct dependencies.
  301. temporaryInput := newHiddenAPIFlagInput()
  302. // Create paths to the flag files specified in the properties.
  303. temporaryInput.extractFlagFilesFromProperties(ctx, &b.properties.HiddenAPIFlagFileProperties)
  304. // Create the monolithic info, by starting with the flag files specified on this and then merging
  305. // in information from all the fragment dependencies of this.
  306. monolithicInfo := newMonolithicHiddenAPIInfo(ctx, temporaryInput.FlagFilesByCategory, classpathElements)
  307. // Store the information for testing.
  308. ctx.SetProvider(MonolithicHiddenAPIInfoProvider, monolithicInfo)
  309. return monolithicInfo
  310. }
  311. func (b *platformBootclasspathModule) buildRuleMergeCSV(ctx android.ModuleContext, desc string, inputPaths android.Paths, outputPath android.WritablePath) {
  312. rule := android.NewRuleBuilder(pctx, ctx)
  313. rule.Command().
  314. BuiltTool("merge_csv").
  315. Flag("--key_field signature").
  316. FlagWithOutput("--output=", outputPath).
  317. Inputs(inputPaths)
  318. rule.Build(desc, desc)
  319. }
  320. // generateHiddenApiMakeVars generates make variables needed by hidden API related make rules, e.g.
  321. // veridex and run-appcompat.
  322. func (b *platformBootclasspathModule) generateHiddenApiMakeVars(ctx android.MakeVarsContext) {
  323. if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
  324. return
  325. }
  326. // INTERNAL_PLATFORM_HIDDENAPI_FLAGS is used by Make rules in art/ and cts/.
  327. ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_FLAGS", b.hiddenAPIFlagsCSV.String())
  328. }
  329. // generateBootImageBuildActions generates ninja rules related to the boot image creation.
  330. func (b *platformBootclasspathModule) generateBootImageBuildActions(ctx android.ModuleContext) {
  331. // Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars
  332. // GenerateSingletonBuildActions method as it cannot create it for itself.
  333. dexpreopt.GetGlobalSoongConfig(ctx)
  334. global := dexpreopt.GetGlobalConfig(ctx)
  335. if !shouldBuildBootImages(ctx.Config(), global) {
  336. return
  337. }
  338. frameworkBootImageConfig := defaultBootImageConfig(ctx)
  339. bootFrameworkProfileRule(ctx, frameworkBootImageConfig)
  340. b.generateBootImage(ctx, frameworkBootImageName)
  341. b.generateBootImage(ctx, mainlineBootImageName)
  342. dumpOatRules(ctx, frameworkBootImageConfig)
  343. }
  344. func (b *platformBootclasspathModule) generateBootImage(ctx android.ModuleContext, imageName string) {
  345. imageConfig := genBootImageConfigs(ctx)[imageName]
  346. modules := b.getModulesForImage(ctx, imageConfig)
  347. // Copy module dex jars to their predefined locations.
  348. bootDexJarsByModule := extractEncodedDexJarsFromModules(ctx, modules)
  349. copyBootJarsToPredefinedLocations(ctx, bootDexJarsByModule, imageConfig.dexPathsByModule)
  350. // Build a profile for the image config and then use that to build the boot image.
  351. profile := bootImageProfileRule(ctx, imageConfig)
  352. // If dexpreopt of boot image jars should be skipped, generate only a profile.
  353. global := dexpreopt.GetGlobalConfig(ctx)
  354. if global.DisablePreoptBootImages {
  355. return
  356. }
  357. // Build boot image files for the android variants.
  358. androidBootImageFiles := buildBootImageVariantsForAndroidOs(ctx, imageConfig, profile)
  359. // Zip the android variant boot image files up.
  360. buildBootImageZipInPredefinedLocation(ctx, imageConfig, androidBootImageFiles.byArch)
  361. // Build boot image files for the host variants. There are use directly by ART host side tests.
  362. buildBootImageVariantsForBuildOs(ctx, imageConfig, profile)
  363. }
  364. // Copy apex module dex jars to their predefined locations. They will be used for dexpreopt for apps.
  365. func (b *platformBootclasspathModule) copyApexBootJarsForAppsDexpreopt(ctx android.ModuleContext, apexModules []android.Module) {
  366. config := GetApexBootConfig(ctx)
  367. apexBootDexJarsByModule := extractEncodedDexJarsFromModules(ctx, apexModules)
  368. copyBootJarsToPredefinedLocations(ctx, apexBootDexJarsByModule, config.dexPathsByModule)
  369. }
  370. func (b *platformBootclasspathModule) getModulesForImage(ctx android.ModuleContext, imageConfig *bootImageConfig) []android.Module {
  371. modules := make([]android.Module, 0, imageConfig.modules.Len())
  372. for i := 0; i < imageConfig.modules.Len(); i++ {
  373. found := false
  374. for _, module := range b.configuredModules {
  375. name := android.RemoveOptionalPrebuiltPrefix(module.Name())
  376. if name == imageConfig.modules.Jar(i) {
  377. modules = append(modules, module)
  378. found = true
  379. break
  380. }
  381. }
  382. if !found && !ctx.Config().AllowMissingDependencies() {
  383. ctx.ModuleErrorf(
  384. "Boot image '%s' module '%s' not added as a dependency of platform_bootclasspath",
  385. imageConfig.name,
  386. imageConfig.modules.Jar(i))
  387. return []android.Module{}
  388. }
  389. }
  390. return modules
  391. }