• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2024 Google Inc. All rights reserved.
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 android
16
17import "github.com/google/blueprint"
18
19type vintfFragmentProperties struct {
20	// Vintf fragment XML file.
21	Src string `android:"path"`
22}
23
24type VintfFragmentModule struct {
25	ModuleBase
26	ApexModuleBase
27
28	properties vintfFragmentProperties
29
30	installDirPath InstallPath
31	outputFilePath Path
32}
33
34func init() {
35	registerVintfFragmentComponents(InitRegistrationContext)
36}
37
38func registerVintfFragmentComponents(ctx RegistrationContext) {
39	ctx.RegisterModuleType("vintf_fragment", vintfLibraryFactory)
40}
41
42type VintfFragmentInfo struct {
43	OutputFile Path
44}
45
46var VintfFragmentInfoProvider = blueprint.NewProvider[VintfFragmentInfo]()
47
48// vintf_fragment module processes vintf fragment file and installs under etc/vintf/manifest.
49// Vintf fragment files formerly listed in vintf_fragment property would be transformed into
50// this module type.
51func vintfLibraryFactory() Module {
52	m := &VintfFragmentModule{}
53	m.AddProperties(
54		&m.properties,
55	)
56	InitAndroidArchModule(m, DeviceSupported, MultilibCommon)
57
58	return m
59}
60
61func (m *VintfFragmentModule) GenerateAndroidBuildActions(ctx ModuleContext) {
62	builder := NewRuleBuilder(pctx, ctx)
63	srcVintfFragment := PathForModuleSrc(ctx, m.properties.Src)
64	processedVintfFragment := PathForModuleOut(ctx, srcVintfFragment.Base())
65
66	// Process vintf fragment source file with assemble_vintf tool
67	builder.Command().
68		Flag("VINTF_IGNORE_TARGET_FCM_VERSION=true").
69		BuiltTool("assemble_vintf").
70		FlagWithInput("-i ", srcVintfFragment).
71		FlagWithOutput("-o ", processedVintfFragment)
72
73	builder.Build("assemble_vintf", "Process vintf fragment "+processedVintfFragment.String())
74
75	m.installDirPath = PathForModuleInstall(ctx, "etc", "vintf", "manifest")
76	m.outputFilePath = processedVintfFragment
77
78	ctx.InstallFile(m.installDirPath, processedVintfFragment.Base(), processedVintfFragment)
79
80	SetProvider(ctx, VintfFragmentInfoProvider, VintfFragmentInfo{
81		OutputFile: m.OutputFile(),
82	})
83}
84
85func (m *VintfFragmentModule) OutputFile() Path {
86	return m.outputFilePath
87}
88
89// Make this module visible to AndroidMK so it can be referenced from modules defined from Android.mk files
90func (m *VintfFragmentModule) AndroidMkEntries() []AndroidMkEntries {
91	return []AndroidMkEntries{{
92		Class:      "ETC",
93		OutputFile: OptionalPathForPath(m.outputFilePath),
94		ExtraEntries: []AndroidMkExtraEntriesFunc{
95			func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries) {
96				entries.SetString("LOCAL_MODULE_PATH", m.installDirPath.String())
97				entries.SetString("LOCAL_INSTALLED_MODULE_STEM", m.outputFilePath.Base())
98			},
99		},
100	}}
101}
102
103var _ ApexModule = (*VintfFragmentModule)(nil)
104
105// Implements android.ApexModule
106func (m *VintfFragmentModule) MinSdkVersionSupported(ctx BaseModuleContext) ApiLevel {
107	return MinApiLevel
108}
109