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. |
| 30 | Linker_config_src *string |
| 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. |
| 36 | func systemImageFactory() android.Module { |
| 37 | module := &systemImage{} |
| 38 | module.AddProperties(&module.properties) |
| 39 | module.filesystem.buildExtraFiles = module.buildExtraFiles |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 40 | module.filesystem.filterPackagingSpecs = module.filterPackagingSpecs |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 41 | initFilesystemModule(&module.filesystem) |
| 42 | return module |
| 43 | } |
| 44 | |
| 45 | func (s *systemImage) buildExtraFiles(ctx android.ModuleContext, root android.OutputPath) android.OutputPaths { |
| 46 | lc := s.buildLinkerConfigFile(ctx, root) |
| 47 | // Add more files if needed |
| 48 | return []android.OutputPath{lc} |
| 49 | } |
| 50 | |
| 51 | func (s *systemImage) buildLinkerConfigFile(ctx android.ModuleContext, root android.OutputPath) android.OutputPath { |
| 52 | input := android.PathForModuleSrc(ctx, android.String(s.properties.Linker_config_src)) |
| 53 | output := root.Join(ctx, "system", "etc", "linker.config.pb") |
Jooyung Han | df09d17 | 2021-05-11 11:13:30 +0900 | [diff] [blame] | 54 | |
| 55 | // we need "Module"s for packaging items |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 56 | var otherModules []android.Module |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 57 | deps := s.gatherFilteredPackagingSpecs(ctx) |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 58 | ctx.WalkDeps(func(child, parent android.Module) bool { |
Jooyung Han | df09d17 | 2021-05-11 11:13:30 +0900 | [diff] [blame] | 59 | for _, ps := range child.PackagingSpecs() { |
| 60 | if _, ok := deps[ps.RelPathInPackage()]; ok { |
| 61 | otherModules = append(otherModules, child) |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 62 | } |
| 63 | } |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 64 | return true |
| 65 | }) |
Jooyung Han | df09d17 | 2021-05-11 11:13:30 +0900 | [diff] [blame] | 66 | |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 67 | builder := android.NewRuleBuilder(pctx, ctx) |
| 68 | linkerconfig.BuildLinkerConfig(ctx, builder, input, otherModules, output) |
| 69 | builder.Build("conv_linker_config", "Generate linker config protobuf "+output.String()) |
| 70 | return output |
| 71 | } |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 72 | |
| 73 | // Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition. |
| 74 | // Note that "apex" module installs its contents to "apex"(fake partition) as well |
| 75 | // for symbol lookup by imitating "activated" paths. |
| 76 | func (s *systemImage) filterPackagingSpecs(specs map[string]android.PackagingSpec) { |
| 77 | for k, ps := range specs { |
| 78 | if ps.Partition() != "system" { |
| 79 | delete(specs, k) |
| 80 | } |
| 81 | } |
| 82 | } |