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

Commit c1ded7e7 authored by Spandan Das's avatar Spandan Das
Browse files

Support override_android_(app|apex) in deps of android_filesystem

These modules implicitly override their base module. e.g. if
com.android.foo and com.company.android.foo are listed in deps, only the
latter should be installed.

Override modules are implemented as an "override" variant of the base
module, and all the build actions are generated there. To not install
the overridden app/apex, the following properties are updated in the
_overriding_ PackagingSpec variant of the base apex
1. overrides: base apex (e.g. com.android.foo)
2. owner: overriding apex (e.g. com.company.android.foo)

Test: go test ./filesystem
Change-Id: I59f17134dc6ed99a252977c3615b1be5d6d746ba
parent f69bffbc
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)
}