Merge "InstallPath keeps its partition dir"

This commit is contained in:
Treehugger Robot
2020-10-27 01:33:12 +00:00
committed by Gerrit Code Review
2 changed files with 164 additions and 74 deletions

View File

@@ -1237,7 +1237,12 @@ func PathForModuleRes(ctx ModuleContext, pathComponents ...string) ModuleResPath
type InstallPath struct {
basePath
baseDir string // "../" for Make paths to convert "out/soong" to "out", "" for Soong paths
// partitionDir is the part of the InstallPath that is automatically determined according to the context.
// For example, it is host/<os>-<arch> for host modules, and target/product/<device>/<partition> for device modules.
partitionDir string
// makePath indicates whether this path is for Soong (false) or Make (true).
makePath bool
}
func (p InstallPath) buildDir() string {
@@ -1250,7 +1255,23 @@ var _ WritablePath = InstallPath{}
func (p InstallPath) writablePath() {}
func (p InstallPath) String() string {
return filepath.Join(p.config.buildDir, p.baseDir, p.path)
if p.makePath {
// Make path starts with out/ instead of out/soong.
return filepath.Join(p.config.buildDir, "../", p.path)
} else {
return filepath.Join(p.config.buildDir, p.path)
}
}
// PartitionDir returns the path to the partition where the install path is rooted at. It is
// out/soong/target/product/<device>/<partition> for device modules, and out/soong/host/<os>-<arch> for host modules.
// The ./soong is dropped if the install path is for Make.
func (p InstallPath) PartitionDir() string {
if p.makePath {
return filepath.Join(p.config.buildDir, "../", p.partitionDir)
} else {
return filepath.Join(p.config.buildDir, p.partitionDir)
}
}
// Join creates a new InstallPath with paths... joined with the current path. The
@@ -1271,7 +1292,7 @@ func (p InstallPath) withRel(rel string) InstallPath {
// ToMakePath returns a new InstallPath that points to Make's install directory instead of Soong's,
// i.e. out/ instead of out/soong/.
func (p InstallPath) ToMakePath() InstallPath {
p.baseDir = "../"
p.makePath = true
return p
}
@@ -1301,10 +1322,10 @@ func PathForModuleInstall(ctx ModuleInstallPathContext, pathComponents ...string
func pathForInstall(ctx PathContext, os OsType, arch ArchType, partition string, debug bool,
pathComponents ...string) InstallPath {
var outPaths []string
var partionPaths []string
if os.Class == Device {
outPaths = []string{"target", "product", ctx.Config().DeviceName(), partition}
partionPaths = []string{"target", "product", ctx.Config().DeviceName(), partition}
} else {
osName := os.String()
if os == Linux {
@@ -1320,30 +1341,33 @@ func pathForInstall(ctx PathContext, os OsType, arch ArchType, partition string,
if os.Class == Host && (arch == X86_64 || arch == Common) {
archName = "x86"
}
outPaths = []string{"host", osName + "-" + archName, partition}
partionPaths = []string{"host", osName + "-" + archName, partition}
}
if debug {
outPaths = append([]string{"debug"}, outPaths...)
partionPaths = append([]string{"debug"}, partionPaths...)
}
outPaths = append(outPaths, pathComponents...)
path, err := validatePath(outPaths...)
partionPath, err := validatePath(partionPaths...)
if err != nil {
reportPathError(ctx, err)
}
ret := InstallPath{basePath{path, ctx.Config(), ""}, ""}
base := InstallPath{
basePath: basePath{partionPath, ctx.Config(), ""},
partitionDir: partionPath,
makePath: false,
}
return ret
return base.Join(ctx, pathComponents...)
}
func pathForNdkOrSdkInstall(ctx PathContext, prefix string, paths []string) InstallPath {
paths = append([]string{prefix}, paths...)
path, err := validatePath(paths...)
if err != nil {
reportPathError(ctx, err)
base := InstallPath{
basePath: basePath{prefix, ctx.Config(), ""},
partitionDir: prefix,
makePath: false,
}
return InstallPath{basePath{path, ctx.Config(), ""}, ""}
return base.Join(ctx, paths...)
}
func PathForNdkInstall(ctx PathContext, paths ...string) InstallPath {