Merge "Fix PackagingBase.CopyDepsToZip"

This commit is contained in:
Treehugger Robot 2021-03-23 04:21:38 +00:00 committed by Gerrit Code Review
commit 9b6108f8de
3 changed files with 54 additions and 9 deletions

View File

@ -59,7 +59,8 @@ type PackageModule interface {
packagingBase() *PackagingBase packagingBase() *PackagingBase
// AddDeps adds dependencies to the `deps` modules. This should be called in DepsMutator. // AddDeps adds dependencies to the `deps` modules. This should be called in DepsMutator.
// When adding the dependencies, depTag is used as the tag. // When adding the dependencies, depTag is used as the tag. If `deps` modules are meant to
// be copied to a zip in CopyDepsToZip, `depTag` should implement PackagingItem marker interface.
AddDeps(ctx BottomUpMutatorContext, depTag blueprint.DependencyTag) AddDeps(ctx BottomUpMutatorContext, depTag blueprint.DependencyTag)
// CopyDepsToZip zips the built artifacts of the dependencies into the given zip file and // CopyDepsToZip zips the built artifacts of the dependencies into the given zip file and
@ -167,6 +168,24 @@ func (p *PackagingBase) getSupportedTargets(ctx BaseModuleContext) []Target {
return ret return ret
} }
// PackagingItem is a marker interface for dependency tags.
// Direct dependencies with a tag implementing PackagingItem are packaged in CopyDepsToZip().
type PackagingItem interface {
// IsPackagingItem returns true if the dep is to be packaged
IsPackagingItem() bool
}
// DepTag provides default implementation of PackagingItem interface.
// PackagingBase-derived modules can define their own dependency tag by embedding this, which
// can be passed to AddDeps() or AddDependencies().
type PackagingItemAlwaysDepTag struct {
}
// IsPackagingItem returns true if the dep is to be packaged
func (PackagingItemAlwaysDepTag) IsPackagingItem() bool {
return true
}
// See PackageModule.AddDeps // See PackageModule.AddDeps
func (p *PackagingBase) AddDeps(ctx BottomUpMutatorContext, depTag blueprint.DependencyTag) { func (p *PackagingBase) AddDeps(ctx BottomUpMutatorContext, depTag blueprint.DependencyTag) {
for _, t := range p.getSupportedTargets(ctx) { for _, t := range p.getSupportedTargets(ctx) {
@ -182,16 +201,15 @@ func (p *PackagingBase) AddDeps(ctx BottomUpMutatorContext, depTag blueprint.Dep
// See PackageModule.CopyDepsToZip // See PackageModule.CopyDepsToZip
func (p *PackagingBase) CopyDepsToZip(ctx ModuleContext, zipOut WritablePath) (entries []string) { func (p *PackagingBase) CopyDepsToZip(ctx ModuleContext, zipOut WritablePath) (entries []string) {
m := make(map[string]PackagingSpec) m := make(map[string]PackagingSpec)
ctx.WalkDeps(func(child Module, parent Module) bool { ctx.VisitDirectDeps(func(child Module) {
if !IsInstallDepNeeded(ctx.OtherModuleDependencyTag(child)) { if pi, ok := ctx.OtherModuleDependencyTag(child).(PackagingItem); !ok || !pi.IsPackagingItem() {
return false return
} }
for _, ps := range child.PackagingSpecs() { for _, ps := range child.TransitivePackagingSpecs() {
if _, ok := m[ps.relPathInPackage]; !ok { if _, ok := m[ps.relPathInPackage]; !ok {
m[ps.relPathInPackage] = ps m[ps.relPathInPackage] = ps
} }
} }
return true
}) })
builder := NewRuleBuilder(pctx, ctx) builder := NewRuleBuilder(pctx, ctx)

View File

@ -56,7 +56,9 @@ func (m *componentTestModule) GenerateAndroidBuildActions(ctx ModuleContext) {
type packageTestModule struct { type packageTestModule struct {
ModuleBase ModuleBase
PackagingBase PackagingBase
properties struct {
Install_deps []string `android:`
}
entries []string entries []string
} }
@ -64,6 +66,7 @@ func packageMultiTargetTestModuleFactory() Module {
module := &packageTestModule{} module := &packageTestModule{}
InitPackageModule(module) InitPackageModule(module)
InitAndroidMultiTargetsArchModule(module, DeviceSupported, MultilibCommon) InitAndroidMultiTargetsArchModule(module, DeviceSupported, MultilibCommon)
module.AddProperties(&module.properties)
return module return module
} }
@ -71,11 +74,18 @@ func packageTestModuleFactory() Module {
module := &packageTestModule{} module := &packageTestModule{}
InitPackageModule(module) InitPackageModule(module)
InitAndroidArchModule(module, DeviceSupported, MultilibBoth) InitAndroidArchModule(module, DeviceSupported, MultilibBoth)
module.AddProperties(&module.properties)
return module return module
} }
type packagingDepTag struct {
blueprint.BaseDependencyTag
PackagingItemAlwaysDepTag
}
func (m *packageTestModule) DepsMutator(ctx BottomUpMutatorContext) { func (m *packageTestModule) DepsMutator(ctx BottomUpMutatorContext) {
m.AddDeps(ctx, installDepTag{}) m.AddDeps(ctx, packagingDepTag{})
ctx.AddDependency(ctx.Module(), installDepTag{}, m.properties.Install_deps...)
} }
func (m *packageTestModule) GenerateAndroidBuildActions(ctx ModuleContext) { func (m *packageTestModule) GenerateAndroidBuildActions(ctx ModuleContext) {
@ -337,4 +347,21 @@ func TestPackagingBaseSingleTarget(t *testing.T) {
}, },
} }
`, []string{"lib64/foo", "lib64/bar"}) `, []string{"lib64/foo", "lib64/bar"})
runPackagingTest(t, multiTarget,
`
component {
name: "foo",
}
component {
name: "bar",
}
package_module {
name: "package",
deps: ["foo"],
install_deps: ["bar"],
}
`, []string{"lib64/foo"})
} }

View File

@ -91,7 +91,7 @@ func filesystemFactory() android.Module {
var dependencyTag = struct { var dependencyTag = struct {
blueprint.BaseDependencyTag blueprint.BaseDependencyTag
android.InstallAlwaysNeededDependencyTag android.PackagingItemAlwaysDepTag
}{} }{}
func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) { func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) {