dexpreopt_bootjars.go 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080
  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. FlagWithArg("--oat-file=", outputPath.String()).
  705. FlagWithArg("--oat-location=", oatLocation).
  706. FlagWithArg("--image=", imagePath.String()).
  707. FlagWithArg("--instruction-set=", arch.String()).
  708. FlagWithArg("--android-root=", global.EmptyDirectory).
  709. FlagWithArg("--no-inline-from=", "core-oj.jar").
  710. Flag("--force-determinism").
  711. Flag("--abort-on-hard-verifier-error")
  712. // We don't strip on host to make perf tools work.
  713. if image.target.Os == android.Android {
  714. cmd.Flag("--strip")
  715. }
  716. // If the image is profile-guided but the profile is disabled, we omit "--compiler-filter" to
  717. // leave the decision to dex2oat to pick the compiler filter.
  718. if !(image.isProfileGuided() && global.DisableGenerateProfile) {
  719. cmd.FlagWithArg("--compiler-filter=", image.compilerFilter)
  720. }
  721. if image.singleImage {
  722. cmd.Flag("--single-image")
  723. }
  724. // Use the default variant/features for host builds.
  725. // The map below contains only device CPU info (which might be x86 on some devices).
  726. if image.target.Os == android.Android {
  727. cmd.FlagWithArg("--instruction-set-variant=", global.CpuVariant[arch])
  728. cmd.FlagWithArg("--instruction-set-features=", global.InstructionSetFeatures[arch])
  729. }
  730. if global.EnableUffdGc && image.target.Os == android.Android {
  731. cmd.Flag("--runtime-arg").Flag("-Xgc:CMC")
  732. }
  733. if global.BootFlags != "" {
  734. cmd.Flag(global.BootFlags)
  735. }
  736. if extraFlags != "" {
  737. cmd.Flag(extraFlags)
  738. }
  739. cmd.Textf(`|| ( echo %s ; false )`, proptools.ShellEscape(failureMessage))
  740. installDir := filepath.Dir(image.imagePathOnDevice)
  741. var vdexInstalls android.RuleBuilderInstalls
  742. var unstrippedInstalls android.RuleBuilderInstalls
  743. for _, artOrOat := range image.moduleFiles(ctx, outputDir, ".art", ".oat") {
  744. cmd.ImplicitOutput(artOrOat)
  745. // Install the .oat and .art files
  746. rule.Install(artOrOat, filepath.Join(installDir, artOrOat.Base()))
  747. }
  748. for _, vdex := range image.moduleFiles(ctx, outputDir, ".vdex") {
  749. cmd.ImplicitOutput(vdex)
  750. // Note that the vdex files are identical between architectures.
  751. // Make rules will create symlinks to share them between architectures.
  752. vdexInstalls = append(vdexInstalls,
  753. android.RuleBuilderInstall{vdex, filepath.Join(installDir, vdex.Base())})
  754. }
  755. for _, unstrippedOat := range image.moduleFiles(ctx, symbolsDir, ".oat") {
  756. cmd.ImplicitOutput(unstrippedOat)
  757. // Install the unstripped oat files. The Make rules will put these in $(TARGET_OUT_UNSTRIPPED)
  758. unstrippedInstalls = append(unstrippedInstalls,
  759. android.RuleBuilderInstall{unstrippedOat, filepath.Join(installDir, unstrippedOat.Base())})
  760. }
  761. rule.Build(image.name+"JarsDexpreopt_"+image.target.String(), "dexpreopt "+image.name+" jars "+arch.String())
  762. // save output and installed files for makevars
  763. // TODO - these are always the same and so should be initialized in genBootImageConfigs
  764. image.installs = rule.Installs()
  765. image.vdexInstalls = vdexInstalls
  766. image.unstrippedInstalls = unstrippedInstalls
  767. // Only set the licenseMetadataFile from the active module.
  768. if isActiveModule(ctx.Module()) {
  769. image.licenseMetadataFile = android.OptionalPathForPath(ctx.LicenseMetadataFile())
  770. }
  771. return bootImageVariantOutputs{
  772. image,
  773. }
  774. }
  775. const failureMessage = `ERROR: Dex2oat failed to compile a boot image.
  776. It is likely that the boot classpath is inconsistent.
  777. Rebuild with ART_BOOT_IMAGE_EXTRA_ARGS="--runtime-arg -verbose:verifier" to see verification errors.`
  778. func bootImageProfileRule(ctx android.ModuleContext, image *bootImageConfig) android.WritablePath {
  779. if !image.isProfileGuided() {
  780. return nil
  781. }
  782. globalSoong := dexpreopt.GetGlobalSoongConfig(ctx)
  783. global := dexpreopt.GetGlobalConfig(ctx)
  784. if global.DisableGenerateProfile {
  785. return nil
  786. }
  787. defaultProfile := "frameworks/base/config/boot-image-profile.txt"
  788. extraProfile := "frameworks/base/config/boot-image-profile-extra.txt"
  789. rule := android.NewRuleBuilder(pctx, ctx)
  790. var profiles android.Paths
  791. if len(global.BootImageProfiles) > 0 {
  792. profiles = append(profiles, global.BootImageProfiles...)
  793. } else if path := android.ExistentPathForSource(ctx, defaultProfile); path.Valid() {
  794. profiles = append(profiles, path.Path())
  795. } else {
  796. // No profile (not even a default one, which is the case on some branches
  797. // like master-art-host that don't have frameworks/base).
  798. // Return nil and continue without profile.
  799. return nil
  800. }
  801. if path := android.ExistentPathForSource(ctx, extraProfile); path.Valid() {
  802. profiles = append(profiles, path.Path())
  803. }
  804. bootImageProfile := image.dir.Join(ctx, "boot-image-profile.txt")
  805. rule.Command().Text("cat").Inputs(profiles).Text(">").Output(bootImageProfile)
  806. profile := image.dir.Join(ctx, "boot.prof")
  807. rule.Command().
  808. Text(`ANDROID_LOG_TAGS="*:e"`).
  809. Tool(globalSoong.Profman).
  810. Flag("--output-profile-type=boot").
  811. FlagWithInput("--create-profile-from=", bootImageProfile).
  812. FlagForEachInput("--apk=", image.dexPathsDeps.Paths()).
  813. FlagForEachArg("--dex-location=", image.getAnyAndroidVariant().dexLocationsDeps).
  814. FlagWithOutput("--reference-profile-file=", profile)
  815. if image == defaultBootImageConfig(ctx) {
  816. rule.Install(profile, "/system/etc/boot-image.prof")
  817. image.profileInstalls = append(image.profileInstalls, rule.Installs()...)
  818. image.profileLicenseMetadataFile = android.OptionalPathForPath(ctx.LicenseMetadataFile())
  819. }
  820. rule.Build("bootJarsProfile", "profile boot jars")
  821. return profile
  822. }
  823. // bootFrameworkProfileRule generates the rule to create the boot framework profile and
  824. // returns a path to the generated file.
  825. func bootFrameworkProfileRule(ctx android.ModuleContext, image *bootImageConfig) android.WritablePath {
  826. globalSoong := dexpreopt.GetGlobalSoongConfig(ctx)
  827. global := dexpreopt.GetGlobalConfig(ctx)
  828. if global.DisableGenerateProfile || ctx.Config().UnbundledBuild() {
  829. return nil
  830. }
  831. defaultProfile := "frameworks/base/config/boot-profile.txt"
  832. bootFrameworkProfile := android.PathForSource(ctx, defaultProfile)
  833. profile := image.dir.Join(ctx, "boot.bprof")
  834. rule := android.NewRuleBuilder(pctx, ctx)
  835. rule.Command().
  836. Text(`ANDROID_LOG_TAGS="*:e"`).
  837. Tool(globalSoong.Profman).
  838. Flag("--output-profile-type=bprof").
  839. FlagWithInput("--create-profile-from=", bootFrameworkProfile).
  840. FlagForEachInput("--apk=", image.dexPathsDeps.Paths()).
  841. FlagForEachArg("--dex-location=", image.getAnyAndroidVariant().dexLocationsDeps).
  842. FlagWithOutput("--reference-profile-file=", profile)
  843. rule.Install(profile, "/system/etc/boot-image.bprof")
  844. rule.Build("bootFrameworkProfile", "profile boot framework jars")
  845. image.profileInstalls = append(image.profileInstalls, rule.Installs()...)
  846. image.profileLicenseMetadataFile = android.OptionalPathForPath(ctx.LicenseMetadataFile())
  847. return profile
  848. }
  849. func dumpOatRules(ctx android.ModuleContext, image *bootImageConfig) {
  850. var allPhonies android.Paths
  851. for _, image := range image.variants {
  852. arch := image.target.Arch.ArchType
  853. suffix := arch.String()
  854. // Host and target might both use x86 arch. We need to ensure the names are unique.
  855. if image.target.Os.Class == android.Host {
  856. suffix = "host-" + suffix
  857. }
  858. // Create a rule to call oatdump.
  859. output := android.PathForOutput(ctx, "boot."+suffix+".oatdump.txt")
  860. rule := android.NewRuleBuilder(pctx, ctx)
  861. imageLocationsOnHost, _ := image.imageLocations()
  862. rule.Command().
  863. BuiltTool("oatdump").
  864. FlagWithInputList("--runtime-arg -Xbootclasspath:", image.dexPathsDeps.Paths(), ":").
  865. FlagWithList("--runtime-arg -Xbootclasspath-locations:", image.dexLocationsDeps, ":").
  866. FlagWithArg("--image=", strings.Join(imageLocationsOnHost, ":")).Implicits(image.imagesDeps.Paths()).
  867. FlagWithOutput("--output=", output).
  868. FlagWithArg("--instruction-set=", arch.String())
  869. rule.Build("dump-oat-boot-"+suffix, "dump oat boot "+arch.String())
  870. // Create a phony rule that depends on the output file and prints the path.
  871. phony := android.PathForPhony(ctx, "dump-oat-boot-"+suffix)
  872. rule = android.NewRuleBuilder(pctx, ctx)
  873. rule.Command().
  874. Implicit(output).
  875. ImplicitOutput(phony).
  876. Text("echo").FlagWithArg("Output in ", output.String())
  877. rule.Build("phony-dump-oat-boot-"+suffix, "dump oat boot "+arch.String())
  878. allPhonies = append(allPhonies, phony)
  879. }
  880. phony := android.PathForPhony(ctx, "dump-oat-boot")
  881. ctx.Build(pctx, android.BuildParams{
  882. Rule: android.Phony,
  883. Output: phony,
  884. Inputs: allPhonies,
  885. Description: "dump-oat-boot",
  886. })
  887. }
  888. func writeGlobalConfigForMake(ctx android.SingletonContext, path android.WritablePath) {
  889. data := dexpreopt.GetGlobalConfigRawData(ctx)
  890. android.WriteFileRule(ctx, path, string(data))
  891. }
  892. // Define Make variables for boot image names, paths, etc. These variables are used in makefiles
  893. // (make/core/dex_preopt_libart.mk) to generate install rules that copy boot image files to the
  894. // correct output directories.
  895. func (d *dexpreoptBootJars) MakeVars(ctx android.MakeVarsContext) {
  896. if d.dexpreoptConfigForMake != nil && !SkipDexpreoptBootJars(ctx) {
  897. ctx.Strict("DEX_PREOPT_CONFIG_FOR_MAKE", d.dexpreoptConfigForMake.String())
  898. ctx.Strict("DEX_PREOPT_SOONG_CONFIG_FOR_MAKE", android.PathForOutput(ctx, "dexpreopt_soong.config").String())
  899. }
  900. image := d.defaultBootImage
  901. if image != nil {
  902. ctx.Strict("DEXPREOPT_IMAGE_PROFILE_BUILT_INSTALLED", image.profileInstalls.String())
  903. if image.profileLicenseMetadataFile.Valid() {
  904. ctx.Strict("DEXPREOPT_IMAGE_PROFILE_LICENSE_METADATA", image.profileLicenseMetadataFile.String())
  905. }
  906. if SkipDexpreoptBootJars(ctx) {
  907. return
  908. }
  909. global := dexpreopt.GetGlobalConfig(ctx)
  910. dexPaths, dexLocations := bcpForDexpreopt(ctx, global.PreoptWithUpdatableBcp)
  911. ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_FILES", strings.Join(dexPaths.Strings(), " "))
  912. ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_LOCATIONS", strings.Join(dexLocations, " "))
  913. var imageNames []string
  914. // The primary ART boot image is exposed to Make for testing (gtests) and benchmarking
  915. // (golem) purposes.
  916. for _, current := range append(d.otherImages, image) {
  917. imageNames = append(imageNames, current.name)
  918. for _, variant := range current.variants {
  919. suffix := ""
  920. if variant.target.Os.Class == android.Host {
  921. suffix = "_host"
  922. }
  923. sfx := variant.name + suffix + "_" + variant.target.Arch.ArchType.String()
  924. ctx.Strict("DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_"+sfx, variant.vdexInstalls.String())
  925. ctx.Strict("DEXPREOPT_IMAGE_"+sfx, variant.imagePathOnHost.String())
  926. ctx.Strict("DEXPREOPT_IMAGE_DEPS_"+sfx, strings.Join(variant.imagesDeps.Strings(), " "))
  927. ctx.Strict("DEXPREOPT_IMAGE_BUILT_INSTALLED_"+sfx, variant.installs.String())
  928. ctx.Strict("DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_"+sfx, variant.unstrippedInstalls.String())
  929. if variant.licenseMetadataFile.Valid() {
  930. ctx.Strict("DEXPREOPT_IMAGE_LICENSE_METADATA_"+sfx, variant.licenseMetadataFile.String())
  931. }
  932. }
  933. imageLocationsOnHost, imageLocationsOnDevice := current.getAnyAndroidVariant().imageLocations()
  934. ctx.Strict("DEXPREOPT_IMAGE_LOCATIONS_ON_HOST"+current.name, strings.Join(imageLocationsOnHost, ":"))
  935. ctx.Strict("DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICE"+current.name, strings.Join(imageLocationsOnDevice, ":"))
  936. ctx.Strict("DEXPREOPT_IMAGE_ZIP_"+current.name, current.zip.String())
  937. }
  938. // Ensure determinism.
  939. sort.Strings(imageNames)
  940. ctx.Strict("DEXPREOPT_IMAGE_NAMES", strings.Join(imageNames, " "))
  941. }
  942. }