blob: 85beb725ca151508c21f6a99485bc2cc6c82c52c [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
Kiyoung Kim11ad4e92024-09-04 14:16:47 +090022type VintfFragmentModule struct {
Kiyoung Kimfaf6af32024-08-12 11:15:19 +090023 ModuleBase
Kiyoung Kim11ad4e92024-09-04 14:16:47 +090024 ApexModuleBase
Kiyoung Kimfaf6af32024-08-12 11:15:19 +090025
26 properties vintfFragmentProperties
27
28 installDirPath InstallPath
Cole Faust4e9f5922024-11-13 16:09:23 -080029 outputFilePath Path
Kiyoung Kimfaf6af32024-08-12 11:15:19 +090030}
31
32func init() {
33 registerVintfFragmentComponents(InitRegistrationContext)
34}
35
36func registerVintfFragmentComponents(ctx RegistrationContext) {
37 ctx.RegisterModuleType("vintf_fragment", vintfLibraryFactory)
38}
39
40// vintf_fragment module processes vintf fragment file and installs under etc/vintf/manifest.
41// Vintf fragment files formerly listed in vintf_fragment property would be transformed into
42// this module type.
43func vintfLibraryFactory() Module {
Kiyoung Kim11ad4e92024-09-04 14:16:47 +090044 m := &VintfFragmentModule{}
Kiyoung Kimfaf6af32024-08-12 11:15:19 +090045 m.AddProperties(
46 &m.properties,
47 )
Cole Faust8ea25032024-10-11 16:28:14 -070048 InitAndroidArchModule(m, DeviceSupported, MultilibCommon)
Kiyoung Kimfaf6af32024-08-12 11:15:19 +090049
50 return m
51}
52
Kiyoung Kim11ad4e92024-09-04 14:16:47 +090053func (m *VintfFragmentModule) GenerateAndroidBuildActions(ctx ModuleContext) {
Kiyoung Kimfaf6af32024-08-12 11:15:19 +090054 builder := NewRuleBuilder(pctx, ctx)
55 srcVintfFragment := PathForModuleSrc(ctx, m.properties.Src)
56 processedVintfFragment := PathForModuleOut(ctx, srcVintfFragment.Base())
57
58 // Process vintf fragment source file with assemble_vintf tool
59 builder.Command().
60 Flag("VINTF_IGNORE_TARGET_FCM_VERSION=true").
61 BuiltTool("assemble_vintf").
62 FlagWithInput("-i ", srcVintfFragment).
63 FlagWithOutput("-o ", processedVintfFragment)
64
65 builder.Build("assemble_vintf", "Process vintf fragment "+processedVintfFragment.String())
66
67 m.installDirPath = PathForModuleInstall(ctx, "etc", "vintf", "manifest")
Cole Faust4e9f5922024-11-13 16:09:23 -080068 m.outputFilePath = processedVintfFragment
Kiyoung Kimfaf6af32024-08-12 11:15:19 +090069
70 ctx.InstallFile(m.installDirPath, processedVintfFragment.Base(), processedVintfFragment)
71}
72
Kiyoung Kim11ad4e92024-09-04 14:16:47 +090073func (m *VintfFragmentModule) OutputFile() Path {
74 return m.outputFilePath
75}
76
Kiyoung Kimfaf6af32024-08-12 11:15:19 +090077// 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 +090078func (m *VintfFragmentModule) AndroidMkEntries() []AndroidMkEntries {
Kiyoung Kimfaf6af32024-08-12 11:15:19 +090079 return []AndroidMkEntries{{
80 Class: "ETC",
81 OutputFile: OptionalPathForPath(m.outputFilePath),
82 ExtraEntries: []AndroidMkExtraEntriesFunc{
83 func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries) {
84 entries.SetString("LOCAL_MODULE_PATH", m.installDirPath.String())
85 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", m.outputFilePath.Base())
86 },
87 },
88 }}
89}
Kiyoung Kim11ad4e92024-09-04 14:16:47 +090090
91var _ ApexModule = (*VintfFragmentModule)(nil)
92
93// Implements android.ApexModule
94func (m *VintfFragmentModule) ShouldSupportSdkVersion(ctx BaseModuleContext, sdkVersion ApiLevel) error {
95 // VintfFragmetModule is independent from the SDK version.
96 return nil
97}