blob: 874d20d8095b3781bdc3cfaa7dfead421cd3c8d8 [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"
Cole Faustb43793e2024-12-13 16:53:36 -080019 "android/soong/cc"
Jiyong Parkfa616132021-04-20 11:36:40 +090020 "android/soong/linkerconfig"
Kiyoung Kim67118212024-11-07 13:23:44 +090021
Inseob Kim3c0a0422024-11-05 17:21:37 +090022 "strings"
23
Kiyoung Kim67118212024-11-07 13:23:44 +090024 "github.com/google/blueprint/proptools"
Jiyong Parkfa616132021-04-20 11:36:40 +090025)
26
27type systemImage struct {
28 filesystem
Jiyong Parkfa616132021-04-20 11:36:40 +090029}
30
Kiyoung Kim67118212024-11-07 13:23:44 +090031var _ filesystemBuilder = (*systemImage)(nil)
Jiyong Parkfa616132021-04-20 11:36:40 +090032
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 Kang98047cf2024-10-02 17:13:54 +000036func SystemImageFactory() android.Module {
Jiyong Parkfa616132021-04-20 11:36:40 +090037 module := &systemImage{}
Kiyoung Kim67118212024-11-07 13:23:44 +090038 module.filesystemBuilder = module
Cole Faust2cfe6962024-09-17 11:31:14 -070039 initFilesystemModule(module, &module.filesystem)
Jiyong Parkfa616132021-04-20 11:36:40 +090040 return module
41}
42
Jihoon Kang98047cf2024-10-02 17:13:54 +000043func (s systemImage) FsProps() FilesystemProperties {
44 return s.filesystem.properties
45}
46
Kiyoung Kim67118212024-11-07 13:23:44 +090047func (s *systemImage) BuildLinkerConfigFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) {
Spandan Das2047a4c2024-11-11 21:24:58 +000048 if !proptools.Bool(s.filesystem.properties.Linker_config.Gen_linker_config) {
Kiyoung Kim67118212024-11-07 13:23:44 +090049 return
Cole Faust9a24d902024-03-18 15:38:12 -070050 }
Jooyung Handf09d172021-05-11 11:13:30 +090051
Kiyoung Kim67118212024-11-07 13:23:44 +090052 output := rebasedDir.Join(ctx, "etc", "linker.config.pb")
Cole Faustb43793e2024-12-13 16:53:36 -080053 if s.filesystem.properties.Linker_config.Linker_config_srcs != nil {
54 provideModules, requireModules := s.getLibsForLinkerConfig(ctx)
55 intermediateOutput := android.PathForModuleOut(ctx, "linker.config.pb")
56 linkerconfig.BuildLinkerConfig(ctx, android.PathsForModuleSrc(ctx, s.filesystem.properties.Linker_config.Linker_config_srcs), provideModules, requireModules, intermediateOutput)
57 builder.Command().Text("cp").Input(intermediateOutput).Output(output)
58 } else {
59 // TODO: This branch is the logic that make uses for the linker config file, which is
60 // different than linkerconfig.BuildLinkerConfig used above. Keeping both branches for now
61 // because microdroid uses the other method and is in theory happy with it. But we should
62 // consider deduping them.
63 stubLibraries := cc.StubLibrariesFile(ctx)
64 llndkMovedToApexLibraries := cc.MovedToApexLlndkLibrariesFile(ctx)
65 outputStep1 := android.PathForModuleOut(ctx, "linker.config.pb.step1")
66 builder.Command().
67 BuiltTool("conv_linker_config").
68 Text("proto --force").
69 FlagWithInput("-s ", android.PathForSource(ctx, "system/core/rootdir/etc/linker.config.json")).
70 FlagWithOutput("-o ", outputStep1)
71 builder.Temporary(outputStep1)
72 builder.Command().
73 BuiltTool("conv_linker_config").
74 Text("systemprovide").
75 FlagWithInput("--source ", outputStep1).
76 FlagWithArg("--output ", output.String()).
77 Textf(`--value "$(cat %s)"`, stubLibraries).
78 Implicit(stubLibraries).
79 FlagWithArg("--system ", rebasedDir.String())
80 builder.Command().
81 BuiltTool("conv_linker_config").
82 Text("append").
83 FlagWithArg("--source ", output.String()).
84 FlagWithOutput("--output ", output).
85 FlagWithArg("--key ", "requireLibs").
86 Textf(`--value "$(cat %s)"`, llndkMovedToApexLibraries).
87 Implicit(llndkMovedToApexLibraries)
88 // TODO: Make also supports adding an extra append command with PRODUCT_EXTRA_STUB_LIBRARIES,
89 // but that variable appears to have no usages.
90 }
Kiyoung Kim67118212024-11-07 13:23:44 +090091
92 s.appendToEntry(ctx, output)
Jiyong Parkfa616132021-04-20 11:36:40 +090093}
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090094
Inseob Kim33f95a92024-07-11 15:44:49 +090095// Filter the result of GatherPackagingSpecs to discard items targeting outside "system" / "root"
96// partition. Note that "apex" module installs its contents to "apex"(fake partition) as well
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090097// for symbol lookup by imitating "activated" paths.
Kiyoung Kim67118212024-11-07 13:23:44 +090098func (s *systemImage) FilterPackagingSpec(ps android.PackagingSpec) bool {
Hugo Drumond Jacob69d829a2024-10-21 09:55:45 +000099 return !ps.SkipInstall() &&
Inseob Kim3c0a0422024-11-05 17:21:37 +0900100 (ps.Partition() == "system" || ps.Partition() == "root" ||
101 strings.HasPrefix(ps.Partition(), "system/"))
102}
Kiyoung Kim23be5bb2024-11-27 00:50:30 +0000103
104func (s *systemImage) ShouldUseVintfFragmentModuleOnly() bool {
105 return true
106}