blob: 4a29fee8732ea487fae3542c86b2002fa013b1d2 [file] [log] [blame]
Kiyoung Kimfaf6af32024-08-12 11:15:19 +09001// 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
Yu Liu0a37d422025-02-13 02:05:00 +000017import "github.com/google/blueprint"
18
Kiyoung Kimfaf6af32024-08-12 11:15:19 +090019type vintfFragmentProperties struct {
20 // Vintf fragment XML file.
21 Src string `android:"path"`
22}
23
Kiyoung Kim11ad4e92024-09-04 14:16:47 +090024type VintfFragmentModule struct {
Kiyoung Kimfaf6af32024-08-12 11:15:19 +090025 ModuleBase
Kiyoung Kim11ad4e92024-09-04 14:16:47 +090026 ApexModuleBase
Kiyoung Kimfaf6af32024-08-12 11:15:19 +090027
28 properties vintfFragmentProperties
29
30 installDirPath InstallPath
Cole Faust4e9f5922024-11-13 16:09:23 -080031 outputFilePath Path
Kiyoung Kimfaf6af32024-08-12 11:15:19 +090032}
33
34func init() {
35 registerVintfFragmentComponents(InitRegistrationContext)
36}
37
38func registerVintfFragmentComponents(ctx RegistrationContext) {
39 ctx.RegisterModuleType("vintf_fragment", vintfLibraryFactory)
40}
41
Yu Liu0a37d422025-02-13 02:05:00 +000042type VintfFragmentInfo struct {
43 OutputFile Path
44}
45
46var VintfFragmentInfoProvider = blueprint.NewProvider[VintfFragmentInfo]()
47
Kiyoung Kimfaf6af32024-08-12 11:15:19 +090048// 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 {
Kiyoung Kim11ad4e92024-09-04 14:16:47 +090052 m := &VintfFragmentModule{}
Kiyoung Kimfaf6af32024-08-12 11:15:19 +090053 m.AddProperties(
54 &m.properties,
55 )
Cole Faust8ea25032024-10-11 16:28:14 -070056 InitAndroidArchModule(m, DeviceSupported, MultilibCommon)
Kiyoung Kimfaf6af32024-08-12 11:15:19 +090057
58 return m
59}
60
Kiyoung Kim11ad4e92024-09-04 14:16:47 +090061func (m *VintfFragmentModule) GenerateAndroidBuildActions(ctx ModuleContext) {
Kiyoung Kimfaf6af32024-08-12 11:15:19 +090062 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")
Cole Faust4e9f5922024-11-13 16:09:23 -080076 m.outputFilePath = processedVintfFragment
Kiyoung Kimfaf6af32024-08-12 11:15:19 +090077
78 ctx.InstallFile(m.installDirPath, processedVintfFragment.Base(), processedVintfFragment)
Yu Liu0a37d422025-02-13 02:05:00 +000079
80 SetProvider(ctx, VintfFragmentInfoProvider, VintfFragmentInfo{
81 OutputFile: m.OutputFile(),
82 })
Kiyoung Kimfaf6af32024-08-12 11:15:19 +090083}
84
Kiyoung Kim11ad4e92024-09-04 14:16:47 +090085func (m *VintfFragmentModule) OutputFile() Path {
86 return m.outputFilePath
87}
88
Kiyoung Kimfaf6af32024-08-12 11:15:19 +090089// Make this module visible to AndroidMK so it can be referenced from modules defined from Android.mk files
Kiyoung Kim11ad4e92024-09-04 14:16:47 +090090func (m *VintfFragmentModule) AndroidMkEntries() []AndroidMkEntries {
Kiyoung Kimfaf6af32024-08-12 11:15:19 +090091 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}
Kiyoung Kim11ad4e92024-09-04 14:16:47 +0900102
103var _ ApexModule = (*VintfFragmentModule)(nil)
104
105// Implements android.ApexModule
Yu Liudf0b8392025-02-12 18:27:03 +0000106func (m *VintfFragmentModule) MinSdkVersionSupported(ctx BaseModuleContext) ApiLevel {
107 return MinApiLevel
Kiyoung Kim11ad4e92024-09-04 14:16:47 +0900108}