dexpreopt_bootjars.go 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  1. // Copyright 2019 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. "path/filepath"
  17. "sort"
  18. "strings"
  19. "android/soong/android"
  20. "android/soong/dexpreopt"
  21. "github.com/google/blueprint/proptools"
  22. )
  23. // =================================================================================================
  24. // WIP - see http://b/177892522 for details
  25. //
  26. // The build support for boot images is currently being migrated away from singleton to modules so
  27. // the documentation may not be strictly accurate. Rather than update the documentation at every
  28. // step which will create a lot of churn the changes that have been made will be listed here and the
  29. // documentation will be updated once it is closer to the final result.
  30. //
  31. // Changes:
  32. // 1) dex_bootjars is now a singleton module and not a plain singleton.
  33. // 2) Boot images are now represented by the boot_image module type.
  34. // 3) The art boot image is called "art-boot-image", the framework boot image is called
  35. // "framework-boot-image".
  36. // 4) They are defined in art/build/boot/Android.bp and frameworks/base/boot/Android.bp
  37. // respectively.
  38. // 5) Each boot_image retrieves the appropriate boot image configuration from the map returned by
  39. // genBootImageConfigs() using the image_name specified in the boot_image module.
  40. // =================================================================================================
  41. // This comment describes:
  42. // 1. ART boot images in general (their types, structure, file layout, etc.)
  43. // 2. build system support for boot images
  44. //
  45. // 1. ART boot images
  46. // ------------------
  47. //
  48. // A boot image in ART is a set of files that contain AOT-compiled native code and a heap snapshot
  49. // of AOT-initialized classes for the bootclasspath Java libraries. A boot image is compiled from a
  50. // set of DEX jars by the dex2oat compiler. A boot image is used for two purposes: 1) it is
  51. // installed on device and loaded at runtime, and 2) other Java libraries and apps are compiled
  52. // against it (compilation may take place either on host, known as "dexpreopt", or on device, known
  53. // as "dexopt").
  54. //
  55. // A boot image is not a single file, but a collection of interrelated files. Each boot image has a
  56. // number of components that correspond to the Java libraries that constitute it. For each component
  57. // there are multiple files:
  58. // - *.oat or *.odex file with native code (architecture-specific, one per instruction set)
  59. // - *.art file with pre-initialized Java classes (architecture-specific, one per instruction set)
  60. // - *.vdex file with verification metadata for the DEX bytecode (architecture independent)
  61. //
  62. // *.vdex files for the boot images do not contain the DEX bytecode itself, because the
  63. // bootclasspath DEX files are stored on disk in uncompressed and aligned form. Consequently a boot
  64. // image is not self-contained and cannot be used without its DEX files. To simplify the management
  65. // of boot image files, ART uses a certain naming scheme and associates the following metadata with
  66. // each boot image:
  67. // - A stem, which is a symbolic name that is prepended to boot image file names.
  68. // - A location (on-device path to the boot image files).
  69. // - A list of boot image locations (on-device paths to dependency boot images).
  70. // - A set of DEX locations (on-device paths to the DEX files, one location for one DEX file used
  71. // to compile the boot image).
  72. //
  73. // There are two kinds of boot images:
  74. // - primary boot images
  75. // - boot image extensions
  76. //
  77. // 1.1. Primary boot images
  78. // ------------------------
  79. //
  80. // A primary boot image is compiled for a core subset of bootclasspath Java libraries. It does not
  81. // depend on any other images, and other boot images may depend on it.
  82. //
  83. // For example, assuming that the stem is "boot", the location is /apex/com.android.art/javalib/,
  84. // the set of core bootclasspath libraries is A B C, and the boot image is compiled for ARM targets
  85. // (32 and 64 bits), it will have three components with the following files:
  86. // - /apex/com.android.art/javalib/{arm,arm64}/boot.{art,oat,vdex}
  87. // - /apex/com.android.art/javalib/{arm,arm64}/boot-B.{art,oat,vdex}
  88. // - /apex/com.android.art/javalib/{arm,arm64}/boot-C.{art,oat,vdex}
  89. //
  90. // The files of the first component are special: they do not have the component name appended after
  91. // the stem. This naming convention dates back to the times when the boot image was not split into
  92. // components, and there were just boot.oat and boot.art. The decision to split was motivated by
  93. // licensing reasons for one of the bootclasspath libraries.
  94. //
  95. // As of November 2020 the only primary boot image in Android is the image in the ART APEX
  96. // com.android.art. The primary ART boot image contains the Core libraries that are part of the ART
  97. // module. When the ART module gets updated, the primary boot image will be updated with it, and all
  98. // dependent images will get invalidated (the checksum of the primary image stored in dependent
  99. // images will not match), unless they are updated in sync with the ART module.
  100. //
  101. // 1.2. Boot image extensions
  102. // --------------------------
  103. //
  104. // A boot image extension is compiled for a subset of bootclasspath Java libraries (in particular,
  105. // this subset does not include the Core bootclasspath libraries that go into the primary boot
  106. // image). A boot image extension depends on the primary boot image and optionally some other boot
  107. // image extensions. Other images may depend on it. In other words, boot image extensions can form
  108. // acyclic dependency graphs.
  109. //
  110. // The motivation for boot image extensions comes from the Mainline project. Consider a situation
  111. // when the list of bootclasspath libraries is A B C, and both A and B are parts of the Android
  112. // platform, but C is part of an updatable APEX com.android.C. When the APEX is updated, the Java
  113. // code for C might have changed compared to the code that was used to compile the boot image.
  114. // Consequently, the whole boot image is obsolete and invalidated (even though the code for A and B
  115. // that does not depend on C is up to date). To avoid this, the original monolithic boot image is
  116. // split in two parts: the primary boot image that contains A B, and the boot image extension that
  117. // contains C and depends on the primary boot image (extends it).
  118. //
  119. // For example, assuming that the stem is "boot", the location is /system/framework, the set of
  120. // bootclasspath libraries is D E (where D is part of the platform and is located in
  121. // /system/framework, and E is part of a non-updatable APEX com.android.E and is located in
  122. // /apex/com.android.E/javalib), and the boot image is compiled for ARM targets (32 and 64 bits),
  123. // it will have two components with the following files:
  124. // - /system/framework/{arm,arm64}/boot-D.{art,oat,vdex}
  125. // - /system/framework/{arm,arm64}/boot-E.{art,oat,vdex}
  126. //
  127. // As of November 2020 the only boot image extension in Android is the Framework boot image
  128. // extension. It extends the primary ART boot image and contains Framework libraries and other
  129. // bootclasspath libraries from the platform and non-updatable APEXes that are not included in the
  130. // ART image. The Framework boot image extension is updated together with the platform. In the
  131. // future other boot image extensions may be added for some updatable modules.
  132. //
  133. //
  134. // 2. Build system support for boot images
  135. // ---------------------------------------
  136. //
  137. // The primary ART boot image needs to be compiled with one dex2oat invocation that depends on DEX
  138. // jars for the core libraries. Framework boot image extension needs to be compiled with one dex2oat
  139. // invocation that depends on the primary ART boot image and all bootclasspath DEX jars except the
  140. // core libraries as they are already part of the primary ART boot image.
  141. //
  142. // 2.1. Libraries that go in the boot images
  143. // -----------------------------------------
  144. //
  145. // The contents of each boot image are determined by the PRODUCT variables. The primary ART APEX
  146. // boot image contains libraries listed in the ART_APEX_JARS variable in the AOSP makefiles. The
  147. // Framework boot image extension contains libraries specified in the PRODUCT_BOOT_JARS and
  148. // PRODUCT_BOOT_JARS_EXTRA variables. The AOSP makefiles specify some common Framework libraries,
  149. // but more product-specific libraries can be added in the product makefiles.
  150. //
  151. // Each component of the PRODUCT_BOOT_JARS and PRODUCT_BOOT_JARS_EXTRA variables is a
  152. // colon-separated pair <apex>:<library>, where <apex> is the variant name of a non-updatable APEX,
  153. // "platform" if the library is a part of the platform in the system partition, or "system_ext" if
  154. // it's in the system_ext partition.
  155. //
  156. // In these variables APEXes are identified by their "variant names", i.e. the names they get
  157. // mounted as in /apex on device. In Soong modules that is the name set in the "apex_name"
  158. // properties, which default to the "name" values. For example, many APEXes have both
  159. // com.android.xxx and com.google.android.xxx modules in Soong, but take the same place
  160. // /apex/com.android.xxx at runtime. In these cases the variant name is always com.android.xxx,
  161. // regardless which APEX goes into the product. See also android.ApexInfo.ApexVariationName and
  162. // apex.apexBundleProperties.Apex_name.
  163. //
  164. // A related variable PRODUCT_APEX_BOOT_JARS contains bootclasspath libraries that are in APEXes.
  165. // They are not included in the boot image. The only exception here are ART jars and core-icu4j.jar
  166. // that have been historically part of the boot image and are now in apexes; they are in boot images
  167. // and core-icu4j.jar is generally treated as being part of PRODUCT_BOOT_JARS.
  168. //
  169. // One exception to the above rules are "coverage" builds (a special build flavor which requires
  170. // setting environment variable EMMA_INSTRUMENT_FRAMEWORK=true). In coverage builds the Java code in
  171. // boot image libraries is instrumented, which means that the instrumentation library (jacocoagent)
  172. // needs to be added to the list of bootclasspath DEX jars.
  173. //
  174. // In general, there is a requirement that the source code for a boot image library must be
  175. // available at build time (e.g. it cannot be a stub that has a separate implementation library).
  176. //
  177. // 2.2. Static configs
  178. // -------------------
  179. //
  180. // Because boot images are used to dexpreopt other Java modules, the paths to boot image files must
  181. // be known by the time dexpreopt build rules for the dependent modules are generated. Boot image
  182. // configs are constructed very early during the build, before build rule generation. The configs
  183. // provide predefined paths to boot image files (these paths depend only on static build
  184. // configuration, such as PRODUCT variables, and use hard-coded directory names).
  185. //
  186. // 2.3. Singleton
  187. // --------------
  188. //
  189. // Build rules for the boot images are generated with a Soong singleton. Because a singleton has no
  190. // dependencies on other modules, it has to find the modules for the DEX jars using VisitAllModules.
  191. // Soong loops through all modules and compares each module against a list of bootclasspath library
  192. // names. Then it generates build rules that copy DEX jars from their intermediate module-specific
  193. // locations to the hard-coded locations predefined in the boot image configs.
  194. //
  195. // It would be possible to use a module with proper dependencies instead, but that would require
  196. // changes in the way Soong generates variables for Make: a singleton can use one MakeVars() method
  197. // that writes variables to out/soong/make_vars-*.mk, which is included early by the main makefile,
  198. // but module(s) would have to use out/soong/Android-*.mk which has a group of LOCAL_* variables
  199. // for each module, and is included later.
  200. //
  201. // 2.4. Install rules
  202. // ------------------
  203. //
  204. // The primary boot image and the Framework extension are installed in different ways. The primary
  205. // boot image is part of the ART APEX: it is copied into the APEX intermediate files, packaged
  206. // together with other APEX contents, extracted and mounted on device. The Framework boot image
  207. // extension is installed by the rules defined in makefiles (make/core/dex_preopt_libart.mk). Soong
  208. // writes out a few DEXPREOPT_IMAGE_* variables for Make; these variables contain boot image names,
  209. // paths and so on.
  210. //
  211. var artApexNames = []string{
  212. "com.android.art",
  213. "com.android.art.debug",
  214. "com.android.art.testing",
  215. "com.google.android.art",
  216. "com.google.android.art.debug",
  217. "com.google.android.art.testing",
  218. }
  219. func init() {
  220. RegisterDexpreoptBootJarsComponents(android.InitRegistrationContext)
  221. }
  222. // Target-independent description of a boot image.
  223. //
  224. // WARNING: All fields in this struct should be initialized in the genBootImageConfigs function.
  225. // Failure to do so can lead to data races if there is no synchronization enforced ordering between
  226. // the writer and the reader. Fields which break this rule are marked as deprecated and should be
  227. // removed and replaced with something else, e.g. providers.
  228. type bootImageConfig struct {
  229. // If this image is an extension, the image that it extends.
  230. extends *bootImageConfig
  231. // Image name (used in directory names and ninja rule names).
  232. name string
  233. // Basename of the image: the resulting filenames are <stem>[-<jar>].{art,oat,vdex}.
  234. stem string
  235. // Output directory for the image files.
  236. dir android.OutputPath
  237. // Output directory for the image files with debug symbols.
  238. symbolsDir android.OutputPath
  239. // The relative location where the image files are installed. On host, the location is relative to
  240. // $ANDROID_PRODUCT_OUT.
  241. //
  242. // Only the configs that are built by platform_bootclasspath are installable on device. On device,
  243. // the location is relative to "/".
  244. installDir string
  245. // Install path of the boot image profile if it needs to be installed in the APEX, or empty if not
  246. // needed.
  247. profileInstallPathInApex string
  248. // A list of (location, jar) pairs for the Java modules in this image.
  249. modules android.ConfiguredJarList
  250. // File paths to jars.
  251. dexPaths android.WritablePaths // for this image
  252. dexPathsDeps android.WritablePaths // for the dependency images and in this image
  253. // Map from module name (without prebuilt_ prefix) to the predefined build path.
  254. dexPathsByModule map[string]android.WritablePath
  255. // File path to a zip archive with all image files (or nil, if not needed).
  256. zip android.WritablePath
  257. // Rules which should be used in make to install the outputs.
  258. //
  259. // Deprecated: Not initialized correctly, see struct comment.
  260. profileInstalls android.RuleBuilderInstalls
  261. // Path to the license metadata file for the module that built the profile.
  262. //
  263. // Deprecated: Not initialized correctly, see struct comment.
  264. profileLicenseMetadataFile android.OptionalPath
  265. // Target-dependent fields.
  266. variants []*bootImageVariant
  267. // Path of the preloaded classes file.
  268. preloadedClassesFile string
  269. // The "--compiler-filter" argument.
  270. compilerFilter string
  271. // The "--single-image" argument.
  272. singleImage bool
  273. // Profiles imported from other boot image configs. Each element must represent a
  274. // `bootclasspath_fragment` of an APEX (i.e., the `name` field of each element must refer to the
  275. // `image_name` property of a `bootclasspath_fragment`).
  276. profileImports []*bootImageConfig
  277. }
  278. // Target-dependent description of a boot image.
  279. //
  280. // WARNING: The warning comment on bootImageConfig applies here too.
  281. type bootImageVariant struct {
  282. *bootImageConfig
  283. // Target for which the image is generated.
  284. target android.Target
  285. // The "locations" of jars.
  286. dexLocations []string // for this image
  287. dexLocationsDeps []string // for the dependency images and in this image
  288. // Paths to image files.
  289. imagePathOnHost android.OutputPath // first image file path on host
  290. imagePathOnDevice string // first image file path on device
  291. // All the files that constitute this image variant, i.e. .art, .oat and .vdex files.
  292. imagesDeps android.OutputPaths
  293. // The path to the base image variant's imagePathOnHost field, where base image variant
  294. // means the image variant that this extends.
  295. //
  296. // This is only set for a variant of an image that extends another image.
  297. baseImages android.OutputPaths
  298. // The paths to the base image variant's imagesDeps field, where base image variant
  299. // means the image variant that this extends.
  300. //
  301. // This is only set for a variant of an image that extends another image.
  302. baseImagesDeps android.Paths
  303. // Rules which should be used in make to install the outputs on host.
  304. //
  305. // Deprecated: Not initialized correctly, see struct comment.
  306. installs android.RuleBuilderInstalls
  307. // Rules which should be used in make to install the vdex outputs on host.
  308. //
  309. // Deprecated: Not initialized correctly, see struct comment.
  310. vdexInstalls android.RuleBuilderInstalls
  311. // Rules which should be used in make to install the unstripped outputs on host.
  312. //
  313. // Deprecated: Not initialized correctly, see struct comment.
  314. unstrippedInstalls android.RuleBuilderInstalls
  315. // Path to the license metadata file for the module that built the image.
  316. //
  317. // Deprecated: Not initialized correctly, see struct comment.
  318. licenseMetadataFile android.OptionalPath
  319. }
  320. // Get target-specific boot image variant for the given boot image config and target.
  321. func (image bootImageConfig) getVariant(target android.Target) *bootImageVariant {
  322. for _, variant := range image.variants {
  323. if variant.target.Os == target.Os && variant.target.Arch.ArchType == target.Arch.ArchType {
  324. return variant
  325. }
  326. }
  327. return nil
  328. }
  329. // Return any (the first) variant which is for the device (as opposed to for the host).
  330. func (image bootImageConfig) getAnyAndroidVariant() *bootImageVariant {
  331. for _, variant := range image.variants {
  332. if variant.target.Os == android.Android {
  333. return variant
  334. }
  335. }
  336. return nil
  337. }
  338. // Return the name of a boot image module given a boot image config and a component (module) index.
  339. // A module name is a combination of the Java library name, and the boot image stem (that is stored
  340. // in the config).
  341. func (image bootImageConfig) moduleName(ctx android.PathContext, idx int) string {
  342. // The first module of the primary boot image is special: its module name has only the stem, but
  343. // not the library name. All other module names are of the form <stem>-<library name>
  344. m := image.modules.Jar(idx)
  345. name := image.stem
  346. if idx != 0 || image.extends != nil {
  347. name += "-" + android.ModuleStem(m)
  348. }
  349. return name
  350. }
  351. // Return the name of the first boot image module, or stem if the list of modules is empty.
  352. func (image bootImageConfig) firstModuleNameOrStem(ctx android.PathContext) string {
  353. if image.modules.Len() > 0 {
  354. return image.moduleName(ctx, 0)
  355. } else {
  356. return image.stem
  357. }
  358. }
  359. // Return filenames for the given boot image component, given the output directory and a list of
  360. // extensions.
  361. func (image bootImageConfig) moduleFiles(ctx android.PathContext, dir android.OutputPath, exts ...string) android.OutputPaths {
  362. ret := make(android.OutputPaths, 0, image.modules.Len()*len(exts))
  363. for i := 0; i < image.modules.Len(); i++ {
  364. name := image.moduleName(ctx, i)
  365. for _, ext := range exts {
  366. ret = append(ret, dir.Join(ctx, name+ext))
  367. }
  368. if image.singleImage {
  369. break
  370. }
  371. }
  372. return ret
  373. }
  374. // apexVariants returns a list of all *bootImageVariant that could be included in an apex.
  375. func (image *bootImageConfig) apexVariants() []*bootImageVariant {
  376. variants := []*bootImageVariant{}
  377. for _, variant := range image.variants {
  378. // We also generate boot images for host (for testing), but we don't need those in the apex.
  379. // TODO(b/177892522) - consider changing this to check Os.OsClass = android.Device
  380. if variant.target.Os == android.Android {
  381. variants = append(variants, variant)
  382. }
  383. }
  384. return variants
  385. }
  386. // Return boot image locations (as a list of symbolic paths).
  387. //
  388. // The image "location" is a symbolic path that, with multiarchitecture support, doesn't really
  389. // exist on the device. Typically it is /apex/com.android.art/javalib/boot.art and should be the
  390. // same for all supported architectures on the device. The concrete architecture specific files
  391. // actually end up in architecture-specific sub-directory such as arm, arm64, x86, or x86_64.
  392. //
  393. // For example a physical file /apex/com.android.art/javalib/x86/boot.art has "image location"
  394. // /apex/com.android.art/javalib/boot.art (which is not an actual file).
  395. //
  396. // For a primary boot image the list of locations has a single element.
  397. //
  398. // For a boot image extension the list of locations contains a location for all dependency images
  399. // (including the primary image) and the location of the extension itself. For example, for the
  400. // Framework boot image extension that depends on the primary ART boot image the list contains two
  401. // elements.
  402. //
  403. // The location is passed as an argument to the ART tools like dex2oat instead of the real path.
  404. // ART tools will then reconstruct the architecture-specific real path.
  405. func (image *bootImageVariant) imageLocations() (imageLocationsOnHost []string, imageLocationsOnDevice []string) {
  406. if image.extends != nil {
  407. imageLocationsOnHost, imageLocationsOnDevice = image.extends.getVariant(image.target).imageLocations()
  408. }
  409. return append(imageLocationsOnHost, dexpreopt.PathToLocation(image.imagePathOnHost, image.target.Arch.ArchType)),
  410. append(imageLocationsOnDevice, dexpreopt.PathStringToLocation(image.imagePathOnDevice, image.target.Arch.ArchType))
  411. }
  412. func (image *bootImageConfig) isProfileGuided() bool {
  413. return image.compilerFilter == "speed-profile"
  414. }
  415. func dexpreoptBootJarsFactory() android.SingletonModule {
  416. m := &dexpreoptBootJars{}
  417. android.InitAndroidModule(m)
  418. return m
  419. }
  420. func RegisterDexpreoptBootJarsComponents(ctx android.RegistrationContext) {
  421. ctx.RegisterParallelSingletonModuleType("dex_bootjars", dexpreoptBootJarsFactory)
  422. }
  423. func SkipDexpreoptBootJars(ctx android.PathContext) bool {
  424. return dexpreopt.GetGlobalConfig(ctx).DisablePreoptBootImages
  425. }
  426. // Singleton module for generating boot image build rules.
  427. type dexpreoptBootJars struct {
  428. android.SingletonModuleBase
  429. // Default boot image config (currently always the Framework boot image extension). It should be
  430. // noted that JIT-Zygote builds use ART APEX image instead of the Framework boot image extension,
  431. // but the switch is handled not here, but in the makefiles (triggered with
  432. // DEXPREOPT_USE_ART_IMAGE=true).
  433. defaultBootImage *bootImageConfig
  434. // Other boot image configs (currently the list contains only the primary ART APEX image. It
  435. // used to contain an experimental JIT-Zygote image (now replaced with the ART APEX image). In
  436. // the future other boot image extensions may be added.
  437. otherImages []*bootImageConfig
  438. // Build path to a config file that Soong writes for Make (to be used in makefiles that install
  439. // the default boot image).
  440. dexpreoptConfigForMake android.WritablePath
  441. }
  442. // Provide paths to boot images for use by modules that depend upon them.
  443. //
  444. // The build rules are created in GenerateSingletonBuildActions().
  445. func (d *dexpreoptBootJars) GenerateAndroidBuildActions(ctx android.ModuleContext) {
  446. // Placeholder for now.
  447. }
  448. // Generate build rules for boot images.
  449. func (d *dexpreoptBootJars) GenerateSingletonBuildActions(ctx android.SingletonContext) {
  450. if dexpreopt.GetCachedGlobalSoongConfig(ctx) == nil {
  451. // No module has enabled dexpreopting, so we assume there will be no boot image to make.
  452. return
  453. }
  454. archType := ctx.Config().Targets[android.Android][0].Arch.ArchType
  455. d.dexpreoptConfigForMake = android.PathForOutput(ctx, toDexpreoptDirName(archType), "dexpreopt.config")
  456. writeGlobalConfigForMake(ctx, d.dexpreoptConfigForMake)
  457. global := dexpreopt.GetGlobalConfig(ctx)
  458. if !shouldBuildBootImages(ctx.Config(), global) {
  459. return
  460. }
  461. defaultImageConfig := defaultBootImageConfig(ctx)
  462. d.defaultBootImage = defaultImageConfig
  463. imageConfigs := genBootImageConfigs(ctx)
  464. d.otherImages = make([]*bootImageConfig, 0, len(imageConfigs)-1)
  465. for _, config := range imageConfigs {
  466. if config != defaultImageConfig {
  467. d.otherImages = append(d.otherImages, config)
  468. }
  469. }
  470. }
  471. // shouldBuildBootImages determines whether boot images should be built.
  472. func shouldBuildBootImages(config android.Config, global *dexpreopt.GlobalConfig) bool {
  473. // Skip recompiling the boot image for the second sanitization phase. We'll get separate paths
  474. // and invalidate first-stage artifacts which are crucial to SANITIZE_LITE builds.
  475. // Note: this is technically incorrect. Compiled code contains stack checks which may depend
  476. // on ASAN settings.
  477. if len(config.SanitizeDevice()) == 1 && config.SanitizeDevice()[0] == "address" && global.SanitizeLite {
  478. return false
  479. }
  480. return true
  481. }
  482. // copyBootJarsToPredefinedLocations generates commands that will copy boot jars to predefined
  483. // paths in the global config.
  484. func copyBootJarsToPredefinedLocations(ctx android.ModuleContext, srcBootDexJarsByModule bootDexJarByModule, dstBootJarsByModule map[string]android.WritablePath) {
  485. // Create the super set of module names.
  486. names := []string{}
  487. names = append(names, android.SortedKeys(srcBootDexJarsByModule)...)
  488. names = append(names, android.SortedKeys(dstBootJarsByModule)...)
  489. names = android.SortedUniqueStrings(names)
  490. for _, name := range names {
  491. src := srcBootDexJarsByModule[name]
  492. dst := dstBootJarsByModule[name]
  493. if src == nil {
  494. // A dex boot jar should be provided by the source java module. It needs to be installable or
  495. // have compile_dex=true - cf. assignments to java.Module.dexJarFile.
  496. //
  497. // However, the source java module may be either replaced or overridden (using prefer:true) by
  498. // a prebuilt java module with the same name. In that case the dex boot jar needs to be
  499. // provided by the corresponding prebuilt APEX module. That APEX is the one that refers
  500. // through a exported_(boot|systemserver)classpath_fragments property to a
  501. // prebuilt_(boot|systemserver)classpath_fragment module, which in turn lists the prebuilt
  502. // java module in the contents property. If that chain is broken then this dependency will
  503. // fail.
  504. if !ctx.Config().AllowMissingDependencies() {
  505. ctx.ModuleErrorf("module %s does not provide a dex boot jar (see comment next to this message in Soong for details)", name)
  506. } else {
  507. ctx.AddMissingDependencies([]string{name})
  508. }
  509. } else if dst == nil {
  510. ctx.ModuleErrorf("module %s is not part of the boot configuration", name)
  511. } else {
  512. ctx.Build(pctx, android.BuildParams{
  513. Rule: android.Cp,
  514. Input: src,
  515. Output: dst,
  516. })
  517. }
  518. }
  519. }
  520. // buildBootImageVariantsForAndroidOs generates rules to build the boot image variants for the
  521. // android.Android OsType and returns a map from the architectures to the paths of the generated
  522. // boot image files.
  523. //
  524. // The paths are returned because they are needed elsewhere in Soong, e.g. for populating an APEX.
  525. func buildBootImageVariantsForAndroidOs(ctx android.ModuleContext, image *bootImageConfig, profile android.WritablePath) bootImageOutputs {
  526. return buildBootImageForOsType(ctx, image, profile, android.Android)
  527. }
  528. // buildBootImageVariantsForBuildOs generates rules to build the boot image variants for the
  529. // config.BuildOS OsType, i.e. the type of OS on which the build is being running.
  530. //
  531. // The files need to be generated into their predefined location because they are used from there
  532. // both within Soong and outside, e.g. for ART based host side testing and also for use by some
  533. // cloud based tools. However, they are not needed by callers of this function and so the paths do
  534. // not need to be returned from this func, unlike the buildBootImageVariantsForAndroidOs func.
  535. func buildBootImageVariantsForBuildOs(ctx android.ModuleContext, image *bootImageConfig, profile android.WritablePath) {
  536. buildBootImageForOsType(ctx, image, profile, ctx.Config().BuildOS)
  537. }
  538. // bootImageFilesByArch is a map from android.ArchType to the paths to the boot image files.
  539. //
  540. // The paths include the .art, .oat and .vdex files, one for each of the modules from which the boot
  541. // image is created.
  542. type bootImageFilesByArch map[android.ArchType]android.Paths
  543. // bootImageOutputs encapsulates information about boot images that were created/obtained by
  544. // commonBootclasspathFragment.produceBootImageFiles.
  545. type bootImageOutputs struct {
  546. // Map from arch to the paths to the boot image files created/obtained for that arch.
  547. byArch bootImageFilesByArch
  548. variants []bootImageVariantOutputs
  549. // The path to the profile file created/obtained for the boot image.
  550. profile android.WritablePath
  551. }
  552. // buildBootImageForOsType takes a bootImageConfig, a profile file and an android.OsType
  553. // boot image files are required for and it creates rules to build the boot image
  554. // files for all the required architectures for them.
  555. //
  556. // It returns a map from android.ArchType to the predefined paths of the boot image files.
  557. func buildBootImageForOsType(ctx android.ModuleContext, image *bootImageConfig, profile android.WritablePath, requiredOsType android.OsType) bootImageOutputs {
  558. filesByArch := bootImageFilesByArch{}
  559. imageOutputs := bootImageOutputs{
  560. byArch: filesByArch,
  561. profile: profile,
  562. }
  563. for _, variant := range image.variants {
  564. if variant.target.Os == requiredOsType {
  565. variantOutputs := buildBootImageVariant(ctx, variant, profile)
  566. imageOutputs.variants = append(imageOutputs.variants, variantOutputs)
  567. filesByArch[variant.target.Arch.ArchType] = variant.imagesDeps.Paths()
  568. }
  569. }
  570. return imageOutputs
  571. }
  572. // buildBootImageZipInPredefinedLocation generates a zip file containing all the boot image files.
  573. //
  574. // The supplied filesByArch is nil when the boot image files have not been generated. Otherwise, it
  575. // is a map from android.ArchType to the predefined locations.
  576. func buildBootImageZipInPredefinedLocation(ctx android.ModuleContext, image *bootImageConfig, filesByArch bootImageFilesByArch) {
  577. if filesByArch == nil {
  578. return
  579. }
  580. // Compute the list of files from all the architectures.
  581. zipFiles := android.Paths{}
  582. for _, archType := range android.ArchTypeList() {
  583. zipFiles = append(zipFiles, filesByArch[archType]...)
  584. }
  585. rule := android.NewRuleBuilder(pctx, ctx)
  586. rule.Command().
  587. BuiltTool("soong_zip").
  588. FlagWithOutput("-o ", image.zip).
  589. FlagWithArg("-C ", image.dir.Join(ctx, android.Android.String()).String()).
  590. FlagWithInputList("-f ", zipFiles, " -f ")
  591. rule.Build("zip_"+image.name, "zip "+image.name+" image")
  592. }
  593. type bootImageVariantOutputs struct {
  594. config *bootImageVariant
  595. }
  596. // Generate boot image build rules for a specific target.
  597. func buildBootImageVariant(ctx android.ModuleContext, image *bootImageVariant, profile android.Path) bootImageVariantOutputs {
  598. globalSoong := dexpreopt.GetGlobalSoongConfig(ctx)
  599. global := dexpreopt.GetGlobalConfig(ctx)
  600. arch := image.target.Arch.ArchType
  601. os := image.target.Os.String() // We need to distinguish host-x86 and device-x86.
  602. symbolsDir := image.symbolsDir.Join(ctx, os, image.installDir, arch.String())
  603. symbolsFile := symbolsDir.Join(ctx, image.stem+".oat")
  604. outputDir := image.dir.Join(ctx, os, image.installDir, arch.String())
  605. outputPath := outputDir.Join(ctx, image.stem+".oat")
  606. oatLocation := dexpreopt.PathToLocation(outputPath, arch)
  607. imagePath := outputPath.ReplaceExtension(ctx, "art")
  608. rule := android.NewRuleBuilder(pctx, ctx)
  609. rule.Command().Text("mkdir").Flag("-p").Flag(symbolsDir.String())
  610. rule.Command().Text("rm").Flag("-f").
  611. Flag(symbolsDir.Join(ctx, "*.art").String()).
  612. Flag(symbolsDir.Join(ctx, "*.oat").String()).
  613. Flag(symbolsDir.Join(ctx, "*.invocation").String())
  614. rule.Command().Text("rm").Flag("-f").
  615. Flag(outputDir.Join(ctx, "*.art").String()).
  616. Flag(outputDir.Join(ctx, "*.oat").String()).
  617. Flag(outputDir.Join(ctx, "*.invocation").String())
  618. cmd := rule.Command()
  619. extraFlags := ctx.Config().Getenv("ART_BOOT_IMAGE_EXTRA_ARGS")
  620. if extraFlags == "" {
  621. // Use ANDROID_LOG_TAGS to suppress most logging by default...
  622. cmd.Text(`ANDROID_LOG_TAGS="*:e"`)
  623. } else {
  624. // ...unless the boot image is generated specifically for testing, then allow all logging.
  625. cmd.Text(`ANDROID_LOG_TAGS="*:v"`)
  626. }
  627. invocationPath := outputPath.ReplaceExtension(ctx, "invocation")
  628. cmd.Tool(globalSoong.Dex2oat).
  629. Flag("--avoid-storing-invocation").
  630. FlagWithOutput("--write-invocation-to=", invocationPath).ImplicitOutput(invocationPath).
  631. Flag("--runtime-arg").FlagWithArg("-Xms", global.Dex2oatImageXms).
  632. Flag("--runtime-arg").FlagWithArg("-Xmx", global.Dex2oatImageXmx)
  633. if profile != nil {
  634. cmd.FlagWithInput("--profile-file=", profile)
  635. }
  636. fragments := make(map[string]commonBootclasspathFragment)
  637. ctx.VisitDirectDepsWithTag(bootclasspathFragmentDepTag, func(child android.Module) {
  638. fragment := child.(commonBootclasspathFragment)
  639. if fragment.getImageName() != nil && android.IsModulePreferred(child) {
  640. fragments[*fragment.getImageName()] = fragment
  641. }
  642. })
  643. for _, profileImport := range image.profileImports {
  644. fragment := fragments[profileImport.name]
  645. if fragment == nil {
  646. ctx.ModuleErrorf("Boot image config '%[1]s' imports profile from '%[2]s', but a "+
  647. "bootclasspath_fragment with image name '%[2]s' doesn't exist or is not added as a "+
  648. "dependency of '%[1]s'",
  649. image.name,
  650. profileImport.name)
  651. return bootImageVariantOutputs{}
  652. }
  653. if fragment.getProfilePath() == nil {
  654. ctx.ModuleErrorf("Boot image config '%[1]s' imports profile from '%[2]s', but '%[2]s' "+
  655. "doesn't provide a profile",
  656. image.name,
  657. profileImport.name)
  658. return bootImageVariantOutputs{}
  659. }
  660. cmd.FlagWithInput("--profile-file=", fragment.getProfilePath())
  661. }
  662. dirtyImageFile := "frameworks/base/config/dirty-image-objects"
  663. dirtyImagePath := android.ExistentPathForSource(ctx, dirtyImageFile)
  664. if dirtyImagePath.Valid() {
  665. cmd.FlagWithInput("--dirty-image-objects=", dirtyImagePath.Path())
  666. }
  667. if image.extends != nil {
  668. // It is a boot image extension, so it needs the boot images that it depends on.
  669. baseImageLocations := make([]string, 0, len(image.baseImages))
  670. for _, image := range image.baseImages {
  671. baseImageLocations = append(baseImageLocations, dexpreopt.PathToLocation(image, arch))
  672. }
  673. cmd.
  674. Flag("--runtime-arg").FlagWithInputList("-Xbootclasspath:", image.dexPathsDeps.Paths(), ":").
  675. Flag("--runtime-arg").FlagWithList("-Xbootclasspath-locations:", image.dexLocationsDeps, ":").
  676. // Add the path to the first file in the boot image with the arch specific directory removed,
  677. // dex2oat will reconstruct the path to the actual file when it needs it. As the actual path
  678. // to the file cannot be passed to the command make sure to add the actual path as an Implicit
  679. // dependency to ensure that it is built before the command runs.
  680. FlagWithList("--boot-image=", baseImageLocations, ":").Implicits(image.baseImages.Paths()).
  681. // Similarly, the dex2oat tool will automatically find the paths to other files in the base
  682. // boot image so make sure to add them as implicit dependencies to ensure that they are built
  683. // before this command is run.
  684. Implicits(image.baseImagesDeps)
  685. } else {
  686. // It is a primary image, so it needs a base address.
  687. cmd.FlagWithArg("--base=", ctx.Config().LibartImgDeviceBaseAddress())
  688. }
  689. if len(image.preloadedClassesFile) > 0 {
  690. // We always expect a preloaded classes file to be available. However, if we cannot find it, it's
  691. // OK to not pass the flag to dex2oat.
  692. preloadedClassesPath := android.ExistentPathForSource(ctx, image.preloadedClassesFile)
  693. if preloadedClassesPath.Valid() {
  694. cmd.FlagWithInput("--preloaded-classes=", preloadedClassesPath.Path())
  695. }
  696. }
  697. cmd.
  698. FlagForEachInput("--dex-file=", image.dexPaths.Paths()).
  699. FlagForEachArg("--dex-location=", image.dexLocations).
  700. Flag("--generate-debug-info").
  701. Flag("--generate-build-id").
  702. Flag("--image-format=lz4hc").
  703. FlagWithArg("--oat-symbols=", symbolsFile.String()).
  704. Flag("--strip").
  705. FlagWithArg("--oat-file=", outputPath.String()).
  706. FlagWithArg("--oat-location=", oatLocation).
  707. FlagWithArg("--image=", imagePath.String()).
  708. FlagWithArg("--instruction-set=", arch.String()).
  709. FlagWithArg("--android-root=", global.EmptyDirectory).
  710. FlagWithArg("--no-inline-from=", "core-oj.jar").
  711. Flag("--force-determinism").
  712. Flag("--abort-on-hard-verifier-error")
  713. // If the image is profile-guided but the profile is disabled, we omit "--compiler-filter" to
  714. // leave the decision to dex2oat to pick the compiler filter.
  715. if !(image.isProfileGuided() && global.DisableGenerateProfile) {
  716. cmd.FlagWithArg("--compiler-filter=", image.compilerFilter)
  717. }
  718. if image.singleImage {
  719. cmd.Flag("--single-image")
  720. }
  721. // Use the default variant/features for host builds.
  722. // The map below contains only device CPU info (which might be x86 on some devices).
  723. if image.target.Os == android.Android {
  724. cmd.FlagWithArg("--instruction-set-variant=", global.CpuVariant[arch])
  725. cmd.FlagWithArg("--instruction-set-features=", global.InstructionSetFeatures[arch])
  726. }
  727. if global.EnableUffdGc {
  728. cmd.Flag("--runtime-arg").Flag("-Xgc:CMC")
  729. }
  730. if global.BootFlags != "" {
  731. cmd.Flag(global.BootFlags)
  732. }
  733. if extraFlags != "" {
  734. cmd.Flag(extraFlags)
  735. }
  736. cmd.Textf(`|| ( echo %s ; false )`, proptools.ShellEscape(failureMessage))
  737. installDir := filepath.Dir(image.imagePathOnDevice)
  738. var vdexInstalls android.RuleBuilderInstalls
  739. var unstrippedInstalls android.RuleBuilderInstalls
  740. for _, artOrOat := range image.moduleFiles(ctx, outputDir, ".art", ".oat") {
  741. cmd.ImplicitOutput(artOrOat)
  742. // Install the .oat and .art files
  743. rule.Install(artOrOat, filepath.Join(installDir, artOrOat.Base()))
  744. }
  745. for _, vdex := range image.moduleFiles(ctx, outputDir, ".vdex") {
  746. cmd.ImplicitOutput(vdex)
  747. // Note that the vdex files are identical between architectures.
  748. // Make rules will create symlinks to share them between architectures.
  749. vdexInstalls = append(vdexInstalls,
  750. android.RuleBuilderInstall{vdex, filepath.Join(installDir, vdex.Base())})
  751. }
  752. for _, unstrippedOat := range image.moduleFiles(ctx, symbolsDir, ".oat") {
  753. cmd.ImplicitOutput(unstrippedOat)
  754. // Install the unstripped oat files. The Make rules will put these in $(TARGET_OUT_UNSTRIPPED)
  755. unstrippedInstalls = append(unstrippedInstalls,
  756. android.RuleBuilderInstall{unstrippedOat, filepath.Join(installDir, unstrippedOat.Base())})
  757. }
  758. rule.Build(image.name+"JarsDexpreopt_"+image.target.String(), "dexpreopt "+image.name+" jars "+arch.String())
  759. // save output and installed files for makevars
  760. // TODO - these are always the same and so should be initialized in genBootImageConfigs
  761. image.installs = rule.Installs()
  762. image.vdexInstalls = vdexInstalls
  763. image.unstrippedInstalls = unstrippedInstalls
  764. // Only set the licenseMetadataFile from the active module.
  765. if isActiveModule(ctx.Module()) {
  766. image.licenseMetadataFile = android.OptionalPathForPath(ctx.LicenseMetadataFile())
  767. }
  768. return bootImageVariantOutputs{
  769. image,
  770. }
  771. }
  772. const failureMessage = `ERROR: Dex2oat failed to compile a boot image.
  773. It is likely that the boot classpath is inconsistent.
  774. Rebuild with ART_BOOT_IMAGE_EXTRA_ARGS="--runtime-arg -verbose:verifier" to see verification errors.`
  775. func bootImageProfileRule(ctx android.ModuleContext, image *bootImageConfig) android.WritablePath {
  776. if !image.isProfileGuided() {
  777. return nil
  778. }
  779. globalSoong := dexpreopt.GetGlobalSoongConfig(ctx)
  780. global := dexpreopt.GetGlobalConfig(ctx)
  781. if global.DisableGenerateProfile {
  782. return nil
  783. }
  784. defaultProfile := "frameworks/base/config/boot-image-profile.txt"
  785. extraProfile := "frameworks/base/config/boot-image-profile-extra.txt"
  786. rule := android.NewRuleBuilder(pctx, ctx)
  787. var profiles android.Paths
  788. if len(global.BootImageProfiles) > 0 {
  789. profiles = append(profiles, global.BootImageProfiles...)
  790. } else if path := android.ExistentPathForSource(ctx, defaultProfile); path.Valid() {
  791. profiles = append(profiles, path.Path())
  792. } else {
  793. // No profile (not even a default one, which is the case on some branches
  794. // like master-art-host that don't have frameworks/base).
  795. // Return nil and continue without profile.
  796. return nil
  797. }
  798. if path := android.ExistentPathForSource(ctx, extraProfile); path.Valid() {
  799. profiles = append(profiles, path.Path())
  800. }
  801. bootImageProfile := image.dir.Join(ctx, "boot-image-profile.txt")
  802. rule.Command().Text("cat").Inputs(profiles).Text(">").Output(bootImageProfile)
  803. profile := image.dir.Join(ctx, "boot.prof")
  804. rule.Command().
  805. Text(`ANDROID_LOG_TAGS="*:e"`).
  806. Tool(globalSoong.Profman).
  807. Flag("--output-profile-type=boot").
  808. FlagWithInput("--create-profile-from=", bootImageProfile).
  809. FlagForEachInput("--apk=", image.dexPathsDeps.Paths()).
  810. FlagForEachArg("--dex-location=", image.getAnyAndroidVariant().dexLocationsDeps).
  811. FlagWithOutput("--reference-profile-file=", profile)
  812. if image == defaultBootImageConfig(ctx) {
  813. rule.Install(profile, "/system/etc/boot-image.prof")
  814. image.profileInstalls = append(image.profileInstalls, rule.Installs()...)
  815. image.profileLicenseMetadataFile = android.OptionalPathForPath(ctx.LicenseMetadataFile())
  816. }
  817. rule.Build("bootJarsProfile", "profile boot jars")
  818. return profile
  819. }
  820. // bootFrameworkProfileRule generates the rule to create the boot framework profile and
  821. // returns a path to the generated file.
  822. func bootFrameworkProfileRule(ctx android.ModuleContext, image *bootImageConfig) android.WritablePath {
  823. globalSoong := dexpreopt.GetGlobalSoongConfig(ctx)
  824. global := dexpreopt.GetGlobalConfig(ctx)
  825. if global.DisableGenerateProfile || ctx.Config().UnbundledBuild() {
  826. return nil
  827. }
  828. defaultProfile := "frameworks/base/config/boot-profile.txt"
  829. bootFrameworkProfile := android.PathForSource(ctx, defaultProfile)
  830. profile := image.dir.Join(ctx, "boot.bprof")
  831. rule := android.NewRuleBuilder(pctx, ctx)
  832. rule.Command().
  833. Text(`ANDROID_LOG_TAGS="*:e"`).
  834. Tool(globalSoong.Profman).
  835. Flag("--output-profile-type=bprof").
  836. FlagWithInput("--create-profile-from=", bootFrameworkProfile).
  837. FlagForEachInput("--apk=", image.dexPathsDeps.Paths()).
  838. FlagForEachArg("--dex-location=", image.getAnyAndroidVariant().dexLocationsDeps).
  839. FlagWithOutput("--reference-profile-file=", profile)
  840. rule.Install(profile, "/system/etc/boot-image.bprof")
  841. rule.Build("bootFrameworkProfile", "profile boot framework jars")
  842. image.profileInstalls = append(image.profileInstalls, rule.Installs()...)
  843. image.profileLicenseMetadataFile = android.OptionalPathForPath(ctx.LicenseMetadataFile())
  844. return profile
  845. }
  846. func dumpOatRules(ctx android.ModuleContext, image *bootImageConfig) {
  847. var allPhonies android.Paths
  848. for _, image := range image.variants {
  849. arch := image.target.Arch.ArchType
  850. suffix := arch.String()
  851. // Host and target might both use x86 arch. We need to ensure the names are unique.
  852. if image.target.Os.Class == android.Host {
  853. suffix = "host-" + suffix
  854. }
  855. // Create a rule to call oatdump.
  856. output := android.PathForOutput(ctx, "boot."+suffix+".oatdump.txt")
  857. rule := android.NewRuleBuilder(pctx, ctx)
  858. imageLocationsOnHost, _ := image.imageLocations()
  859. rule.Command().
  860. BuiltTool("oatdump").
  861. FlagWithInputList("--runtime-arg -Xbootclasspath:", image.dexPathsDeps.Paths(), ":").
  862. FlagWithList("--runtime-arg -Xbootclasspath-locations:", image.dexLocationsDeps, ":").
  863. FlagWithArg("--image=", strings.Join(imageLocationsOnHost, ":")).Implicits(image.imagesDeps.Paths()).
  864. FlagWithOutput("--output=", output).
  865. FlagWithArg("--instruction-set=", arch.String())
  866. rule.Build("dump-oat-boot-"+suffix, "dump oat boot "+arch.String())
  867. // Create a phony rule that depends on the output file and prints the path.
  868. phony := android.PathForPhony(ctx, "dump-oat-boot-"+suffix)
  869. rule = android.NewRuleBuilder(pctx, ctx)
  870. rule.Command().
  871. Implicit(output).
  872. ImplicitOutput(phony).
  873. Text("echo").FlagWithArg("Output in ", output.String())
  874. rule.Build("phony-dump-oat-boot-"+suffix, "dump oat boot "+arch.String())
  875. allPhonies = append(allPhonies, phony)
  876. }
  877. phony := android.PathForPhony(ctx, "dump-oat-boot")
  878. ctx.Build(pctx, android.BuildParams{
  879. Rule: android.Phony,
  880. Output: phony,
  881. Inputs: allPhonies,
  882. Description: "dump-oat-boot",
  883. })
  884. }
  885. func writeGlobalConfigForMake(ctx android.SingletonContext, path android.WritablePath) {
  886. data := dexpreopt.GetGlobalConfigRawData(ctx)
  887. android.WriteFileRule(ctx, path, string(data))
  888. }
  889. // Define Make variables for boot image names, paths, etc. These variables are used in makefiles
  890. // (make/core/dex_preopt_libart.mk) to generate install rules that copy boot image files to the
  891. // correct output directories.
  892. func (d *dexpreoptBootJars) MakeVars(ctx android.MakeVarsContext) {
  893. if d.dexpreoptConfigForMake != nil && !SkipDexpreoptBootJars(ctx) {
  894. ctx.Strict("DEX_PREOPT_CONFIG_FOR_MAKE", d.dexpreoptConfigForMake.String())
  895. ctx.Strict("DEX_PREOPT_SOONG_CONFIG_FOR_MAKE", android.PathForOutput(ctx, "dexpreopt_soong.config").String())
  896. }
  897. image := d.defaultBootImage
  898. if image != nil {
  899. ctx.Strict("DEXPREOPT_IMAGE_PROFILE_BUILT_INSTALLED", image.profileInstalls.String())
  900. if image.profileLicenseMetadataFile.Valid() {
  901. ctx.Strict("DEXPREOPT_IMAGE_PROFILE_LICENSE_METADATA", image.profileLicenseMetadataFile.String())
  902. }
  903. if SkipDexpreoptBootJars(ctx) {
  904. return
  905. }
  906. global := dexpreopt.GetGlobalConfig(ctx)
  907. dexPaths, dexLocations := bcpForDexpreopt(ctx, global.PreoptWithUpdatableBcp)
  908. ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_FILES", strings.Join(dexPaths.Strings(), " "))
  909. ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_LOCATIONS", strings.Join(dexLocations, " "))
  910. var imageNames []string
  911. // The primary ART boot image is exposed to Make for testing (gtests) and benchmarking
  912. // (golem) purposes.
  913. for _, current := range append(d.otherImages, image) {
  914. imageNames = append(imageNames, current.name)
  915. for _, variant := range current.variants {
  916. suffix := ""
  917. if variant.target.Os.Class == android.Host {
  918. suffix = "_host"
  919. }
  920. sfx := variant.name + suffix + "_" + variant.target.Arch.ArchType.String()
  921. ctx.Strict("DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_"+sfx, variant.vdexInstalls.String())
  922. ctx.Strict("DEXPREOPT_IMAGE_"+sfx, variant.imagePathOnHost.String())
  923. ctx.Strict("DEXPREOPT_IMAGE_DEPS_"+sfx, strings.Join(variant.imagesDeps.Strings(), " "))
  924. ctx.Strict("DEXPREOPT_IMAGE_BUILT_INSTALLED_"+sfx, variant.installs.String())
  925. ctx.Strict("DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_"+sfx, variant.unstrippedInstalls.String())
  926. if variant.licenseMetadataFile.Valid() {
  927. ctx.Strict("DEXPREOPT_IMAGE_LICENSE_METADATA_"+sfx, variant.licenseMetadataFile.String())
  928. }
  929. }
  930. imageLocationsOnHost, imageLocationsOnDevice := current.getAnyAndroidVariant().imageLocations()
  931. ctx.Strict("DEXPREOPT_IMAGE_LOCATIONS_ON_HOST"+current.name, strings.Join(imageLocationsOnHost, ":"))
  932. ctx.Strict("DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICE"+current.name, strings.Join(imageLocationsOnDevice, ":"))
  933. ctx.Strict("DEXPREOPT_IMAGE_ZIP_"+current.name, current.zip.String())
  934. }
  935. // Ensure determinism.
  936. sort.Strings(imageNames)
  937. ctx.Strict("DEXPREOPT_IMAGE_NAMES", strings.Join(imageNames, " "))
  938. }
  939. }