system_image.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright (C) 2021 The Android Open Source Project
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package filesystem
  15. import (
  16. "android/soong/android"
  17. "android/soong/linkerconfig"
  18. )
  19. type systemImage struct {
  20. filesystem
  21. properties systemImageProperties
  22. }
  23. type systemImageProperties struct {
  24. // Path to the input linker config json file.
  25. Linker_config_src *string
  26. }
  27. // android_system_image is a specialization of android_filesystem for the 'system' partition.
  28. // Currently, the only difference is the inclusion of linker.config.pb file which specifies
  29. // the provided and the required libraries to and from APEXes.
  30. func systemImageFactory() android.Module {
  31. module := &systemImage{}
  32. module.AddProperties(&module.properties)
  33. module.filesystem.buildExtraFiles = module.buildExtraFiles
  34. module.filesystem.filterPackagingSpecs = module.filterPackagingSpecs
  35. initFilesystemModule(&module.filesystem)
  36. return module
  37. }
  38. func (s *systemImage) buildExtraFiles(ctx android.ModuleContext, root android.OutputPath) android.OutputPaths {
  39. lc := s.buildLinkerConfigFile(ctx, root)
  40. // Add more files if needed
  41. return []android.OutputPath{lc}
  42. }
  43. func (s *systemImage) buildLinkerConfigFile(ctx android.ModuleContext, root android.OutputPath) android.OutputPath {
  44. input := android.PathForModuleSrc(ctx, android.String(s.properties.Linker_config_src))
  45. output := root.Join(ctx, "system", "etc", "linker.config.pb")
  46. // we need "Module"s for packaging items
  47. var otherModules []android.Module
  48. deps := s.gatherFilteredPackagingSpecs(ctx)
  49. ctx.WalkDeps(func(child, parent android.Module) bool {
  50. for _, ps := range child.PackagingSpecs() {
  51. if _, ok := deps[ps.RelPathInPackage()]; ok {
  52. otherModules = append(otherModules, child)
  53. }
  54. }
  55. return true
  56. })
  57. builder := android.NewRuleBuilder(pctx, ctx)
  58. linkerconfig.BuildLinkerConfig(ctx, builder, input, otherModules, output)
  59. builder.Build("conv_linker_config", "Generate linker config protobuf "+output.String())
  60. return output
  61. }
  62. // Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition.
  63. // Note that "apex" module installs its contents to "apex"(fake partition) as well
  64. // for symbol lookup by imitating "activated" paths.
  65. func (s *systemImage) filterPackagingSpecs(specs map[string]android.PackagingSpec) {
  66. for k, ps := range specs {
  67. if ps.Partition() != "system" {
  68. delete(specs, k)
  69. }
  70. }
  71. }