Merge "Make overrides work in Soong" into main am: b11c99d084 am: c299c20911

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/3241433

Change-Id: Ic9ff8fbf86a0a706038ce7d0c4a9ab9cf5f0dc89
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Jiyong Park
2024-09-04 00:17:23 +00:00
committed by Automerger Merge Worker
5 changed files with 110 additions and 9 deletions

View File

@@ -492,6 +492,10 @@ type commonProperties struct {
// vintf_fragment Modules required from this module. // vintf_fragment Modules required from this module.
Vintf_fragment_modules proptools.Configurable[[]string] `android:"path"` Vintf_fragment_modules proptools.Configurable[[]string] `android:"path"`
// List of module names that are prevented from being installed when this module gets
// installed.
Overrides []string
} }
type distProperties struct { type distProperties struct {

View File

@@ -543,6 +543,7 @@ func (m *moduleContext) setAconfigPaths(paths Paths) {
func (m *moduleContext) packageFile(fullInstallPath InstallPath, srcPath Path, executable bool) PackagingSpec { func (m *moduleContext) packageFile(fullInstallPath InstallPath, srcPath Path, executable bool) PackagingSpec {
licenseFiles := m.Module().EffectiveLicenseFiles() licenseFiles := m.Module().EffectiveLicenseFiles()
overrides := CopyOf(m.Module().base().commonProperties.Overrides)
spec := PackagingSpec{ spec := PackagingSpec{
relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()), relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
srcPath: srcPath, srcPath: srcPath,
@@ -553,6 +554,8 @@ func (m *moduleContext) packageFile(fullInstallPath InstallPath, srcPath Path, e
skipInstall: m.skipInstall(), skipInstall: m.skipInstall(),
aconfigPaths: m.getAconfigPaths(), aconfigPaths: m.getAconfigPaths(),
archType: m.target.Arch.ArchType, archType: m.target.Arch.ArchType,
overrides: &overrides,
owner: m.ModuleName(),
} }
m.packagingSpecs = append(m.packagingSpecs, spec) m.packagingSpecs = append(m.packagingSpecs, spec)
return spec return spec
@@ -670,6 +673,7 @@ func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, src
m.checkbuildFiles = append(m.checkbuildFiles, srcPath) m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
} }
overrides := CopyOf(m.Module().base().commonProperties.Overrides)
m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{ m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()), relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
srcPath: nil, srcPath: nil,
@@ -679,6 +683,8 @@ func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, src
skipInstall: m.skipInstall(), skipInstall: m.skipInstall(),
aconfigPaths: m.getAconfigPaths(), aconfigPaths: m.getAconfigPaths(),
archType: m.target.Arch.ArchType, archType: m.target.Arch.ArchType,
overrides: &overrides,
owner: m.ModuleName(),
}) })
return fullInstallPath return fullInstallPath
@@ -714,6 +720,7 @@ func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name str
m.installFiles = append(m.installFiles, fullInstallPath) m.installFiles = append(m.installFiles, fullInstallPath)
} }
overrides := CopyOf(m.Module().base().commonProperties.Overrides)
m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{ m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()), relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
srcPath: nil, srcPath: nil,
@@ -723,6 +730,8 @@ func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name str
skipInstall: m.skipInstall(), skipInstall: m.skipInstall(),
aconfigPaths: m.getAconfigPaths(), aconfigPaths: m.getAconfigPaths(),
archType: m.target.Arch.ArchType, archType: m.target.Arch.ArchType,
overrides: &overrides,
owner: m.ModuleName(),
}) })
return fullInstallPath return fullInstallPath

View File

