Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 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 | |
| 15 | package filesystem |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/linkerconfig" |
| 20 | ) |
| 21 | |
| 22 | type systemImage struct { |
| 23 | filesystem |
| 24 | |
| 25 | properties systemImageProperties |
| 26 | } |
| 27 | |
| 28 | type systemImageProperties struct { |
| 29 | // Path to the input linker config json file. |
Justin Yun | 903856e | 2024-09-12 15:14:06 +0900 | [diff] [blame] | 30 | Linker_config_src *string `android:"path"` |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | // android_system_image is a specialization of android_filesystem for the 'system' partition. |
| 34 | // Currently, the only difference is the inclusion of linker.config.pb file which specifies |
| 35 | // the provided and the required libraries to and from APEXes. |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 36 | func SystemImageFactory() android.Module { |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 37 | module := &systemImage{} |
| 38 | module.AddProperties(&module.properties) |
| 39 | module.filesystem.buildExtraFiles = module.buildExtraFiles |
Jeongik Cha | 54bf875 | 2024-02-08 10:44:37 +0900 | [diff] [blame] | 40 | module.filesystem.filterPackagingSpec = module.filterPackagingSpec |
Cole Faust | 2cfe696 | 2024-09-17 11:31:14 -0700 | [diff] [blame] | 41 | initFilesystemModule(module, &module.filesystem) |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 42 | return module |
| 43 | } |
| 44 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 45 | func (s systemImage) FsProps() FilesystemProperties { |
| 46 | return s.filesystem.properties |
| 47 | } |
| 48 | |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 49 | func (s *systemImage) buildExtraFiles(ctx android.ModuleContext, root android.OutputPath) android.OutputPaths { |
Cole Faust | 9a24d90 | 2024-03-18 15:38:12 -0700 | [diff] [blame] | 50 | if s.filesystem.properties.Partition_type != nil { |
| 51 | ctx.PropertyErrorf("partition_type", "partition_type must be unset on an android_system_image module. It is assumed to be 'system'.") |
| 52 | } |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 53 | lc := s.buildLinkerConfigFile(ctx, root) |
| 54 | // Add more files if needed |
| 55 | return []android.OutputPath{lc} |
| 56 | } |
| 57 | |
| 58 | func (s *systemImage) buildLinkerConfigFile(ctx android.ModuleContext, root android.OutputPath) android.OutputPath { |
| 59 | input := android.PathForModuleSrc(ctx, android.String(s.properties.Linker_config_src)) |
| 60 | output := root.Join(ctx, "system", "etc", "linker.config.pb") |
Jooyung Han | df09d17 | 2021-05-11 11:13:30 +0900 | [diff] [blame] | 61 | |
| 62 | // we need "Module"s for packaging items |
Kiyoung Kim | ee599d6 | 2024-03-22 18:00:40 +0900 | [diff] [blame] | 63 | modulesInPackageByModule := make(map[android.Module]bool) |
| 64 | modulesInPackageByName := make(map[string]bool) |
| 65 | |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 66 | deps := s.gatherFilteredPackagingSpecs(ctx) |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 67 | ctx.WalkDeps(func(child, parent android.Module) bool { |
Yu Liu | d46e5ae | 2024-08-15 18:46:17 +0000 | [diff] [blame] | 68 | for _, ps := range android.OtherModuleProviderOrDefault( |
| 69 | ctx, child, android.InstallFilesProvider).PackagingSpecs { |
Jooyung Han | df09d17 | 2021-05-11 11:13:30 +0900 | [diff] [blame] | 70 | if _, ok := deps[ps.RelPathInPackage()]; ok { |
Kiyoung Kim | ee599d6 | 2024-03-22 18:00:40 +0900 | [diff] [blame] | 71 | modulesInPackageByModule[child] = true |
| 72 | modulesInPackageByName[child.Name()] = true |
| 73 | return true |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 74 | } |
| 75 | } |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 76 | return true |
| 77 | }) |
Jooyung Han | df09d17 | 2021-05-11 11:13:30 +0900 | [diff] [blame] | 78 | |
Kiyoung Kim | ee599d6 | 2024-03-22 18:00:40 +0900 | [diff] [blame] | 79 | provideModules := make([]android.Module, 0, len(modulesInPackageByModule)) |
| 80 | for mod := range modulesInPackageByModule { |
| 81 | provideModules = append(provideModules, mod) |
| 82 | } |
| 83 | |
| 84 | var requireModules []android.Module |
| 85 | ctx.WalkDeps(func(child, parent android.Module) bool { |
| 86 | _, parentInPackage := modulesInPackageByModule[parent] |
| 87 | _, childInPackageName := modulesInPackageByName[child.Name()] |
| 88 | |
| 89 | // When parent is in the package, and child (or its variant) is not, this can be from an interface. |
| 90 | if parentInPackage && !childInPackageName { |
| 91 | requireModules = append(requireModules, child) |
| 92 | } |
| 93 | return true |
| 94 | }) |
| 95 | |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 96 | builder := android.NewRuleBuilder(pctx, ctx) |
Kiyoung Kim | ee599d6 | 2024-03-22 18:00:40 +0900 | [diff] [blame] | 97 | linkerconfig.BuildLinkerConfig(ctx, builder, input, provideModules, requireModules, output) |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 98 | builder.Build("conv_linker_config", "Generate linker config protobuf "+output.String()) |
| 99 | return output |
| 100 | } |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 101 | |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame] | 102 | // Filter the result of GatherPackagingSpecs to discard items targeting outside "system" / "root" |
| 103 | // partition. Note that "apex" module installs its contents to "apex"(fake partition) as well |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 104 | // for symbol lookup by imitating "activated" paths. |
Jeongik Cha | 54bf875 | 2024-02-08 10:44:37 +0900 | [diff] [blame] | 105 | func (s *systemImage) filterPackagingSpec(ps android.PackagingSpec) bool { |
Pechetty Sravani (xWF) | 02adec8 | 2024-10-21 02:17:40 +0000 | [diff] [blame^] | 106 | return s.filesystem.filterInstallablePackagingSpec(ps) && |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame] | 107 | (ps.Partition() == "system" || ps.Partition() == "root") |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 108 | } |