prebuilt_etc.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. // Copyright 2016 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 etc
  15. // This file implements module types that install prebuilt artifacts.
  16. //
  17. // There exist two classes of prebuilt modules in the Android tree. The first class are the ones
  18. // based on `android.Prebuilt`, such as `cc_prebuilt_library` and `java_import`. This kind of
  19. // modules may exist both as prebuilts and source at the same time, though only one would be
  20. // installed and the other would be marked disabled. The `prebuilt_postdeps` mutator would select
  21. // the actual modules to be installed. More details in android/prebuilt.go.
  22. //
  23. // The second class is described in this file. Unlike `android.Prebuilt` based module types,
  24. // `prebuilt_etc` exist only as prebuilts and cannot have a same-named source module counterpart.
  25. // This makes the logic of `prebuilt_etc` to be much simpler as they don't need to go through the
  26. // various `prebuilt_*` mutators.
  27. import (
  28. "encoding/json"
  29. "fmt"
  30. "path/filepath"
  31. "strings"
  32. "github.com/google/blueprint/proptools"
  33. "android/soong/android"
  34. "android/soong/bazel"
  35. "android/soong/snapshot"
  36. )
  37. var pctx = android.NewPackageContext("android/soong/etc")
  38. // TODO(jungw): Now that it handles more than the ones in etc/, consider renaming this file.
  39. func init() {
  40. pctx.Import("android/soong/android")
  41. RegisterPrebuiltEtcBuildComponents(android.InitRegistrationContext)
  42. snapshot.RegisterSnapshotAction(generatePrebuiltSnapshot)
  43. }
  44. func RegisterPrebuiltEtcBuildComponents(ctx android.RegistrationContext) {
  45. ctx.RegisterModuleType("prebuilt_etc", PrebuiltEtcFactory)
  46. ctx.RegisterModuleType("prebuilt_etc_host", PrebuiltEtcHostFactory)
  47. ctx.RegisterModuleType("prebuilt_root", PrebuiltRootFactory)
  48. ctx.RegisterModuleType("prebuilt_usr_share", PrebuiltUserShareFactory)
  49. ctx.RegisterModuleType("prebuilt_usr_share_host", PrebuiltUserShareHostFactory)
  50. ctx.RegisterModuleType("prebuilt_font", PrebuiltFontFactory)
  51. ctx.RegisterModuleType("prebuilt_firmware", PrebuiltFirmwareFactory)
  52. ctx.RegisterModuleType("prebuilt_dsp", PrebuiltDSPFactory)
  53. ctx.RegisterModuleType("prebuilt_rfsa", PrebuiltRFSAFactory)
  54. ctx.RegisterModuleType("prebuilt_defaults", defaultsFactory)
  55. }
  56. var PrepareForTestWithPrebuiltEtc = android.FixtureRegisterWithContext(RegisterPrebuiltEtcBuildComponents)
  57. type prebuiltEtcProperties struct {
  58. // Source file of this prebuilt. Can reference a genrule type module with the ":module" syntax.
  59. Src *string `android:"path,arch_variant"`
  60. // Optional name for the installed file. If unspecified, name of the module is used as the file
  61. // name.
  62. Filename *string `android:"arch_variant"`
  63. // When set to true, and filename property is not set, the name for the installed file
  64. // is the same as the file name of the source file.
  65. Filename_from_src *bool `android:"arch_variant"`
  66. // Make this module available when building for ramdisk.
  67. // On device without a dedicated recovery partition, the module is only
  68. // available after switching root into
  69. // /first_stage_ramdisk. To expose the module before switching root, install
  70. // the recovery variant instead.
  71. Ramdisk_available *bool
  72. // Make this module available when building for vendor ramdisk.
  73. // On device without a dedicated recovery partition, the module is only
  74. // available after switching root into
  75. // /first_stage_ramdisk. To expose the module before switching root, install
  76. // the recovery variant instead.
  77. Vendor_ramdisk_available *bool
  78. // Make this module available when building for debug ramdisk.
  79. Debug_ramdisk_available *bool
  80. // Make this module available when building for recovery.
  81. Recovery_available *bool
  82. // Whether this module is directly installable to one of the partitions. Default: true.
  83. Installable *bool
  84. // Install symlinks to the installed file.
  85. Symlinks []string `android:"arch_variant"`
  86. }
  87. type prebuiltSubdirProperties struct {
  88. // Optional subdirectory under which this file is installed into, cannot be specified with
  89. // relative_install_path, prefer relative_install_path.
  90. Sub_dir *string `android:"arch_variant"`
  91. // Optional subdirectory under which this file is installed into, cannot be specified with
  92. // sub_dir.
  93. Relative_install_path *string `android:"arch_variant"`
  94. }
  95. type PrebuiltEtcModule interface {
  96. android.Module
  97. // Returns the base install directory, such as "etc", "usr/share".
  98. BaseDir() string
  99. // Returns the sub install directory relative to BaseDir().
  100. SubDir() string
  101. // Returns an android.OutputPath to the intermeidate file, which is the renamed prebuilt source
  102. // file.
  103. OutputFile() android.OutputPath
  104. }
  105. type PrebuiltEtc struct {
  106. android.ModuleBase
  107. android.DefaultableModuleBase
  108. android.BazelModuleBase
  109. snapshot.VendorSnapshotModuleInterface
  110. snapshot.RecoverySnapshotModuleInterface
  111. properties prebuiltEtcProperties
  112. subdirProperties prebuiltSubdirProperties
  113. sourceFilePath android.Path
  114. outputFilePath android.OutputPath
  115. // The base install location, e.g. "etc" for prebuilt_etc, "usr/share" for prebuilt_usr_share.
  116. installDirBase string
  117. // The base install location when soc_specific property is set to true, e.g. "firmware" for
  118. // prebuilt_firmware.
  119. socInstallDirBase string
  120. installDirPath android.InstallPath
  121. additionalDependencies *android.Paths
  122. }
  123. type Defaults struct {
  124. android.ModuleBase
  125. android.DefaultsModuleBase
  126. }
  127. func (p *PrebuiltEtc) inRamdisk() bool {
  128. return p.ModuleBase.InRamdisk() || p.ModuleBase.InstallInRamdisk()
  129. }
  130. func (p *PrebuiltEtc) onlyInRamdisk() bool {
  131. return p.ModuleBase.InstallInRamdisk()
  132. }
  133. func (p *PrebuiltEtc) InstallInRamdisk() bool {
  134. return p.inRamdisk()
  135. }
  136. func (p *PrebuiltEtc) inVendorRamdisk() bool {
  137. return p.ModuleBase.InVendorRamdisk() || p.ModuleBase.InstallInVendorRamdisk()
  138. }
  139. func (p *PrebuiltEtc) onlyInVendorRamdisk() bool {
  140. return p.ModuleBase.InstallInVendorRamdisk()
  141. }
  142. func (p *PrebuiltEtc) InstallInVendorRamdisk() bool {
  143. return p.inVendorRamdisk()
  144. }
  145. func (p *PrebuiltEtc) inDebugRamdisk() bool {
  146. return p.ModuleBase.InDebugRamdisk() || p.ModuleBase.InstallInDebugRamdisk()
  147. }
  148. func (p *PrebuiltEtc) onlyInDebugRamdisk() bool {
  149. return p.ModuleBase.InstallInDebugRamdisk()
  150. }
  151. func (p *PrebuiltEtc) InstallInDebugRamdisk() bool {
  152. return p.inDebugRamdisk()
  153. }
  154. func (p *PrebuiltEtc) InRecovery() bool {
  155. return p.ModuleBase.InRecovery() || p.ModuleBase.InstallInRecovery()
  156. }
  157. func (p *PrebuiltEtc) onlyInRecovery() bool {
  158. return p.ModuleBase.InstallInRecovery()
  159. }
  160. func (p *PrebuiltEtc) InstallInRecovery() bool {
  161. return p.InRecovery()
  162. }
  163. var _ android.ImageInterface = (*PrebuiltEtc)(nil)
  164. func (p *PrebuiltEtc) ImageMutatorBegin(ctx android.BaseModuleContext) {}
  165. func (p *PrebuiltEtc) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
  166. return !p.ModuleBase.InstallInRecovery() && !p.ModuleBase.InstallInRamdisk() &&
  167. !p.ModuleBase.InstallInVendorRamdisk() && !p.ModuleBase.InstallInDebugRamdisk()
  168. }
  169. func (p *PrebuiltEtc) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
  170. return proptools.Bool(p.properties.Ramdisk_available) || p.ModuleBase.InstallInRamdisk()
  171. }
  172. func (p *PrebuiltEtc) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
  173. return proptools.Bool(p.properties.Vendor_ramdisk_available) || p.ModuleBase.InstallInVendorRamdisk()
  174. }
  175. func (p *PrebuiltEtc) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
  176. return proptools.Bool(p.properties.Debug_ramdisk_available) || p.ModuleBase.InstallInDebugRamdisk()
  177. }
  178. func (p *PrebuiltEtc) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
  179. return proptools.Bool(p.properties.Recovery_available) || p.ModuleBase.InstallInRecovery()
  180. }
  181. func (p *PrebuiltEtc) ExtraImageVariations(ctx android.BaseModuleContext) []string {
  182. return nil
  183. }
  184. func (p *PrebuiltEtc) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
  185. }
  186. func (p *PrebuiltEtc) SourceFilePath(ctx android.ModuleContext) android.Path {
  187. return android.PathForModuleSrc(ctx, proptools.String(p.properties.Src))
  188. }
  189. func (p *PrebuiltEtc) InstallDirPath() android.InstallPath {
  190. return p.installDirPath
  191. }
  192. // This allows other derivative modules (e.g. prebuilt_etc_xml) to perform
  193. // additional steps (like validating the src) before the file is installed.
  194. func (p *PrebuiltEtc) SetAdditionalDependencies(paths android.Paths) {
  195. p.additionalDependencies = &paths
  196. }
  197. func (p *PrebuiltEtc) OutputFile() android.OutputPath {
  198. return p.outputFilePath
  199. }
  200. var _ android.OutputFileProducer = (*PrebuiltEtc)(nil)
  201. func (p *PrebuiltEtc) OutputFiles(tag string) (android.Paths, error) {
  202. switch tag {
  203. case "":
  204. return android.Paths{p.outputFilePath}, nil
  205. default:
  206. return nil, fmt.Errorf("unsupported module reference tag %q", tag)
  207. }
  208. }
  209. func (p *PrebuiltEtc) SubDir() string {
  210. if subDir := proptools.String(p.subdirProperties.Sub_dir); subDir != "" {
  211. return subDir
  212. }
  213. return proptools.String(p.subdirProperties.Relative_install_path)
  214. }
  215. func (p *PrebuiltEtc) BaseDir() string {
  216. return p.installDirBase
  217. }
  218. func (p *PrebuiltEtc) Installable() bool {
  219. return p.properties.Installable == nil || proptools.Bool(p.properties.Installable)
  220. }
  221. func (p *PrebuiltEtc) InVendor() bool {
  222. return p.ModuleBase.InstallInVendor()
  223. }
  224. func (p *PrebuiltEtc) ExcludeFromVendorSnapshot() bool {
  225. return false
  226. }
  227. func (p *PrebuiltEtc) ExcludeFromRecoverySnapshot() bool {
  228. return false
  229. }
  230. func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
  231. if p.properties.Src == nil {
  232. ctx.PropertyErrorf("src", "missing prebuilt source file")
  233. return
  234. }
  235. p.sourceFilePath = android.PathForModuleSrc(ctx, proptools.String(p.properties.Src))
  236. // Determine the output file basename.
  237. // If Filename is set, use the name specified by the property.
  238. // If Filename_from_src is set, use the source file name.
  239. // Otherwise use the module name.
  240. filename := proptools.String(p.properties.Filename)
  241. filenameFromSrc := proptools.Bool(p.properties.Filename_from_src)
  242. if filename != "" {
  243. if filenameFromSrc {
  244. ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true")
  245. return
  246. }
  247. } else if filenameFromSrc {
  248. filename = p.sourceFilePath.Base()
  249. } else {
  250. filename = ctx.ModuleName()
  251. }
  252. p.outputFilePath = android.PathForModuleOut(ctx, filename).OutputPath
  253. if strings.Contains(filename, "/") {
  254. ctx.PropertyErrorf("filename", "filename cannot contain separator '/'")
  255. return
  256. }
  257. // Check that `sub_dir` and `relative_install_path` are not set at the same time.
  258. if p.subdirProperties.Sub_dir != nil && p.subdirProperties.Relative_install_path != nil {
  259. ctx.PropertyErrorf("sub_dir", "relative_install_path is set. Cannot set sub_dir")
  260. }
  261. // If soc install dir was specified and SOC specific is set, set the installDirPath to the
  262. // specified socInstallDirBase.
  263. installBaseDir := p.installDirBase
  264. if p.SocSpecific() && p.socInstallDirBase != "" {
  265. installBaseDir = p.socInstallDirBase
  266. }
  267. p.installDirPath = android.PathForModuleInstall(ctx, installBaseDir, p.SubDir())
  268. // This ensures that outputFilePath has the correct name for others to
  269. // use, as the source file may have a different name.
  270. ctx.Build(pctx, android.BuildParams{
  271. Rule: android.Cp,
  272. Output: p.outputFilePath,
  273. Input: p.sourceFilePath,
  274. })
  275. if !p.Installable() {
  276. p.SkipInstall()
  277. }
  278. // Call InstallFile even when uninstallable to make the module included in the package
  279. installPath := ctx.InstallFile(p.installDirPath, p.outputFilePath.Base(), p.outputFilePath)
  280. for _, sl := range p.properties.Symlinks {
  281. ctx.InstallSymlink(p.installDirPath, sl, installPath)
  282. }
  283. }
  284. func (p *PrebuiltEtc) AndroidMkEntries() []android.AndroidMkEntries {
  285. nameSuffix := ""
  286. if p.inRamdisk() && !p.onlyInRamdisk() {
  287. nameSuffix = ".ramdisk"
  288. }
  289. if p.inVendorRamdisk() && !p.onlyInVendorRamdisk() {
  290. nameSuffix = ".vendor_ramdisk"
  291. }
  292. if p.inDebugRamdisk() && !p.onlyInDebugRamdisk() {
  293. nameSuffix = ".debug_ramdisk"
  294. }
  295. if p.InRecovery() && !p.onlyInRecovery() {
  296. nameSuffix = ".recovery"
  297. }
  298. return []android.AndroidMkEntries{android.AndroidMkEntries{
  299. Class: "ETC",
  300. SubName: nameSuffix,
  301. OutputFile: android.OptionalPathForPath(p.outputFilePath),
  302. ExtraEntries: []android.AndroidMkExtraEntriesFunc{
  303. func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  304. entries.SetString("LOCAL_MODULE_TAGS", "optional")
  305. entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.String())
  306. entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
  307. if len(p.properties.Symlinks) > 0 {
  308. entries.AddStrings("LOCAL_MODULE_SYMLINKS", p.properties.Symlinks...)
  309. }
  310. entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.Installable())
  311. if p.additionalDependencies != nil {
  312. entries.AddStrings("LOCAL_ADDITIONAL_DEPENDENCIES", p.additionalDependencies.Strings()...)
  313. }
  314. },
  315. },
  316. }}
  317. }
  318. func InitPrebuiltEtcModule(p *PrebuiltEtc, dirBase string) {
  319. p.installDirBase = dirBase
  320. p.AddProperties(&p.properties)
  321. p.AddProperties(&p.subdirProperties)
  322. }
  323. func InitPrebuiltRootModule(p *PrebuiltEtc) {
  324. p.installDirBase = "."
  325. p.AddProperties(&p.properties)
  326. }
  327. // prebuilt_etc is for a prebuilt artifact that is installed in
  328. // <partition>/etc/<sub_dir> directory.
  329. func PrebuiltEtcFactory() android.Module {
  330. module := &PrebuiltEtc{}
  331. InitPrebuiltEtcModule(module, "etc")
  332. // This module is device-only
  333. android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
  334. android.InitDefaultableModule(module)
  335. android.InitBazelModule(module)
  336. return module
  337. }
  338. func defaultsFactory() android.Module {
  339. return DefaultsFactory()
  340. }
  341. func DefaultsFactory(props ...interface{}) android.Module {
  342. module := &Defaults{}
  343. module.AddProperties(props...)
  344. module.AddProperties(
  345. &prebuiltEtcProperties{},
  346. &prebuiltSubdirProperties{},
  347. )
  348. android.InitDefaultsModule(module)
  349. return module
  350. }
  351. // prebuilt_etc_host is for a host prebuilt artifact that is installed in
  352. // $(HOST_OUT)/etc/<sub_dir> directory.
  353. func PrebuiltEtcHostFactory() android.Module {
  354. module := &PrebuiltEtc{}
  355. InitPrebuiltEtcModule(module, "etc")
  356. // This module is host-only
  357. android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
  358. android.InitDefaultableModule(module)
  359. return module
  360. }
  361. // prebuilt_root is for a prebuilt artifact that is installed in
  362. // <partition>/ directory. Can't have any sub directories.
  363. func PrebuiltRootFactory() android.Module {
  364. module := &PrebuiltEtc{}
  365. InitPrebuiltRootModule(module)
  366. // This module is device-only
  367. android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
  368. android.InitDefaultableModule(module)
  369. return module
  370. }
  371. // prebuilt_usr_share is for a prebuilt artifact that is installed in
  372. // <partition>/usr/share/<sub_dir> directory.
  373. func PrebuiltUserShareFactory() android.Module {
  374. module := &PrebuiltEtc{}
  375. InitPrebuiltEtcModule(module, "usr/share")
  376. // This module is device-only
  377. android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
  378. android.InitDefaultableModule(module)
  379. return module
  380. }
  381. // prebuild_usr_share_host is for a host prebuilt artifact that is installed in
  382. // $(HOST_OUT)/usr/share/<sub_dir> directory.
  383. func PrebuiltUserShareHostFactory() android.Module {
  384. module := &PrebuiltEtc{}
  385. InitPrebuiltEtcModule(module, "usr/share")
  386. // This module is host-only
  387. android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
  388. android.InitDefaultableModule(module)
  389. return module
  390. }
  391. // prebuilt_font installs a font in <partition>/fonts directory.
  392. func PrebuiltFontFactory() android.Module {
  393. module := &PrebuiltEtc{}
  394. InitPrebuiltEtcModule(module, "fonts")
  395. // This module is device-only
  396. android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
  397. android.InitDefaultableModule(module)
  398. return module
  399. }
  400. // prebuilt_firmware installs a firmware file to <partition>/etc/firmware directory for system
  401. // image.
  402. // If soc_specific property is set to true, the firmware file is installed to the
  403. // vendor <partition>/firmware directory for vendor image.
  404. func PrebuiltFirmwareFactory() android.Module {
  405. module := &PrebuiltEtc{}
  406. module.socInstallDirBase = "firmware"
  407. InitPrebuiltEtcModule(module, "etc/firmware")
  408. // This module is device-only
  409. android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
  410. android.InitDefaultableModule(module)
  411. return module
  412. }
  413. // prebuilt_dsp installs a DSP related file to <partition>/etc/dsp directory for system image.
  414. // If soc_specific property is set to true, the DSP related file is installed to the
  415. // vendor <partition>/dsp directory for vendor image.
  416. func PrebuiltDSPFactory() android.Module {
  417. module := &PrebuiltEtc{}
  418. module.socInstallDirBase = "dsp"
  419. InitPrebuiltEtcModule(module, "etc/dsp")
  420. // This module is device-only
  421. android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
  422. android.InitDefaultableModule(module)
  423. return module
  424. }
  425. // prebuilt_rfsa installs a firmware file that will be available through Qualcomm's RFSA
  426. // to the <partition>/lib/rfsa directory.
  427. func PrebuiltRFSAFactory() android.Module {
  428. module := &PrebuiltEtc{}
  429. // Ideally these would go in /vendor/dsp, but the /vendor/lib/rfsa paths are hardcoded in too
  430. // many places outside of the application processor. They could be moved to /vendor/dsp once
  431. // that is cleaned up.
  432. InitPrebuiltEtcModule(module, "lib/rfsa")
  433. // This module is device-only
  434. android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
  435. android.InitDefaultableModule(module)
  436. return module
  437. }
  438. // Copy file into the snapshot
  439. func copyFile(ctx android.SingletonContext, path android.Path, out string, fake bool) android.OutputPath {
  440. if fake {
  441. // Create empty file instead for the fake snapshot
  442. return snapshot.WriteStringToFileRule(ctx, "", out)
  443. } else {
  444. return snapshot.CopyFileRule(pctx, ctx, path, out)
  445. }
  446. }
  447. // Check if the module is target of the snapshot
  448. func isSnapshotAware(ctx android.SingletonContext, m *PrebuiltEtc, image snapshot.SnapshotImage) bool {
  449. if !m.Enabled() {
  450. return false
  451. }
  452. // Skip if the module is not included in the image
  453. if !image.InImage(m)() {
  454. return false
  455. }
  456. // When android/prebuilt.go selects between source and prebuilt, it sets
  457. // HideFromMake on the other one to avoid duplicate install rules in make.
  458. if m.IsHideFromMake() {
  459. return false
  460. }
  461. // There are some prebuilt_etc module with multiple definition of same name.
  462. // Check if the target would be included from the build
  463. if !m.ExportedToMake() {
  464. return false
  465. }
  466. // Skip if the module is in the predefined path list to skip
  467. if image.IsProprietaryPath(ctx.ModuleDir(m), ctx.DeviceConfig()) {
  468. return false
  469. }
  470. // Skip if the module should be excluded
  471. if image.ExcludeFromSnapshot(m) || image.ExcludeFromDirectedSnapshot(ctx.DeviceConfig(), m.BaseModuleName()) {
  472. return false
  473. }
  474. // Skip from other exceptional cases
  475. if m.Target().Os.Class != android.Device {
  476. return false
  477. }
  478. if m.Target().NativeBridge == android.NativeBridgeEnabled {
  479. return false
  480. }
  481. return true
  482. }
  483. func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) android.Paths {
  484. /*
  485. Snapshot zipped artifacts directory structure for etc modules:
  486. {SNAPSHOT_ARCH}/
  487. arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
  488. etc/
  489. (prebuilt etc files)
  490. arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
  491. etc/
  492. (prebuilt etc files)
  493. NOTICE_FILES/
  494. (notice files)
  495. */
  496. var snapshotOutputs android.Paths
  497. noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES")
  498. installedNotices := make(map[string]bool)
  499. ctx.VisitAllModules(func(module android.Module) {
  500. m, ok := module.(*PrebuiltEtc)
  501. if !ok {
  502. return
  503. }
  504. if !isSnapshotAware(ctx, m, s.Image) {
  505. return
  506. }
  507. targetArch := "arch-" + m.Target().Arch.ArchType.String()
  508. snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, "etc", m.BaseModuleName())
  509. snapshotOutputs = append(snapshotOutputs, copyFile(ctx, m.OutputFile(), snapshotLibOut, s.Fake))
  510. prop := snapshot.SnapshotJsonFlags{}
  511. propOut := snapshotLibOut + ".json"
  512. prop.ModuleName = m.BaseModuleName()
  513. if m.subdirProperties.Relative_install_path != nil {
  514. prop.RelativeInstallPath = *m.subdirProperties.Relative_install_path
  515. }
  516. if m.properties.Filename != nil {
  517. prop.Filename = *m.properties.Filename
  518. }
  519. j, err := json.Marshal(prop)
  520. if err != nil {
  521. ctx.Errorf("json marshal to %q failed: %#v", propOut, err)
  522. return
  523. }
  524. snapshotOutputs = append(snapshotOutputs, snapshot.WriteStringToFileRule(ctx, string(j), propOut))
  525. if len(m.EffectiveLicenseFiles()) > 0 {
  526. noticeName := ctx.ModuleName(m) + ".txt"
  527. noticeOut := filepath.Join(noticeDir, noticeName)
  528. // skip already copied notice file
  529. if !installedNotices[noticeOut] {
  530. installedNotices[noticeOut] = true
  531. noticeOutPath := android.PathForOutput(ctx, noticeOut)
  532. ctx.Build(pctx, android.BuildParams{
  533. Rule: android.Cat,
  534. Inputs: m.EffectiveLicenseFiles(),
  535. Output: noticeOutPath,
  536. Description: "combine notices for " + noticeOut,
  537. })
  538. snapshotOutputs = append(snapshotOutputs, noticeOutPath)
  539. }
  540. }
  541. })
  542. return snapshotOutputs
  543. }
  544. // For Bazel / bp2build
  545. type bazelPrebuiltEtcAttributes struct {
  546. Src bazel.LabelAttribute
  547. Filename string
  548. Sub_dir string
  549. Installable bazel.BoolAttribute
  550. }
  551. // ConvertWithBp2build performs bp2build conversion of PrebuiltEtc
  552. func (p *PrebuiltEtc) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
  553. // All prebuilt_* modules are PrebuiltEtc, but at this time, we only convert prebuilt_etc modules.
  554. if ctx.ModuleType() != "prebuilt_etc" {
  555. return
  556. }
  557. prebuiltEtcBp2BuildInternal(ctx, p)
  558. }
  559. func prebuiltEtcBp2BuildInternal(ctx android.TopDownMutatorContext, module *PrebuiltEtc) {
  560. var srcLabelAttribute bazel.LabelAttribute
  561. for axis, configToProps := range module.GetArchVariantProperties(ctx, &prebuiltEtcProperties{}) {
  562. for config, p := range configToProps {
  563. props, ok := p.(*prebuiltEtcProperties)
  564. if !ok {
  565. continue
  566. }
  567. if props.Src != nil {
  568. srcLabelAttribute.SetSelectValue(axis, config, android.BazelLabelForModuleSrcSingle(ctx, *props.Src))
  569. }
  570. }
  571. }
  572. var filename string
  573. if module.properties.Filename != nil {
  574. filename = *module.properties.Filename
  575. }
  576. var subDir string
  577. if module.subdirProperties.Sub_dir != nil {
  578. subDir = *module.subdirProperties.Sub_dir
  579. }
  580. var installableBoolAttribute bazel.BoolAttribute
  581. if module.properties.Installable != nil {
  582. installableBoolAttribute.Value = module.properties.Installable
  583. }
  584. attrs := &bazelPrebuiltEtcAttributes{
  585. Src: srcLabelAttribute,
  586. Filename: filename,
  587. Sub_dir: subDir,
  588. Installable: installableBoolAttribute,
  589. }
  590. props := bazel.BazelTargetModuleProperties{
  591. Rule_class: "prebuilt_etc",
  592. Bzl_load_location: "//build/bazel/rules:prebuilt_etc.bzl",
  593. }
  594. ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, attrs)
  595. }