Add InstallForceOS, fix testcases for host
Robolectric tests compile against device modules but are installed and run as host modules. Allow a module to override its install OS. Test: TestPathForModuleInstall Change-Id: Icf37bb3d4cc1222a9b079602c6a5fdb8b51c86ed
This commit is contained in:
parent
387ad5c576
commit
6e3594003b
|
@ -172,6 +172,7 @@ type ModuleContext interface {
|
||||||
InstallInRecovery() bool
|
InstallInRecovery() bool
|
||||||
InstallInRoot() bool
|
InstallInRoot() bool
|
||||||
InstallBypassMake() bool
|
InstallBypassMake() bool
|
||||||
|
InstallForceOS() *OsType
|
||||||
|
|
||||||
RequiredModuleNames() []string
|
RequiredModuleNames() []string
|
||||||
HostRequiredModuleNames() []string
|
HostRequiredModuleNames() []string
|
||||||
|
@ -213,6 +214,7 @@ type Module interface {
|
||||||
InstallInRecovery() bool
|
InstallInRecovery() bool
|
||||||
InstallInRoot() bool
|
InstallInRoot() bool
|
||||||
InstallBypassMake() bool
|
InstallBypassMake() bool
|
||||||
|
InstallForceOS() *OsType
|
||||||
SkipInstall()
|
SkipInstall()
|
||||||
ExportedToMake() bool
|
ExportedToMake() bool
|
||||||
NoticeFile() OptionalPath
|
NoticeFile() OptionalPath
|
||||||
|
@ -893,6 +895,10 @@ func (m *ModuleBase) InstallBypassMake() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *ModuleBase) InstallForceOS() *OsType {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (m *ModuleBase) Owner() string {
|
func (m *ModuleBase) Owner() string {
|
||||||
return String(m.commonProperties.Owner)
|
return String(m.commonProperties.Owner)
|
||||||
}
|
}
|
||||||
|
@ -1683,6 +1689,10 @@ func (m *moduleContext) InstallBypassMake() bool {
|
||||||
return m.module.InstallBypassMake()
|
return m.module.InstallBypassMake()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *moduleContext) InstallForceOS() *OsType {
|
||||||
|
return m.module.InstallForceOS()
|
||||||
|
}
|
||||||
|
|
||||||
func (m *moduleContext) skipInstall(fullInstallPath InstallPath) bool {
|
func (m *moduleContext) skipInstall(fullInstallPath InstallPath) bool {
|
||||||
if m.module.base().commonProperties.SkipInstall {
|
if m.module.base().commonProperties.SkipInstall {
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -53,6 +53,7 @@ type ModuleInstallPathContext interface {
|
||||||
InstallInRecovery() bool
|
InstallInRecovery() bool
|
||||||
InstallInRoot() bool
|
InstallInRoot() bool
|
||||||
InstallBypassMake() bool
|
InstallBypassMake() bool
|
||||||
|
InstallForceOS() *OsType
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ ModuleInstallPathContext = ModuleContext(nil)
|
var _ ModuleInstallPathContext = ModuleContext(nil)
|
||||||
|
@ -1206,18 +1207,22 @@ func (p InstallPath) ToMakePath() InstallPath {
|
||||||
// module appended with paths...
|
// module appended with paths...
|
||||||
func PathForModuleInstall(ctx ModuleInstallPathContext, pathComponents ...string) InstallPath {
|
func PathForModuleInstall(ctx ModuleInstallPathContext, pathComponents ...string) InstallPath {
|
||||||
var outPaths []string
|
var outPaths []string
|
||||||
if ctx.Device() {
|
os := ctx.Os()
|
||||||
partition := modulePartition(ctx)
|
if forceOS := ctx.InstallForceOS(); forceOS != nil {
|
||||||
|
os = *forceOS
|
||||||
|
}
|
||||||
|
partition := modulePartition(ctx, os)
|
||||||
|
if os.Class == Device {
|
||||||
outPaths = []string{"target", "product", ctx.Config().DeviceName(), partition}
|
outPaths = []string{"target", "product", ctx.Config().DeviceName(), partition}
|
||||||
} else {
|
} else {
|
||||||
switch ctx.Os() {
|
switch os {
|
||||||
case Linux:
|
case Linux:
|
||||||
outPaths = []string{"host", "linux-x86"}
|
outPaths = []string{"host", "linux-x86", partition}
|
||||||
case LinuxBionic:
|
case LinuxBionic:
|
||||||
// TODO: should this be a separate top level, or shared with linux-x86?
|
// TODO: should this be a separate top level, or shared with linux-x86?
|
||||||
outPaths = []string{"host", "linux_bionic-x86"}
|
outPaths = []string{"host", "linux_bionic-x86", partition}
|
||||||
default:
|
default:
|
||||||
outPaths = []string{"host", ctx.Os().String() + "-x86"}
|
outPaths = []string{"host", os.String() + "-x86", partition}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ctx.Debug() {
|
if ctx.Debug() {
|
||||||
|
@ -1253,43 +1258,46 @@ func InstallPathToOnDevicePath(ctx PathContext, path InstallPath) string {
|
||||||
return "/" + rel
|
return "/" + rel
|
||||||
}
|
}
|
||||||
|
|
||||||
func modulePartition(ctx ModuleInstallPathContext) string {
|
func modulePartition(ctx ModuleInstallPathContext, os OsType) string {
|
||||||
var partition string
|
var partition string
|
||||||
if ctx.InstallInData() {
|
if ctx.InstallInTestcases() {
|
||||||
partition = "data"
|
// "testcases" install directory can be used for host or device modules.
|
||||||
} else if ctx.InstallInTestcases() {
|
|
||||||
partition = "testcases"
|
partition = "testcases"
|
||||||
} else if ctx.InstallInRamdisk() {
|
} else if os.Class == Device {
|
||||||
if ctx.DeviceConfig().BoardUsesRecoveryAsBoot() {
|
if ctx.InstallInData() {
|
||||||
partition = "recovery/root/first_stage_ramdisk"
|
partition = "data"
|
||||||
|
} else if ctx.InstallInRamdisk() {
|
||||||
|
if ctx.DeviceConfig().BoardUsesRecoveryAsBoot() {
|
||||||
|
partition = "recovery/root/first_stage_ramdisk"
|
||||||
|
} else {
|
||||||
|
partition = "ramdisk"
|
||||||
|
}
|
||||||
|
if !ctx.InstallInRoot() {
|
||||||
|
partition += "/system"
|
||||||
|
}
|
||||||
|
} else if ctx.InstallInRecovery() {
|
||||||
|
if ctx.InstallInRoot() {
|
||||||
|
partition = "recovery/root"
|
||||||
|
} else {
|
||||||
|
// the layout of recovery partion is the same as that of system partition
|
||||||
|
partition = "recovery/root/system"
|
||||||
|
}
|
||||||
|
} else if ctx.SocSpecific() {
|
||||||
|
partition = ctx.DeviceConfig().VendorPath()
|
||||||
|
} else if ctx.DeviceSpecific() {
|
||||||
|
partition = ctx.DeviceConfig().OdmPath()
|
||||||
|
} else if ctx.ProductSpecific() {
|
||||||
|
partition = ctx.DeviceConfig().ProductPath()
|
||||||
|
} else if ctx.SystemExtSpecific() {
|
||||||
|
partition = ctx.DeviceConfig().SystemExtPath()
|
||||||
|
} else if ctx.InstallInRoot() {
|
||||||
|
partition = "root"
|
||||||
} else {
|
} else {
|
||||||
partition = "ramdisk"
|
partition = "system"
|
||||||
}
|
}
|
||||||
if !ctx.InstallInRoot() {
|
if ctx.InstallInSanitizerDir() {
|
||||||
partition += "/system"
|
partition = "data/asan/" + partition
|
||||||
}
|
}
|
||||||
} else if ctx.InstallInRecovery() {
|
|
||||||
if ctx.InstallInRoot() {
|
|
||||||
partition = "recovery/root"
|
|
||||||
} else {
|
|
||||||
// the layout of recovery partion is the same as that of system partition
|
|
||||||
partition = "recovery/root/system"
|
|
||||||
}
|
|
||||||
} else if ctx.SocSpecific() {
|
|
||||||
partition = ctx.DeviceConfig().VendorPath()
|
|
||||||
} else if ctx.DeviceSpecific() {
|
|
||||||
partition = ctx.DeviceConfig().OdmPath()
|
|
||||||
} else if ctx.ProductSpecific() {
|
|
||||||
partition = ctx.DeviceConfig().ProductPath()
|
|
||||||
} else if ctx.SystemExtSpecific() {
|
|
||||||
partition = ctx.DeviceConfig().SystemExtPath()
|
|
||||||
} else if ctx.InstallInRoot() {
|
|
||||||
partition = "root"
|
|
||||||
} else {
|
|
||||||
partition = "system"
|
|
||||||
}
|
|
||||||
if ctx.InstallInSanitizerDir() {
|
|
||||||
partition = "data/asan/" + partition
|
|
||||||
}
|
}
|
||||||
return partition
|
return partition
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,6 +205,7 @@ type moduleInstallPathContextImpl struct {
|
||||||
inRamdisk bool
|
inRamdisk bool
|
||||||
inRecovery bool
|
inRecovery bool
|
||||||
inRoot bool
|
inRoot bool
|
||||||
|
forceOS *OsType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m moduleInstallPathContextImpl) Config() Config {
|
func (m moduleInstallPathContextImpl) Config() Config {
|
||||||
|
@ -241,6 +242,10 @@ func (m moduleInstallPathContextImpl) InstallBypassMake() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m moduleInstallPathContextImpl) InstallForceOS() *OsType {
|
||||||
|
return m.forceOS
|
||||||
|
}
|
||||||
|
|
||||||
func pathTestConfig(buildDir string) Config {
|
func pathTestConfig(buildDir string) Config {
|
||||||
return TestConfig(buildDir, nil, "", nil)
|
return TestConfig(buildDir, nil, "", nil)
|
||||||
}
|
}
|
||||||
|
@ -598,6 +603,40 @@ func TestPathForModuleInstall(t *testing.T) {
|
||||||
},
|
},
|
||||||
in: []string{"nativetest", "my_test"},
|
in: []string{"nativetest", "my_test"},
|
||||||
out: "target/product/test_device/data/asan/data/nativetest/my_test",
|
out: "target/product/test_device/data/asan/data/nativetest/my_test",
|
||||||
|
}, {
|
||||||
|
name: "device testcases",
|
||||||
|
ctx: &moduleInstallPathContextImpl{
|
||||||
|
baseModuleContext: baseModuleContext{
|
||||||
|
os: deviceTarget.Os,
|
||||||
|
target: deviceTarget,
|
||||||
|
},
|
||||||
|
inTestcases: true,
|
||||||
|
},
|
||||||
|
in: []string{"my_test", "my_test_bin"},
|
||||||
|
out: "target/product/test_device/testcases/my_test/my_test_bin",
|
||||||
|
}, {
|
||||||
|
name: "host testcases",
|
||||||
|
ctx: &moduleInstallPathContextImpl{
|
||||||
|
baseModuleContext: baseModuleContext{
|
||||||
|
os: hostTarget.Os,
|
||||||
|
target: hostTarget,
|
||||||
|
},
|
||||||
|
inTestcases: true,
|
||||||
|
},
|
||||||
|
in: []string{"my_test", "my_test_bin"},
|
||||||
|
out: "host/linux-x86/testcases/my_test/my_test_bin",
|
||||||
|
}, {
|
||||||
|
name: "forced host testcases",
|
||||||
|
ctx: &moduleInstallPathContextImpl{
|
||||||
|
baseModuleContext: baseModuleContext{
|
||||||
|
os: deviceTarget.Os,
|
||||||
|
target: deviceTarget,
|
||||||
|
},
|
||||||
|
inTestcases: true,
|
||||||
|
forceOS: &Linux,
|
||||||
|
},
|
||||||
|
in: []string{"my_test", "my_test_bin"},
|
||||||
|
out: "host/linux-x86/testcases/my_test/my_test_bin",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue