diff options
-rw-r--r-- | android/module.go | 58 | ||||
-rw-r--r-- | android/paths.go | 129 | ||||
-rw-r--r-- | android/paths_test.go | 39 | ||||
-rw-r--r-- | cc/test.go | 2 |
4 files changed, 154 insertions, 74 deletions
diff --git a/android/module.go b/android/module.go index 847b02cd7..1026bdfeb 100644 --- a/android/module.go +++ b/android/module.go @@ -172,6 +172,7 @@ type ModuleContext interface { InstallInRecovery() bool InstallInRoot() bool InstallBypassMake() bool + InstallForceOS() *OsType RequiredModuleNames() []string HostRequiredModuleNames() []string @@ -214,6 +215,7 @@ type Module interface { InstallInRecovery() bool InstallInRoot() bool InstallBypassMake() bool + InstallForceOS() *OsType SkipInstall() ExportedToMake() bool InitRc() Paths @@ -242,6 +244,8 @@ type Module interface { RequiredModuleNames() []string HostRequiredModuleNames() []string TargetRequiredModuleNames() []string + + filesToInstall() InstallPaths } // Qualified id for a module @@ -643,7 +647,7 @@ type ModuleBase struct { primaryVisibilityProperty visibilityProperty noAddressSanitizer bool - installFiles Paths + installFiles InstallPaths checkbuildFiles Paths noticeFiles Paths @@ -849,22 +853,20 @@ func (m *ModuleBase) ExportedToMake() bool { return m.commonProperties.NamespaceExportedToMake } -func (m *ModuleBase) computeInstallDeps( - ctx blueprint.ModuleContext) Paths { +func (m *ModuleBase) computeInstallDeps(ctx blueprint.ModuleContext) InstallPaths { - result := Paths{} + var result InstallPaths // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation - ctx.VisitDepsDepthFirstIf(isFileInstaller, - func(m blueprint.Module) { - fileInstaller := m.(fileInstaller) - files := fileInstaller.filesToInstall() - result = append(result, files...) - }) + ctx.VisitDepsDepthFirst(func(m blueprint.Module) { + if a, ok := m.(Module); ok { + result = append(result, a.filesToInstall()...) + } + }) return result } -func (m *ModuleBase) filesToInstall() Paths { +func (m *ModuleBase) filesToInstall() InstallPaths { return m.installFiles } @@ -900,6 +902,10 @@ func (m *ModuleBase) InstallBypassMake() bool { return false } +func (m *ModuleBase) InstallForceOS() *OsType { + return nil +} + func (m *ModuleBase) Owner() string { return String(m.commonProperties.Owner) } @@ -948,8 +954,8 @@ func (m *ModuleBase) VintfFragments() Paths { } func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) { - allInstalledFiles := Paths{} - allCheckbuildFiles := Paths{} + var allInstalledFiles InstallPaths + var allCheckbuildFiles Paths ctx.VisitAllModuleVariants(func(module Module) { a := module.base() allInstalledFiles = append(allInstalledFiles, a.installFiles...) @@ -968,7 +974,7 @@ func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) { ctx.Build(pctx, BuildParams{ Rule: blueprint.Phony, Output: name, - Implicits: allInstalledFiles, + Implicits: allInstalledFiles.Paths(), Default: !ctx.Config().EmbeddedInMake(), }) deps = append(deps, name) @@ -1309,8 +1315,8 @@ func (b *baseModuleContext) GetDirectDepWithTag(name string, tag blueprint.Depen type moduleContext struct { bp blueprint.ModuleContext baseModuleContext - installDeps Paths - installFiles Paths + installDeps InstallPaths + installFiles InstallPaths checkbuildFiles Paths module Module @@ -1716,6 +1722,10 @@ func (m *moduleContext) InstallBypassMake() bool { return m.module.InstallBypassMake() } +func (m *moduleContext) InstallForceOS() *OsType { + return m.module.InstallForceOS() +} + func (m *moduleContext) skipInstall(fullInstallPath InstallPath) bool { if m.module.base().commonProperties.SkipInstall { return true @@ -1759,7 +1769,7 @@ func (m *moduleContext) installFile(installPath InstallPath, name string, srcPat if !m.skipInstall(fullInstallPath) { - deps = append(deps, m.installDeps...) + deps = append(deps, m.installDeps.Paths()...) var implicitDeps, orderOnlyDeps Paths @@ -1840,20 +1850,6 @@ func (m *moduleContext) CheckbuildFile(srcPath Path) { m.checkbuildFiles = append(m.checkbuildFiles, srcPath) } -type fileInstaller interface { - filesToInstall() Paths -} - -func isFileInstaller(m blueprint.Module) bool { - _, ok := m.(fileInstaller) - return ok -} - -func isAndroidModule(m blueprint.Module) bool { - _, ok := m.(Module) - return ok -} - func findStringInSlice(str string, slice []string) int { for i, s := range slice { if s == str { diff --git a/android/paths.go b/android/paths.go index 66725c623..8b373da06 100644 --- a/android/paths.go +++ b/android/paths.go @@ -53,6 +53,7 @@ type ModuleInstallPathContext interface { InstallInRecovery() bool InstallInRoot() bool InstallBypassMake() bool + InstallForceOS() *OsType } var _ ModuleInstallPathContext = ModuleContext(nil) @@ -1205,22 +1206,40 @@ func (p InstallPath) ToMakePath() InstallPath { // PathForModuleInstall returns a Path representing the install path for the // module appended with paths... func PathForModuleInstall(ctx ModuleInstallPathContext, pathComponents ...string) InstallPath { + os := ctx.Os() + if forceOS := ctx.InstallForceOS(); forceOS != nil { + os = *forceOS + } + partition := modulePartition(ctx, os) + + ret := pathForInstall(ctx, os, partition, ctx.Debug(), pathComponents...) + + if ctx.InstallBypassMake() && ctx.Config().EmbeddedInMake() { + ret = ret.ToMakePath() + } + + return ret +} + +func pathForInstall(ctx PathContext, os OsType, partition string, debug bool, + pathComponents ...string) InstallPath { + var outPaths []string - if ctx.Device() { - partition := modulePartition(ctx) + + if os.Class == Device { outPaths = []string{"target", "product", ctx.Config().DeviceName(), partition} } else { - switch ctx.Os() { + switch os { case Linux: - outPaths = []string{"host", "linux-x86"} + outPaths = []string{"host", "linux-x86", partition} case LinuxBionic: // 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: - outPaths = []string{"host", ctx.Os().String() + "-x86"} + outPaths = []string{"host", os.String() + "-x86", partition} } } - if ctx.Debug() { + if debug { outPaths = append([]string{"debug"}, outPaths...) } outPaths = append(outPaths, pathComponents...) @@ -1231,9 +1250,6 @@ func PathForModuleInstall(ctx ModuleInstallPathContext, pathComponents ...string } ret := InstallPath{basePath{path, ctx.Config(), ""}, ""} - if ctx.InstallBypassMake() && ctx.Config().EmbeddedInMake() { - ret = ret.ToMakePath() - } return ret } @@ -1253,47 +1269,76 @@ func InstallPathToOnDevicePath(ctx PathContext, path InstallPath) string { return "/" + rel } -func modulePartition(ctx ModuleInstallPathContext) string { +func modulePartition(ctx ModuleInstallPathContext, os OsType) string { var partition string - if ctx.InstallInData() { - partition = "data" - } else if ctx.InstallInTestcases() { + if ctx.InstallInTestcases() { + // "testcases" install directory can be used for host or device modules. partition = "testcases" - } else if ctx.InstallInRamdisk() { - if ctx.DeviceConfig().BoardUsesRecoveryAsBoot() { - partition = "recovery/root/first_stage_ramdisk" + } else if os.Class == Device { + if ctx.InstallInData() { + 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 { - partition = "ramdisk" + partition = "system" } - if !ctx.InstallInRoot() { - partition += "/system" + if ctx.InstallInSanitizerDir() { + 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 } +type InstallPaths []InstallPath + +// Paths returns the InstallPaths as a Paths +func (p InstallPaths) Paths() Paths { + if p == nil { + return nil + } + ret := make(Paths, len(p)) + for i, path := range p { + ret[i] = path + } + return ret +} + +// Strings returns the string forms of the install paths. +func (p InstallPaths) Strings() []string { + if p == nil { + return nil + } + ret := make([]string, len(p)) + for i, path := range p { + ret[i] = path.String() + } + return ret +} + // validateSafePath validates a path that we trust (may contain ninja variables). // Ensures that each path component does not attempt to leave its component. func validateSafePath(pathComponents ...string) (string, error) { diff --git a/android/paths_test.go b/android/paths_test.go index 7a3202613..f1908ac1d 100644 --- a/android/paths_test.go +++ b/android/paths_test.go @@ -205,6 +205,7 @@ type moduleInstallPathContextImpl struct { inRamdisk bool inRecovery bool inRoot bool + forceOS *OsType } func (m moduleInstallPathContextImpl) Config() Config { @@ -241,6 +242,10 @@ func (m moduleInstallPathContextImpl) InstallBypassMake() bool { return false } +func (m moduleInstallPathContextImpl) InstallForceOS() *OsType { + return m.forceOS +} + func pathTestConfig(buildDir string) Config { return TestConfig(buildDir, nil, "", nil) } @@ -598,6 +603,40 @@ func TestPathForModuleInstall(t *testing.T) { }, in: []string{"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", }, } diff --git a/cc/test.go b/cc/test.go index 05e6fe5e5..1085d3a69 100644 --- a/cc/test.go +++ b/cc/test.go @@ -49,7 +49,7 @@ type TestBinaryProperties struct { // list of files or filegroup modules that provide data that should be installed alongside // the test - Data []string `android:"path"` + Data []string `android:"path,arch_variant"` // list of compatibility suites (for example "cts", "vts") that the module should be // installed into. |