2020-11-09 10:38:48 +01:00
|
|
|
// Copyright 2020 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package android
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2020-11-25 04:44:59 +01:00
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
2020-11-09 10:38:48 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Module to be packaged
|
|
|
|
type componentTestModule struct {
|
|
|
|
ModuleBase
|
|
|
|
props struct {
|
|
|
|
Deps []string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-25 03:47:24 +01:00
|
|
|
// dep tag used in this test. All dependencies are considered as installable.
|
|
|
|
type installDepTag struct {
|
|
|
|
blueprint.BaseDependencyTag
|
|
|
|
InstallAlwaysNeededDependencyTag
|
|
|
|
}
|
|
|
|
|
2020-11-09 10:38:48 +01:00
|
|
|
func componentTestModuleFactory() Module {
|
|
|
|
m := &componentTestModule{}
|
|
|
|
m.AddProperties(&m.props)
|
|
|
|
InitAndroidArchModule(m, HostAndDeviceSupported, MultilibBoth)
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *componentTestModule) DepsMutator(ctx BottomUpMutatorContext) {
|
2020-11-25 03:47:24 +01:00
|
|
|
ctx.AddDependency(ctx.Module(), installDepTag{}, m.props.Deps...)
|
2020-11-09 10:38:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *componentTestModule) GenerateAndroidBuildActions(ctx ModuleContext) {
|
|
|
|
builtFile := PathForModuleOut(ctx, m.Name())
|
|
|
|
dir := ctx.Target().Arch.ArchType.Multilib
|
|
|
|
installDir := PathForModuleInstall(ctx, dir)
|
|
|
|
ctx.InstallFile(installDir, m.Name(), builtFile)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Module that itself is a package
|
|
|
|
type packageTestModule struct {
|
|
|
|
ModuleBase
|
|
|
|
PackagingBase
|
2021-03-10 07:40:34 +01:00
|
|
|
properties struct {
|
|
|
|
Install_deps []string `android:`
|
|
|
|
}
|
2020-11-09 10:38:48 +01:00
|
|
|
entries []string
|
|
|
|
}
|
|
|
|
|
2021-02-01 15:24:56 +01:00
|
|
|
func packageMultiTargetTestModuleFactory() Module {
|
2020-11-09 10:38:48 +01:00
|
|
|
module := &packageTestModule{}
|
|
|
|
InitPackageModule(module)
|
|
|
|
InitAndroidMultiTargetsArchModule(module, DeviceSupported, MultilibCommon)
|
2021-03-10 07:40:34 +01:00
|
|
|
module.AddProperties(&module.properties)
|
2020-11-09 10:38:48 +01:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2021-02-01 15:24:56 +01:00
|
|
|
func packageTestModuleFactory() Module {
|
|
|
|
module := &packageTestModule{}
|
|
|
|
InitPackageModule(module)
|
|
|
|
InitAndroidArchModule(module, DeviceSupported, MultilibBoth)
|
2021-03-10 07:40:34 +01:00
|
|
|
module.AddProperties(&module.properties)
|
2021-02-01 15:24:56 +01:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2021-03-10 07:40:34 +01:00
|
|
|
type packagingDepTag struct {
|
|
|
|
blueprint.BaseDependencyTag
|
|
|
|
PackagingItemAlwaysDepTag
|
|
|
|
}
|
|
|
|
|
2020-11-09 10:38:48 +01:00
|
|
|
func (m *packageTestModule) DepsMutator(ctx BottomUpMutatorContext) {
|
2021-03-10 07:40:34 +01:00
|
|
|
m.AddDeps(ctx, packagingDepTag{})
|
|
|
|
ctx.AddDependency(ctx.Module(), installDepTag{}, m.properties.Install_deps...)
|
2020-11-09 10:38:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *packageTestModule) GenerateAndroidBuildActions(ctx ModuleContext) {
|
2021-02-02 11:59:54 +01:00
|
|
|
zipFile := PathForModuleOut(ctx, "myzip.zip")
|
2020-11-09 10:38:48 +01:00
|
|
|
m.entries = m.CopyDepsToZip(ctx, zipFile)
|
|
|
|
}
|
|
|
|
|
2021-02-01 15:24:56 +01:00
|
|
|
func runPackagingTest(t *testing.T, multitarget bool, bp string, expected []string) {
|
2020-11-09 10:38:48 +01:00
|
|
|
t.Helper()
|
|
|
|
|
2021-02-01 15:24:56 +01:00
|
|
|
var archVariant string
|
2021-03-17 01:06:49 +01:00
|
|
|
var moduleFactory ModuleFactory
|
2021-02-01 15:24:56 +01:00
|
|
|
if multitarget {
|
|
|
|
archVariant = "android_common"
|
2021-03-17 01:06:49 +01:00
|
|
|
moduleFactory = packageMultiTargetTestModuleFactory
|
2021-02-01 15:24:56 +01:00
|
|
|
} else {
|
|
|
|
archVariant = "android_arm64_armv8-a"
|
2021-03-17 01:06:49 +01:00
|
|
|
moduleFactory = packageTestModuleFactory
|
2021-02-01 15:24:56 +01:00
|
|
|
}
|
2020-11-09 10:38:48 +01:00
|
|
|
|
2021-03-20 01:36:14 +01:00
|
|
|
result := GroupFixturePreparers(
|
2021-03-17 01:06:49 +01:00
|
|
|
PrepareForTestWithArchMutator,
|
|
|
|
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("component", componentTestModuleFactory)
|
|
|
|
ctx.RegisterModuleType("package_module", moduleFactory)
|
|
|
|
}),
|
|
|
|
FixtureWithRootAndroidBp(bp),
|
2021-03-20 01:36:14 +01:00
|
|
|
).RunTest(t)
|
2020-11-09 10:38:48 +01:00
|
|
|
|
2021-03-17 01:06:49 +01:00
|
|
|
p := result.Module("package", archVariant).(*packageTestModule)
|
2020-11-09 10:38:48 +01:00
|
|
|
actual := p.entries
|
|
|
|
actual = SortedUniqueStrings(actual)
|
|
|
|
expected = SortedUniqueStrings(expected)
|
2021-03-17 01:06:49 +01:00
|
|
|
AssertDeepEquals(t, "package entries", expected, actual)
|
2020-11-09 10:38:48 +01:00
|
|
|
}
|
|
|
|
|
2021-02-01 15:24:56 +01:00
|
|
|
func TestPackagingBaseMultiTarget(t *testing.T) {
|
|
|
|
multiTarget := true
|
|
|
|
runPackagingTest(t, multiTarget,
|
2020-11-09 10:38:48 +01:00
|
|
|
`
|
|
|
|
component {
|
|
|
|
name: "foo",
|
|
|
|
}
|
|
|
|
|
|
|
|
package_module {
|
|
|
|
name: "package",
|
|
|
|
deps: ["foo"],
|
|
|
|
}
|
|
|
|
`, []string{"lib64/foo"})
|
|
|
|
|
2021-02-01 15:24:56 +01:00
|
|
|
runPackagingTest(t, multiTarget,
|
2020-11-09 10:38:48 +01:00
|
|
|
`
|
|
|
|
component {
|
|
|
|
name: "foo",
|
|
|
|
deps: ["bar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
component {
|
|
|
|
name: "bar",
|
|
|
|
}
|
|
|
|
|
|
|
|
package_module {
|
|
|
|
name: "package",
|
|
|
|
deps: ["foo"],
|
|
|
|
}
|
|
|
|
`, []string{"lib64/foo", "lib64/bar"})
|
|
|
|
|
2021-02-01 15:24:56 +01:00
|
|
|
runPackagingTest(t, multiTarget,
|
2020-11-09 10:38:48 +01:00
|
|
|
`
|
|
|
|
component {
|
|
|
|
name: "foo",
|
|
|
|
deps: ["bar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
component {
|
|
|
|
name: "bar",
|
|
|
|
}
|
|
|
|
|
|
|
|
package_module {
|
|
|
|
name: "package",
|
|
|
|
deps: ["foo"],
|
|
|
|
compile_multilib: "both",
|
|
|
|
}
|
|
|
|
`, []string{"lib32/foo", "lib32/bar", "lib64/foo", "lib64/bar"})
|
|
|
|
|
2021-02-01 15:24:56 +01:00
|
|
|
runPackagingTest(t, multiTarget,
|
2020-11-09 10:38:48 +01:00
|
|
|
`
|
|
|
|
component {
|
|
|
|
name: "foo",
|
|
|
|
}
|
|
|
|
|
|
|
|
component {
|
|
|
|
name: "bar",
|
|
|
|
compile_multilib: "32",
|
|
|
|
}
|
|
|
|
|
|
|
|
package_module {
|
|
|
|
name: "package",
|
|
|
|
deps: ["foo"],
|
|
|
|
multilib: {
|
|
|
|
lib32: {
|
|
|
|
deps: ["bar"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
compile_multilib: "both",
|
|
|
|
}
|
|
|
|
`, []string{"lib32/foo", "lib32/bar", "lib64/foo"})
|
|
|
|
|
2021-02-01 15:24:56 +01:00
|
|
|
runPackagingTest(t, multiTarget,
|
2020-11-09 10:38:48 +01:00
|
|
|
`
|
|
|
|
component {
|
|
|
|
name: "foo",
|
|
|
|
}
|
|
|
|
|
|
|
|
component {
|
|
|
|
name: "bar",
|
|
|
|
}
|
|
|
|
|
|
|
|
package_module {
|
|
|
|
name: "package",
|
|
|
|
deps: ["foo"],
|
|
|
|
multilib: {
|
|
|
|
first: {
|
|
|
|
deps: ["bar"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
compile_multilib: "both",
|
|
|
|
}
|
|
|
|
`, []string{"lib32/foo", "lib64/foo", "lib64/bar"})
|
2021-02-01 15:24:56 +01:00
|
|
|
|
|
|
|
runPackagingTest(t, multiTarget,
|
|
|
|
`
|
|
|
|
component {
|
|
|
|
name: "foo",
|
|
|
|
}
|
|
|
|
|
|
|
|
component {
|
|
|
|
name: "bar",
|
|
|
|
}
|
|
|
|
|
|
|
|
component {
|
|
|
|
name: "baz",
|
|
|
|
}
|
|
|
|
|
|
|
|
package_module {
|
|
|
|
name: "package",
|
|
|
|
deps: ["foo"],
|
|
|
|
arch: {
|
|
|
|
arm64: {
|
|
|
|
deps: ["bar"],
|
|
|
|
},
|
|
|
|
x86_64: {
|
|
|
|
deps: ["baz"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
compile_multilib: "both",
|
|
|
|
}
|
|
|
|
`, []string{"lib32/foo", "lib64/foo", "lib64/bar"})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPackagingBaseSingleTarget(t *testing.T) {
|
|
|
|
multiTarget := false
|
|
|
|
runPackagingTest(t, multiTarget,
|
|
|
|
`
|
|
|
|
component {
|
|
|
|
name: "foo",
|
|
|
|
}
|
|
|
|
|
|
|
|
package_module {
|
|
|
|
name: "package",
|
|
|
|
deps: ["foo"],
|
|
|
|
}
|
|
|
|
`, []string{"lib64/foo"})
|
|
|
|
|
|
|
|
runPackagingTest(t, multiTarget,
|
|
|
|
`
|
|
|
|
component {
|
|
|
|
name: "foo",
|
|
|
|
deps: ["bar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
component {
|
|
|
|
name: "bar",
|
|
|
|
}
|
|
|
|
|
|
|
|
package_module {
|
|
|
|
name: "package",
|
|
|
|
deps: ["foo"],
|
|
|
|
}
|
|
|
|
`, []string{"lib64/foo", "lib64/bar"})
|
|
|
|
|
|
|
|
runPackagingTest(t, multiTarget,
|
|
|
|
`
|
|
|
|
component {
|
|
|
|
name: "foo",
|
|
|
|
}
|
|
|
|
|
|
|
|
component {
|
|
|
|
name: "bar",
|
|
|
|
compile_multilib: "32",
|
|
|
|
}
|
|
|
|
|
|
|
|
package_module {
|
|
|
|
name: "package",
|
|
|
|
deps: ["foo"],
|
|
|
|
multilib: {
|
|
|
|
lib32: {
|
|
|
|
deps: ["bar"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`, []string{"lib64/foo"})
|
|
|
|
|
|
|
|
runPackagingTest(t, multiTarget,
|
|
|
|
`
|
|
|
|
component {
|
|
|
|
name: "foo",
|
|
|
|
}
|
|
|
|
|
|
|
|
component {
|
|
|
|
name: "bar",
|
|
|
|
}
|
|
|
|
|
|
|
|
package_module {
|
|
|
|
name: "package",
|
|
|
|
deps: ["foo"],
|
|
|
|
multilib: {
|
|
|
|
lib64: {
|
|
|
|
deps: ["bar"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`, []string{"lib64/foo", "lib64/bar"})
|
|
|
|
|
|
|
|
runPackagingTest(t, multiTarget,
|
|
|
|
`
|
|
|
|
component {
|
|
|
|
name: "foo",
|
|
|
|
}
|
|
|
|
|
|
|
|
component {
|
|
|
|
name: "bar",
|
|
|
|
}
|
|
|
|
|
|
|
|
component {
|
|
|
|
name: "baz",
|
|
|
|
}
|
|
|
|
|
|
|
|
package_module {
|
|
|
|
name: "package",
|
|
|
|
deps: ["foo"],
|
|
|
|
arch: {
|
|
|
|
arm64: {
|
|
|
|
deps: ["bar"],
|
|
|
|
},
|
|
|
|
x86_64: {
|
|
|
|
deps: ["baz"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`, []string{"lib64/foo", "lib64/bar"})
|
2021-03-10 07:40:34 +01:00
|
|
|
|
|
|
|
runPackagingTest(t, multiTarget,
|
|
|
|
`
|
|
|
|
component {
|
|
|
|
name: "foo",
|
|
|
|
}
|
|
|
|
|
|
|
|
component {
|
|
|
|
name: "bar",
|
|
|
|
}
|
|
|
|
|
|
|
|
package_module {
|
|
|
|
name: "package",
|
|
|
|
deps: ["foo"],
|
|
|
|
install_deps: ["bar"],
|
|
|
|
}
|
|
|
|
`, []string{"lib64/foo"})
|
2020-11-09 10:38:48 +01:00
|
|
|
}
|