xref: /aosp_15_r20/build/soong/filesystem/system_image.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
1*333d2b36SAndroid Build Coastguard Worker// Copyright (C) 2021 The Android Open Source Project
2*333d2b36SAndroid Build Coastguard Worker//
3*333d2b36SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License");
4*333d2b36SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License.
5*333d2b36SAndroid Build Coastguard Worker// You may obtain a copy of the License at
6*333d2b36SAndroid Build Coastguard Worker//
7*333d2b36SAndroid Build Coastguard Worker//     http://www.apache.org/licenses/LICENSE-2.0
8*333d2b36SAndroid Build Coastguard Worker//
9*333d2b36SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software
10*333d2b36SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS,
11*333d2b36SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*333d2b36SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and
13*333d2b36SAndroid Build Coastguard Worker// limitations under the License.
14*333d2b36SAndroid Build Coastguard Worker
15*333d2b36SAndroid Build Coastguard Workerpackage filesystem
16*333d2b36SAndroid Build Coastguard Worker
17*333d2b36SAndroid Build Coastguard Workerimport (
18*333d2b36SAndroid Build Coastguard Worker	"android/soong/android"
19*333d2b36SAndroid Build Coastguard Worker	"android/soong/linkerconfig"
20*333d2b36SAndroid Build Coastguard Worker
21*333d2b36SAndroid Build Coastguard Worker	"strings"
22*333d2b36SAndroid Build Coastguard Worker
23*333d2b36SAndroid Build Coastguard Worker	"github.com/google/blueprint/proptools"
24*333d2b36SAndroid Build Coastguard Worker)
25*333d2b36SAndroid Build Coastguard Worker
26*333d2b36SAndroid Build Coastguard Workertype systemImage struct {
27*333d2b36SAndroid Build Coastguard Worker	filesystem
28*333d2b36SAndroid Build Coastguard Worker}
29*333d2b36SAndroid Build Coastguard Worker
30*333d2b36SAndroid Build Coastguard Workervar _ filesystemBuilder = (*systemImage)(nil)
31*333d2b36SAndroid Build Coastguard Worker
32*333d2b36SAndroid Build Coastguard Worker// android_system_image is a specialization of android_filesystem for the 'system' partition.
33*333d2b36SAndroid Build Coastguard Worker// Currently, the only difference is the inclusion of linker.config.pb file which specifies
34*333d2b36SAndroid Build Coastguard Worker// the provided and the required libraries to and from APEXes.
35*333d2b36SAndroid Build Coastguard Workerfunc SystemImageFactory() android.Module {
36*333d2b36SAndroid Build Coastguard Worker	module := &systemImage{}
37*333d2b36SAndroid Build Coastguard Worker	module.filesystemBuilder = module
38*333d2b36SAndroid Build Coastguard Worker	initFilesystemModule(module, &module.filesystem)
39*333d2b36SAndroid Build Coastguard Worker	return module
40*333d2b36SAndroid Build Coastguard Worker}
41*333d2b36SAndroid Build Coastguard Worker
42*333d2b36SAndroid Build Coastguard Workerfunc (s systemImage) FsProps() FilesystemProperties {
43*333d2b36SAndroid Build Coastguard Worker	return s.filesystem.properties
44*333d2b36SAndroid Build Coastguard Worker}
45*333d2b36SAndroid Build Coastguard Worker
46*333d2b36SAndroid Build Coastguard Workerfunc (s *systemImage) BuildLinkerConfigFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) {
47*333d2b36SAndroid Build Coastguard Worker	if !proptools.Bool(s.filesystem.properties.Linker_config.Gen_linker_config) {
48*333d2b36SAndroid Build Coastguard Worker		return
49*333d2b36SAndroid Build Coastguard Worker	}
50*333d2b36SAndroid Build Coastguard Worker
51*333d2b36SAndroid Build Coastguard Worker	provideModules, requireModules := s.getLibsForLinkerConfig(ctx)
52*333d2b36SAndroid Build Coastguard Worker	output := rebasedDir.Join(ctx, "etc", "linker.config.pb")
53*333d2b36SAndroid Build Coastguard Worker	linkerconfig.BuildLinkerConfig(ctx, builder, android.PathsForModuleSrc(ctx, s.filesystem.properties.Linker_config.Linker_config_srcs), provideModules, requireModules, output)
54*333d2b36SAndroid Build Coastguard Worker
55*333d2b36SAndroid Build Coastguard Worker	s.appendToEntry(ctx, output)
56*333d2b36SAndroid Build Coastguard Worker}
57*333d2b36SAndroid Build Coastguard Worker
58*333d2b36SAndroid Build Coastguard Worker// Filter the result of GatherPackagingSpecs to discard items targeting outside "system" / "root"
59*333d2b36SAndroid Build Coastguard Worker// partition.  Note that "apex" module installs its contents to "apex"(fake partition) as well
60*333d2b36SAndroid Build Coastguard Worker// for symbol lookup by imitating "activated" paths.
61*333d2b36SAndroid Build Coastguard Workerfunc (s *systemImage) FilterPackagingSpec(ps android.PackagingSpec) bool {
62*333d2b36SAndroid Build Coastguard Worker	return !ps.SkipInstall() &&
63*333d2b36SAndroid Build Coastguard Worker		(ps.Partition() == "system" || ps.Partition() == "root" ||
64*333d2b36SAndroid Build Coastguard Worker			strings.HasPrefix(ps.Partition(), "system/"))
65*333d2b36SAndroid Build Coastguard Worker}
66*333d2b36SAndroid Build Coastguard Worker
67*333d2b36SAndroid Build Coastguard Workerfunc (s *systemImage) ShouldUseVintfFragmentModuleOnly() bool {
68*333d2b36SAndroid Build Coastguard Worker	return true
69*333d2b36SAndroid Build Coastguard Worker}
70