xref: /aosp_15_r20/build/soong/filesystem/system_image.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
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
15package filesystem
16
17import (
18	"android/soong/android"
19	"android/soong/linkerconfig"
20
21	"strings"
22
23	"github.com/google/blueprint/proptools"
24)
25
26type systemImage struct {
27	filesystem
28}
29
30var _ filesystemBuilder = (*systemImage)(nil)
31
32// android_system_image is a specialization of android_filesystem for the 'system' partition.
33// Currently, the only difference is the inclusion of linker.config.pb file which specifies
34// the provided and the required libraries to and from APEXes.
35func SystemImageFactory() android.Module {
36	module := &systemImage{}
37	module.filesystemBuilder = module
38	initFilesystemModule(module, &module.filesystem)
39	return module
40}
41
42func (s systemImage) FsProps() FilesystemProperties {
43	return s.filesystem.properties
44}
45
46func (s *systemImage) BuildLinkerConfigFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) {
47	if !proptools.Bool(s.filesystem.properties.Linker_config.Gen_linker_config) {
48		return
49	}
50
51	provideModules, requireModules := s.getLibsForLinkerConfig(ctx)
52	output := rebasedDir.Join(ctx, "etc", "linker.config.pb")
53	linkerconfig.BuildLinkerConfig(ctx, builder, android.PathsForModuleSrc(ctx, s.filesystem.properties.Linker_config.Linker_config_srcs), provideModules, requireModules, output)
54
55	s.appendToEntry(ctx, output)
56}
57
58// Filter the result of GatherPackagingSpecs to discard items targeting outside "system" / "root"
59// partition.  Note that "apex" module installs its contents to "apex"(fake partition) as well
60// for symbol lookup by imitating "activated" paths.
61func (s *systemImage) FilterPackagingSpec(ps android.PackagingSpec) bool {
62	return !ps.SkipInstall() &&
63		(ps.Partition() == "system" || ps.Partition() == "root" ||
64			strings.HasPrefix(ps.Partition(), "system/"))
65}
66
67func (s *systemImage) ShouldUseVintfFragmentModuleOnly() bool {
68	return true
69}
70