blob: 63cb627d85c3b881fb56c888f367f22ebc6aeb3b [file] [log] [blame]
Jiyong Parkfa616132021-04-20 11:36:40 +09001// 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
15package filesystem
16
17import (
18 "android/soong/android"
19 "android/soong/linkerconfig"
20)
21
22type systemImage struct {
23 filesystem
24
25 properties systemImageProperties
26}
27
28type systemImageProperties struct {
29 // Path to the input linker config json file.
Justin Yun903856e2024-09-12 15:14:06 +090030 Linker_config_src *string `android:"path"`
Jiyong Parkfa616132021-04-20 11:36:40 +090031}
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.
36func systemImageFactory() android.Module {
37 module := &systemImage{}
38 module.AddProperties(&module.properties)
39 module.filesystem.buildExtraFiles = module.buildExtraFiles
Jeongik Cha54bf8752024-02-08 10:44:37 +090040 module.filesystem.filterPackagingSpec = module.filterPackagingSpec
Cole Faust2cfe6962024-09-17 11:31:14 -070041 initFilesystemModule(module, &module.filesystem)
Jiyong Parkfa616132021-04-20 11:36:40 +090042 return module
43}
44
45func (s *systemImage) buildExtraFiles(ctx android.ModuleContext, root android.OutputPath) android.OutputPaths {
Cole Faust9a24d902024-03-18 15:38:12 -070046 if s.filesystem.properties.Partition_type != nil {
47 ctx.PropertyErrorf("partition_type", "partition_type must be unset on an android_system_image module. It is assumed to be 'system'.")
48 }
Jiyong Parkfa616132021-04-20 11:36:40 +090049 lc := s.buildLinkerConfigFile(ctx, root)
50 // Add more files if needed
51 return []android.OutputPath{lc}
52}
53
54func (s *systemImage) buildLinkerConfigFile(ctx android.ModuleContext, root android.OutputPath) android.OutputPath {
55 input := android.PathForModuleSrc(ctx, android.String(s.properties.Linker_config_src))
56 output := root.Join(ctx, "system", "etc", "linker.config.pb")
Jooyung Handf09d172021-05-11 11:13:30 +090057
58 // we need "Module"s for packaging items
Kiyoung Kimee599d62024-03-22 18:00:40 +090059 modulesInPackageByModule := make(map[android.Module]bool)
60 modulesInPackageByName := make(map[string]bool)
61
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090062 deps := s.gatherFilteredPackagingSpecs(ctx)
Jiyong Parkfa616132021-04-20 11:36:40 +090063 ctx.WalkDeps(func(child, parent android.Module) bool {
Yu Liud46e5ae2024-08-15 18:46:17 +000064 for _, ps := range android.OtherModuleProviderOrDefault(
65 ctx, child, android.InstallFilesProvider).PackagingSpecs {
Jooyung Handf09d172021-05-11 11:13:30 +090066 if _, ok := deps[ps.RelPathInPackage()]; ok {
Kiyoung Kimee599d62024-03-22 18:00:40 +090067 modulesInPackageByModule[child] = true
68 modulesInPackageByName[child.Name()] = true
69 return true
Jiyong Parkfa616132021-04-20 11:36:40 +090070 }
71 }
Jiyong Parkfa616132021-04-20 11:36:40 +090072 return true
73 })
Jooyung Handf09d172021-05-11 11:13:30 +090074
Kiyoung Kimee599d62024-03-22 18:00:40 +090075 provideModules := make([]android.Module, 0, len(modulesInPackageByModule))
76 for mod := range modulesInPackageByModule {
77 provideModules = append(provideModules, mod)
78 }
79
80 var requireModules []android.Module
81 ctx.WalkDeps(func(child, parent android.Module) bool {
82 _, parentInPackage := modulesInPackageByModule[parent]
83 _, childInPackageName := modulesInPackageByName[child.Name()]
84
85 // When parent is in the package, and child (or its variant) is not, this can be from an interface.
86 if parentInPackage && !childInPackageName {
87 requireModules = append(requireModules, child)
88 }
89 return true
90 })
91
Jiyong Parkfa616132021-04-20 11:36:40 +090092 builder := android.NewRuleBuilder(pctx, ctx)
Kiyoung Kimee599d62024-03-22 18:00:40 +090093 linkerconfig.BuildLinkerConfig(ctx, builder, input, provideModules, requireModules, output)
Jiyong Parkfa616132021-04-20 11:36:40 +090094 builder.Build("conv_linker_config", "Generate linker config protobuf "+output.String())
95 return output
96}
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090097
Inseob Kim33f95a92024-07-11 15:44:49 +090098// Filter the result of GatherPackagingSpecs to discard items targeting outside "system" / "root"
99// partition. Note that "apex" module installs its contents to "apex"(fake partition) as well
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900100// for symbol lookup by imitating "activated" paths.
Jeongik Cha54bf8752024-02-08 10:44:37 +0900101func (s *systemImage) filterPackagingSpec(ps android.PackagingSpec) bool {
Inseob Kim33f95a92024-07-11 15:44:49 +0900102 return s.filesystem.filterInstallablePackagingSpec(ps) &&
103 (ps.Partition() == "system" || ps.Partition() == "root")
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900104}