blob: a7c914395b90ad153e27a0dd6495e89eb6f238e1 [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.
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.
36func systemImageFactory() android.Module {
37 module := &systemImage{}
38 module.AddProperties(&module.properties)
39 module.filesystem.buildExtraFiles = module.buildExtraFiles
40 initFilesystemModule(&module.filesystem)
41 return module
42}
43
44func (s *systemImage) buildExtraFiles(ctx android.ModuleContext, root android.OutputPath) android.OutputPaths {
45 lc := s.buildLinkerConfigFile(ctx, root)
46 // Add more files if needed
47 return []android.OutputPath{lc}
48}
49
50func (s *systemImage) buildLinkerConfigFile(ctx android.ModuleContext, root android.OutputPath) android.OutputPath {
51 input := android.PathForModuleSrc(ctx, android.String(s.properties.Linker_config_src))
52 output := root.Join(ctx, "system", "etc", "linker.config.pb")
53 var otherModules []android.Module
54 ctx.WalkDeps(func(child, parent android.Module) bool {
55 // Don't track direct dependencies that aren't not packaged
56 if parent == s {
57 if pi, ok := ctx.OtherModuleDependencyTag(child).(android.PackagingItem); !ok || !pi.IsPackagingItem() {
58 return false
59 }
60 }
61 otherModules = append(otherModules, child)
62 return true
63 })
64 builder := android.NewRuleBuilder(pctx, ctx)
65 linkerconfig.BuildLinkerConfig(ctx, builder, input, otherModules, output)
66 builder.Build("conv_linker_config", "Generate linker config protobuf "+output.String())
67 return output
68}