blob: 92bb206bc1b663b83bf63179bc13ddbfbdb02859 [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
Jiyong Parkeaac8232024-03-31 21:27:45 +090024 android.DefaultableModuleBase
Jiyong Parkfa616132021-04-20 11:36:40 +090025
26 properties systemImageProperties
27}
28
29type systemImageProperties struct {
30 // Path to the input linker config json file.
31 Linker_config_src *string
32}
33
34// android_system_image is a specialization of android_filesystem for the 'system' partition.
35// Currently, the only difference is the inclusion of linker.config.pb file which specifies
36// the provided and the required libraries to and from APEXes.
37func systemImageFactory() android.Module {
38 module := &systemImage{}
39 module.AddProperties(&module.properties)
40 module.filesystem.buildExtraFiles = module.buildExtraFiles
Jeongik Cha54bf8752024-02-08 10:44:37 +090041 module.filesystem.filterPackagingSpec = module.filterPackagingSpec
Jiyong Parkfa616132021-04-20 11:36:40 +090042 initFilesystemModule(&module.filesystem)
Jiyong Parkeaac8232024-03-31 21:27:45 +090043 android.InitDefaultableModule(module)
Jiyong Parkfa616132021-04-20 11:36:40 +090044 return module
45}
46
47func (s *systemImage) buildExtraFiles(ctx android.ModuleContext, root android.OutputPath) android.OutputPaths {
Cole Faust9a24d902024-03-18 15:38:12 -070048 if s.filesystem.properties.Partition_type != nil {
49 ctx.PropertyErrorf("partition_type", "partition_type must be unset on an android_system_image module. It is assumed to be 'system'.")
50 }
Jiyong Parkfa616132021-04-20 11:36:40 +090051 lc := s.buildLinkerConfigFile(ctx, root)
52 // Add more files if needed
53 return []android.OutputPath{lc}
54}
55
56func (s *systemImage) buildLinkerConfigFile(ctx android.ModuleContext, root android.OutputPath) android.OutputPath {
57 input := android.PathForModuleSrc(ctx, android.String(s.properties.Linker_config_src))
58 output := root.Join(ctx, "system", "etc", "linker.config.pb")
Jooyung Handf09d172021-05-11 11:13:30 +090059
60 // we need "Module"s for packaging items
Kiyoung Kimee599d62024-03-22 18:00:40 +090061 modulesInPackageByModule := make(map[android.Module]bool)
62 modulesInPackageByName := make(map[string]bool)
63
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090064 deps := s.gatherFilteredPackagingSpecs(ctx)
Jiyong Parkfa616132021-04-20 11:36:40 +090065 ctx.WalkDeps(func(child, parent android.Module) bool {
Jooyung Handf09d172021-05-11 11:13:30 +090066 for _, ps := range child.PackagingSpecs() {
67 if _, ok := deps[ps.RelPathInPackage()]; ok {
Kiyoung Kimee599d62024-03-22 18:00:40 +090068 modulesInPackageByModule[child] = true
69 modulesInPackageByName[child.Name()] = true
70 return true
Jiyong Parkfa616132021-04-20 11:36:40 +090071 }
72 }
Jiyong Parkfa616132021-04-20 11:36:40 +090073 return true
74 })
Jooyung Handf09d172021-05-11 11:13:30 +090075
Kiyoung Kimee599d62024-03-22 18:00:40 +090076 provideModules := make([]android.Module, 0, len(modulesInPackageByModule))
77 for mod := range modulesInPackageByModule {
78 provideModules = append(provideModules, mod)
79 }
80
81 var requireModules []android.Module
82 ctx.WalkDeps(func(child, parent android.Module) bool {
83 _, parentInPackage := modulesInPackageByModule[parent]
84 _, childInPackageName := modulesInPackageByName[child.Name()]
85
86 // When parent is in the package, and child (or its variant) is not, this can be from an interface.
87 if parentInPackage && !childInPackageName {
88 requireModules = append(requireModules, child)
89 }
90 return true
91 })
92
Jiyong Parkfa616132021-04-20 11:36:40 +090093 builder := android.NewRuleBuilder(pctx, ctx)
Kiyoung Kimee599d62024-03-22 18:00:40 +090094 linkerconfig.BuildLinkerConfig(ctx, builder, input, provideModules, requireModules, output)
Jiyong Parkfa616132021-04-20 11:36:40 +090095 builder.Build("conv_linker_config", "Generate linker config protobuf "+output.String())
96 return output
97}
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090098
99// Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition.
100// Note that "apex" module installs its contents to "apex"(fake partition) as well
101// for symbol lookup by imitating "activated" paths.
Jeongik Cha54bf8752024-02-08 10:44:37 +0900102func (s *systemImage) filterPackagingSpec(ps android.PackagingSpec) bool {
103 return ps.Partition() == "system"
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900104}
Jiyong Parkeaac8232024-03-31 21:27:45 +0900105
106type systemImageDefaults struct {
107 android.ModuleBase
108 android.DefaultsModuleBase
109}
110
111// android_system_image_defaults is a default module for android_system_image module.
112func systemImageDefaultsFactory() android.Module {
113 module := &systemImageDefaults{}
114 module.AddProperties(&android.PackagingProperties{})
115 module.AddProperties(&systemImageProperties{})
116 android.InitDefaultsModule(module)
117 return module
118}