@@ -182,6 +182,7 @@ func createCcSdkVariantRules() []Rule {
"packages/modules/SdkExtensions/derive_sdk", "packages/modules/SdkExtensions/derive_sdk",
// These are for apps and shouldn't be used by non-SDK variant modules. // These are for apps and shouldn't be used by non-SDK variant modules.
"prebuilts/ndk", "prebuilts/ndk",
"frameworks/native/libs/binder/ndk",
"tools/test/graphicsbenchmark/apps/sample_app", "tools/test/graphicsbenchmark/apps/sample_app",
"tools/test/graphicsbenchmark/functional_tests/java", "tools/test/graphicsbenchmark/functional_tests/java",
"vendor/xts/gts-tests/hostsidetests/gamedevicecert/apps/javatests", "vendor/xts/gts-tests/hostsidetests/gamedevicecert/apps/javatests",

View File

@@ -56,6 +56,12 @@ type PackagingSpec struct {
// ArchType of the module which produced this packaging spec // ArchType of the module which produced this packaging spec
archType ArchType archType ArchType
// List of module names that this packaging spec overrides
overrides *[]string
// Name of the module where this packaging spec is output of
owner string
} }
func (p *PackagingSpec) Equals(other *PackagingSpec) bool { func (p *PackagingSpec) Equals(other *PackagingSpec) bool {
@@ -325,7 +331,10 @@ func (p *PackagingBase) AddDeps(ctx BottomUpMutatorContext, depTag blueprint.Dep
} }
func (p *PackagingBase) GatherPackagingSpecsWithFilter(ctx ModuleContext, filter func(PackagingSpec) bool) map[string]PackagingSpec { func (p *PackagingBase) GatherPackagingSpecsWithFilter(ctx ModuleContext, filter func(PackagingSpec) bool) map[string]PackagingSpec {
m := make(map[string]PackagingSpec) // all packaging specs gathered from the dep.
var all []PackagingSpec
// list of module names overridden
var overridden []string
var arches []ArchType var arches []ArchType
for _, target := range getSupportedTargets(ctx) { for _, target := range getSupportedTargets(ctx) {
@@ -357,6 +366,24 @@ func (p *PackagingBase) GatherPackagingSpecsWithFilter(ctx ModuleContext, filter
continue continue
} }
} }
all = append(all, ps)
if ps.overrides != nil {
overridden = append(overridden, *ps.overrides...)
}
}
})
// all minus packaging specs that are overridden
var filtered []PackagingSpec
for _, ps := range all {
if ps.owner != "" && InList(ps.owner, overridden) {
continue
}
filtered = append(filtered, ps)
}
m := make(map[string]PackagingSpec)
for _, ps := range filtered {
dstPath := ps.relPathInPackage dstPath := ps.relPathInPackage
if existingPs, ok := m[dstPath]; ok { if existingPs, ok := m[dstPath]; ok {
if !existingPs.Equals(&ps) { if !existingPs.Equals(&ps) {
@@ -364,10 +391,8 @@ func (p *PackagingBase) GatherPackagingSpecsWithFilter(ctx ModuleContext, filter
} }
continue continue
} }
m[dstPath] = ps m[dstPath] = ps
} }
})
return m return m
} }

View File

@@ -28,6 +28,7 @@ type componentTestModule struct {
props struct { props struct {
Deps []string Deps []string
Skip_install *bool Skip_install *bool
Overrides []string
} }
} }
@@ -650,3 +651,64 @@ func TestPrefer32Deps(t *testing.T) {
runPackagingTest(t, config, bp, tc.expected) runPackagingTest(t, config, bp, tc.expected)
} }
} }
func TestOverrides(t *testing.T) {
bpTemplate := `
component {
name: "foo",
deps: ["bar"],
}
component {
name: "bar",
}
component {
name: "bar_override",
overrides: ["bar"],
}
component {
name: "baz",
deps: ["bar_override"],
}
package_module {
name: "package",
deps: %DEPS%,
}
`
testcases := []struct {
deps []string
expected []string
}{
{
deps: []string{"foo"},
expected: []string{"lib64/foo", "lib64/bar"},
},
{
deps: []string{"foo", "bar_override"},
expected: []string{"lib64/foo", "lib64/bar_override"},
},
{
deps: []string{"foo", "bar", "bar_override"},
expected: []string{"lib64/foo", "lib64/bar_override"},
},
{
deps: []string{"bar", "bar_override"},
expected: []string{"lib64/bar_override"},
},
{
deps: []string{"foo", "baz"},
expected: []string{"lib64/foo", "lib64/baz", "lib64/bar_override"},
},
}
for _, tc := range testcases {
config := testConfig{
multiTarget: true,
depsCollectFirstTargetOnly: false,
}
bp := strings.Replace(bpTemplate, "%DEPS%", `["`+strings.Join(tc.deps, `", "`)+`"]`, -1)
runPackagingTest(t, config, bp, tc.expected)
}
}