blob: 42eaaf01a0ac0dc15878369edadf02186e6f1bab [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
17type vintfFragmentProperties struct {
18 // Vintf fragment XML file.
19 Src string `android:"path"`
20}
21
22type vintfFragmentModule struct {
23 ModuleBase
24
25 properties vintfFragmentProperties
26
27 installDirPath InstallPath
28 outputFilePath OutputPath
29}
30
31func init() {
32 registerVintfFragmentComponents(InitRegistrationContext)
33}
34
35func registerVintfFragmentComponents(ctx RegistrationContext) {
36 ctx.RegisterModuleType("vintf_fragment", vintfLibraryFactory)
37}
38
39// vintf_fragment module processes vintf fragment file and installs under etc/vintf/manifest.
40// Vintf fragment files formerly listed in vintf_fragment property would be transformed into
41// this module type.
42func vintfLibraryFactory() Module {
43 m := &vintfFragmentModule{}
44 m.AddProperties(
45 &m.properties,
46 )
Cole Faust8ea25032024-10-11 16:28:14 -070047 InitAndroidArchModule(m, DeviceSupported, MultilibCommon)
Kiyoung Kimfaf6af32024-08-12 11:15:19 +090048
49 return m
50}
51
52func (m *vintfFragmentModule) GenerateAndroidBuildActions(ctx ModuleContext) {
53 builder := NewRuleBuilder(pctx, ctx)
54 srcVintfFragment := PathForModuleSrc(ctx, m.properties.Src)
55 processedVintfFragment := PathForModuleOut(ctx, srcVintfFragment.Base())
56
57 // Process vintf fragment source file with assemble_vintf tool
58 builder.Command().
59 Flag("VINTF_IGNORE_TARGET_FCM_VERSION=true").
60 BuiltTool("assemble_vintf").
61 FlagWithInput("-i ", srcVintfFragment).
62 FlagWithOutput("-o ", processedVintfFragment)
63
64 builder.Build("assemble_vintf", "Process vintf fragment "+processedVintfFragment.String())
65
66 m.installDirPath = PathForModuleInstall(ctx, "etc", "vintf", "manifest")
67 m.outputFilePath = processedVintfFragment.OutputPath
68
69 ctx.InstallFile(m.installDirPath, processedVintfFragment.Base(), processedVintfFragment)
70}
71
72// Make this module visible to AndroidMK so it can be referenced from modules defined from Android.mk files
73func (m *vintfFragmentModule) AndroidMkEntries() []AndroidMkEntries {
74 return []AndroidMkEntries{{
75 Class: "ETC",
76 OutputFile: OptionalPathForPath(m.outputFilePath),
77 ExtraEntries: []AndroidMkExtraEntriesFunc{
78 func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries) {
79 entries.SetString("LOCAL_MODULE_PATH", m.installDirPath.String())
80 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", m.outputFilePath.Base())
81 },
82 },
83 }}
84}