Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9961d223 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Support override_android_(app|apex) in deps of android_filesystem" into main

parents 76d9446e c1ded7e7
Loading
Loading
Loading
Loading
+20 −6
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import (
	"github.com/google/blueprint/depset"
	"path"
	"path/filepath"
	"slices"
	"strings"

	"github.com/google/blueprint"
@@ -562,9 +563,22 @@ func (m *moduleContext) setAconfigPaths(paths Paths) {
	m.aconfigFilePaths = paths
}

func (m *moduleContext) getOwnerAndOverrides() (string, []string) {
	owner := m.ModuleName()
	overrides := slices.Clone(m.Module().base().commonProperties.Overrides)
	if b, ok := m.Module().(OverridableModule); ok {
		if b.GetOverriddenBy() != "" {
			// overriding variant of base module
			overrides = append(overrides, m.ModuleName()) // com.android.foo
			owner = m.Module().Name()                     // com.company.android.foo
		}
	}
	return owner, overrides
}

func (m *moduleContext) packageFile(fullInstallPath InstallPath, srcPath Path, executable bool) PackagingSpec {
	licenseFiles := m.Module().EffectiveLicenseFiles()
	overrides := CopyOf(m.Module().base().commonProperties.Overrides)
	owner, overrides := m.getOwnerAndOverrides()
	spec := PackagingSpec{
		relPathInPackage:      Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
		srcPath:               srcPath,
@@ -576,7 +590,7 @@ func (m *moduleContext) packageFile(fullInstallPath InstallPath, srcPath Path, e
		aconfigPaths:          m.getAconfigPaths(),
		archType:              m.target.Arch.ArchType,
		overrides:             &overrides,
		owner:                 m.ModuleName(),
		owner:                 owner,
	}
	m.packagingSpecs = append(m.packagingSpecs, spec)
	return spec
@@ -695,7 +709,7 @@ func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, src
		m.installFiles = append(m.installFiles, fullInstallPath)
	}

	overrides := CopyOf(m.Module().base().commonProperties.Overrides)
	owner, overrides := m.getOwnerAndOverrides()
	m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
		relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
		srcPath:          nil,
@@ -706,7 +720,7 @@ func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, src
		aconfigPaths:     m.getAconfigPaths(),
		archType:         m.target.Arch.ArchType,
		overrides:        &overrides,
		owner:            m.ModuleName(),
		owner:            owner,
	})

	return fullInstallPath
@@ -742,7 +756,7 @@ func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name str
		m.installFiles = append(m.installFiles, fullInstallPath)
	}

	overrides := CopyOf(m.Module().base().commonProperties.Overrides)
	owner, overrides := m.getOwnerAndOverrides()
	m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
		relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
		srcPath:          nil,
@@ -753,7 +767,7 @@ func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name str
		aconfigPaths:     m.getAconfigPaths(),
		archType:         m.target.Arch.ArchType,
		overrides:        &overrides,
		owner:            m.ModuleName(),
		owner:            owner,
	})

	return fullInstallPath
+24 −0
Original line number Diff line number Diff line
@@ -691,3 +691,27 @@ cc_library {
	android.AssertStringDoesContain(t, "Could not find linker.config.json file in cmd", linkerConfigCmd, "conv_linker_config proto --force -s linker.config.json")
	android.AssertStringDoesContain(t, "Could not find stub in `provideLibs`", linkerConfigCmd, "--key provideLibs --value libfoo_has_stubs.so")
}

// override_android_* modules implicitly override their base module.
// If both of these are listed in `deps`, the base module should not be installed.
func TestOverrideModulesInDeps(t *testing.T) {
	result := fixture.RunTestWithBp(t, `
		android_filesystem {
			name: "myfilesystem",
			deps: ["myapp", "myoverrideapp"],
		}

		android_app {
			name: "myapp",
			platform_apis: true,
		}
		override_android_app {
			name: "myoverrideapp",
			base: "myapp",
		}
	`)

	partition := result.ModuleForTests("myfilesystem", "android_common")
	fileList := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("fileList"))
	android.AssertStringEquals(t, "filesystem with override app", "app/myoverrideapp/myoverrideapp.apk\n", fileList)
}