Kiyoung Kim | faf6af3 | 2024-08-12 11:15:19 +0900 | [diff] [blame] | 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 | |
| 15 | package android |
| 16 | |
| 17 | type vintfFragmentProperties struct { |
| 18 | // Vintf fragment XML file. |
| 19 | Src string `android:"path"` |
| 20 | } |
| 21 | |
Kiyoung Kim | 11ad4e9 | 2024-09-04 14:16:47 +0900 | [diff] [blame^] | 22 | type VintfFragmentModule struct { |
Kiyoung Kim | faf6af3 | 2024-08-12 11:15:19 +0900 | [diff] [blame] | 23 | ModuleBase |
Kiyoung Kim | 11ad4e9 | 2024-09-04 14:16:47 +0900 | [diff] [blame^] | 24 | ApexModuleBase |
Kiyoung Kim | faf6af3 | 2024-08-12 11:15:19 +0900 | [diff] [blame] | 25 | |
| 26 | properties vintfFragmentProperties |
| 27 | |
| 28 | installDirPath InstallPath |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 29 | outputFilePath Path |
Kiyoung Kim | faf6af3 | 2024-08-12 11:15:19 +0900 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | func init() { |
| 33 | registerVintfFragmentComponents(InitRegistrationContext) |
| 34 | } |
| 35 | |
| 36 | func 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. |
| 43 | func vintfLibraryFactory() Module { |
Kiyoung Kim | 11ad4e9 | 2024-09-04 14:16:47 +0900 | [diff] [blame^] | 44 | m := &VintfFragmentModule{} |
Kiyoung Kim | faf6af3 | 2024-08-12 11:15:19 +0900 | [diff] [blame] | 45 | m.AddProperties( |
| 46 | &m.properties, |
| 47 | ) |
Cole Faust | 8ea2503 | 2024-10-11 16:28:14 -0700 | [diff] [blame] | 48 | InitAndroidArchModule(m, DeviceSupported, MultilibCommon) |
Kiyoung Kim | faf6af3 | 2024-08-12 11:15:19 +0900 | [diff] [blame] | 49 | |
| 50 | return m |
| 51 | } |
| 52 | |
Kiyoung Kim | 11ad4e9 | 2024-09-04 14:16:47 +0900 | [diff] [blame^] | 53 | func (m *VintfFragmentModule) GenerateAndroidBuildActions(ctx ModuleContext) { |
Kiyoung Kim | faf6af3 | 2024-08-12 11:15:19 +0900 | [diff] [blame] | 54 | 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 Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 68 | m.outputFilePath = processedVintfFragment |
Kiyoung Kim | faf6af3 | 2024-08-12 11:15:19 +0900 | [diff] [blame] | 69 | |
| 70 | ctx.InstallFile(m.installDirPath, processedVintfFragment.Base(), processedVintfFragment) |
| 71 | } |
| 72 | |
Kiyoung Kim | 11ad4e9 | 2024-09-04 14:16:47 +0900 | [diff] [blame^] | 73 | func (m *VintfFragmentModule) OutputFile() Path { |
| 74 | return m.outputFilePath |
| 75 | } |
| 76 | |
Kiyoung Kim | faf6af3 | 2024-08-12 11:15:19 +0900 | [diff] [blame] | 77 | // Make this module visible to AndroidMK so it can be referenced from modules defined from Android.mk files |
Kiyoung Kim | 11ad4e9 | 2024-09-04 14:16:47 +0900 | [diff] [blame^] | 78 | func (m *VintfFragmentModule) AndroidMkEntries() []AndroidMkEntries { |
Kiyoung Kim | faf6af3 | 2024-08-12 11:15:19 +0900 | [diff] [blame] | 79 | 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 Kim | 11ad4e9 | 2024-09-04 14:16:47 +0900 | [diff] [blame^] | 90 | |
| 91 | var _ ApexModule = (*VintfFragmentModule)(nil) |
| 92 | |
| 93 | // Implements android.ApexModule |
| 94 | func (m *VintfFragmentModule) ShouldSupportSdkVersion(ctx BaseModuleContext, sdkVersion ApiLevel) error { |
| 95 | // VintfFragmetModule is independent from the SDK version. |
| 96 | return nil |
| 97 | } |