diff options
author | 2025-02-12 06:37:16 -0800 | |
---|---|---|
committer | 2025-02-12 06:37:16 -0800 | |
commit | 1a49813031ed2829f70d0de92454ff53f4c3da84 (patch) | |
tree | a2fcd3d9f9aa5bc0fb5b489f199395bc86a17932 | |
parent | 719a8807c9d47b192d9f15e0eaa7a4a248d4e17a (diff) | |
parent | 11ad4e940b342fb0bdf700276f9a7b513c3656b0 (diff) |
Merge "Install VINTF fragment modules in the APEX" into main
-rw-r--r-- | android/module.go | 6 | ||||
-rw-r--r-- | android/vintf_fragment.go | 21 | ||||
-rw-r--r-- | apex/apex.go | 12 | ||||
-rw-r--r-- | apex/apex_test.go | 32 | ||||
-rw-r--r-- | apex/builder.go | 7 |
5 files changed, 70 insertions, 8 deletions
diff --git a/android/module.go b/android/module.go index 80275a309..3295e93be 100644 --- a/android/module.go +++ b/android/module.go @@ -1091,6 +1091,10 @@ var vintfDepTag = struct { InstallAlwaysNeededDependencyTag }{} +func IsVintfDepTag(depTag blueprint.DependencyTag) bool { + return depTag == vintfDepTag +} + func addVintfFragmentDeps(ctx BottomUpMutatorContext) { // Vintf manifests in the recovery partition will be ignored. if !ctx.Device() || ctx.Module().InstallInRecovery() { @@ -1109,7 +1113,7 @@ func addVintfFragmentDeps(ctx BottomUpMutatorContext) { // of nil pointer dereference errors, but we should resolve the missing dependencies. continue } - if vintfModule, ok := vintf.(*vintfFragmentModule); ok { + if vintfModule, ok := vintf.(*VintfFragmentModule); ok { vintfPartition := vintfModule.PartitionTag(deviceConfig) if modPartition != vintfPartition { ctx.ModuleErrorf("Module %q(%q) and Vintf_fragment %q(%q) are installed to different partitions.", diff --git a/android/vintf_fragment.go b/android/vintf_fragment.go index a3343fd5a..85beb725c 100644 --- a/android/vintf_fragment.go +++ b/android/vintf_fragment.go @@ -19,8 +19,9 @@ type vintfFragmentProperties struct { Src string `android:"path"` } -type vintfFragmentModule struct { +type VintfFragmentModule struct { ModuleBase + ApexModuleBase properties vintfFragmentProperties @@ -40,7 +41,7 @@ func registerVintfFragmentComponents(ctx RegistrationContext) { // Vintf fragment files formerly listed in vintf_fragment property would be transformed into // this module type. func vintfLibraryFactory() Module { - m := &vintfFragmentModule{} + m := &VintfFragmentModule{} m.AddProperties( &m.properties, ) @@ -49,7 +50,7 @@ func vintfLibraryFactory() Module { return m } -func (m *vintfFragmentModule) GenerateAndroidBuildActions(ctx ModuleContext) { +func (m *VintfFragmentModule) GenerateAndroidBuildActions(ctx ModuleContext) { builder := NewRuleBuilder(pctx, ctx) srcVintfFragment := PathForModuleSrc(ctx, m.properties.Src) processedVintfFragment := PathForModuleOut(ctx, srcVintfFragment.Base()) @@ -69,8 +70,12 @@ func (m *vintfFragmentModule) GenerateAndroidBuildActions(ctx ModuleContext) { ctx.InstallFile(m.installDirPath, processedVintfFragment.Base(), processedVintfFragment) } +func (m *VintfFragmentModule) OutputFile() Path { + return m.outputFilePath +} + // Make this module visible to AndroidMK so it can be referenced from modules defined from Android.mk files -func (m *vintfFragmentModule) AndroidMkEntries() []AndroidMkEntries { +func (m *VintfFragmentModule) AndroidMkEntries() []AndroidMkEntries { return []AndroidMkEntries{{ Class: "ETC", OutputFile: OptionalPathForPath(m.outputFilePath), @@ -82,3 +87,11 @@ func (m *vintfFragmentModule) AndroidMkEntries() []AndroidMkEntries { }, }} } + +var _ ApexModule = (*VintfFragmentModule)(nil) + +// Implements android.ApexModule +func (m *VintfFragmentModule) ShouldSupportSdkVersion(ctx BaseModuleContext, sdkVersion ApiLevel) error { + // VintfFragmetModule is independent from the SDK version. + return nil +} diff --git a/apex/apex.go b/apex/apex.go index 33538fb13..04816580d 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -1475,6 +1475,12 @@ func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.Platform return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config) } +func apexFileForVintfFragment(ctx android.BaseModuleContext, vintfFragment *android.VintfFragmentModule) apexFile { + dirInApex := filepath.Join("etc", "vintf") + + return newApexFile(ctx, vintfFragment.OutputFile(), vintfFragment.BaseModuleName(), dirInApex, etc, vintfFragment) +} + // javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same // way. type javaModule interface { @@ -2160,7 +2166,13 @@ func (a *apexBundle) depVisitor(vctx *visitorContext, ctx android.ModuleContext, // nothing } else if am.CanHaveApexVariants() && am.IsInstallableToApex() { ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName) + } else if android.IsVintfDepTag(depTag) { + if vf, ok := child.(*android.VintfFragmentModule); ok { + apexFile := apexFileForVintfFragment(ctx, vf) + vctx.filesInfo = append(vctx.filesInfo, apexFile) + } } + return false } diff --git a/apex/apex_test.go b/apex/apex_test.go index f88c09ebd..6c1a2d66b 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -12184,3 +12184,35 @@ func TestFilesystemWithApexDeps(t *testing.T) { fileList := android.ContentFromFileRuleForTests(t, result, partition.Output("fileList")) android.AssertDeepEquals(t, "filesystem with apex", "apex/myapex.apex\n", fileList) } + +func TestVintfFragmentInApex(t *testing.T) { + t.Parallel() + ctx := testApex(t, apex_default_bp+` + apex { + name: "myapex", + manifest: ":myapex.manifest", + androidManifest: ":myapex.androidmanifest", + key: "myapex.key", + binaries: [ "mybin" ], + updatable: false, + } + + cc_binary { + name: "mybin", + srcs: ["mybin.cpp"], + vintf_fragment_modules: ["my_vintf_fragment.xml"], + apex_available: [ "myapex" ], + } + + vintf_fragment { + name: "my_vintf_fragment.xml", + src: "my_vintf_fragment.xml", + } + `) + + generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("generateFsConfig") + cmd := generateFsRule.RuleParams.Command + + // Ensure that vintf fragment file is being installed + ensureContains(t, cmd, "/etc/vintf/my_vintf_fragment.xml ") +} diff --git a/apex/builder.go b/apex/builder.go index b34dc84a6..03a0bb902 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -528,9 +528,10 @@ func markManifestTestOnly(ctx android.ModuleContext, androidManifestFile android }) } -func isVintfFragment(fi apexFile) bool { +func shouldApplyAssembleVintf(fi apexFile) bool { isVintfFragment, _ := path.Match("etc/vintf/*", fi.path()) - return isVintfFragment + _, fromVintfFragmentModule := fi.module.(*android.VintfFragmentModule) + return isVintfFragment && !fromVintfFragmentModule } func runAssembleVintf(ctx android.ModuleContext, vintfFragment android.Path) android.Path { @@ -639,7 +640,7 @@ func (a *apexBundle) buildApex(ctx android.ModuleContext) { copyCommands = append(copyCommands, "ln -sfn "+pathOnDevice+" "+destPath) } else { // Copy the file into APEX - if !a.testApex && isVintfFragment(fi) { + if !a.testApex && shouldApplyAssembleVintf(fi) { // copy the output of assemble_vintf instead of the original vintfFragment := runAssembleVintf(ctx, fi.builtFile) copyCommands = append(copyCommands, "cp -f "+vintfFragment.String()+" "+destPath) |