Merge changes I12e1854c,I08f7dba4 am: 85484e344a

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1652614

Change-Id: I95aba831638f6b195b0e1006f721a4054bebfde5
This commit is contained in:
Paul Duffin
2021-03-25 15:09:36 +00:00
committed by Automerger Merge Worker
2 changed files with 33 additions and 19 deletions

View File

@@ -181,7 +181,7 @@ type WritablePath interface {
Path Path
// return the path to the build directory. // return the path to the build directory.
buildDir() string getBuildDir() string
// the writablePath method doesn't directly do anything, // the writablePath method doesn't directly do anything,
// but it allows a struct to distinguish between whether or not it implements the WritablePath interface // but it allows a struct to distinguish between whether or not it implements the WritablePath interface
@@ -968,6 +968,9 @@ func (p basePath) withRel(rel string) basePath {
// SourcePath is a Path representing a file path rooted from SrcDir // SourcePath is a Path representing a file path rooted from SrcDir
type SourcePath struct { type SourcePath struct {
basePath basePath
// The sources root, i.e. Config.SrcDir()
srcDir string
} }
var _ Path = SourcePath{} var _ Path = SourcePath{}
@@ -981,7 +984,7 @@ func (p SourcePath) withRel(rel string) SourcePath {
// code that is embedding ninja variables in paths // code that is embedding ninja variables in paths
func safePathForSource(ctx PathContext, pathComponents ...string) (SourcePath, error) { func safePathForSource(ctx PathContext, pathComponents ...string) (SourcePath, error) {
p, err := validateSafePath(pathComponents...) p, err := validateSafePath(pathComponents...)
ret := SourcePath{basePath{p, ctx.Config(), ""}} ret := SourcePath{basePath{p, ctx.Config(), ""}, ctx.Config().srcDir}
if err != nil { if err != nil {
return ret, err return ret, err
} }
@@ -997,7 +1000,7 @@ func safePathForSource(ctx PathContext, pathComponents ...string) (SourcePath, e
// pathForSource creates a SourcePath from pathComponents, but does not check that it exists. // pathForSource creates a SourcePath from pathComponents, but does not check that it exists.
func pathForSource(ctx PathContext, pathComponents ...string) (SourcePath, error) { func pathForSource(ctx PathContext, pathComponents ...string) (SourcePath, error) {
p, err := validatePath(pathComponents...) p, err := validatePath(pathComponents...)
ret := SourcePath{basePath{p, ctx.Config(), ""}} ret := SourcePath{basePath{p, ctx.Config(), ""}, ctx.Config().srcDir}
if err != nil { if err != nil {
return ret, err return ret, err
} }
@@ -1091,7 +1094,7 @@ func ExistentPathForSource(ctx PathContext, pathComponents ...string) OptionalPa
} }
func (p SourcePath) String() string { func (p SourcePath) String() string {
return filepath.Join(p.config.srcDir, p.path) return filepath.Join(p.srcDir, p.path)
} }
// Join creates a new SourcePath with paths... joined with the current path. The // Join creates a new SourcePath with paths... joined with the current path. The
@@ -1123,7 +1126,7 @@ func (p SourcePath) OverlayPath(ctx ModuleMissingDepsPathContext, path Path) Opt
ReportPathErrorf(ctx, "Cannot find relative path for %s(%s)", reflect.TypeOf(path).Name(), path) ReportPathErrorf(ctx, "Cannot find relative path for %s(%s)", reflect.TypeOf(path).Name(), path)
return OptionalPath{} return OptionalPath{}
} }
dir := filepath.Join(p.config.srcDir, p.path, relDir) dir := filepath.Join(p.srcDir, p.path, relDir)
// Use Glob so that we are run again if the directory is added. // Use Glob so that we are run again if the directory is added.
if pathtools.IsGlob(dir) { if pathtools.IsGlob(dir) {
ReportPathErrorf(ctx, "Path may not contain a glob: %s", dir) ReportPathErrorf(ctx, "Path may not contain a glob: %s", dir)
@@ -1136,13 +1139,17 @@ func (p SourcePath) OverlayPath(ctx ModuleMissingDepsPathContext, path Path) Opt
if len(paths) == 0 { if len(paths) == 0 {
return OptionalPath{} return OptionalPath{}
} }
relPath := Rel(ctx, p.config.srcDir, paths[0]) relPath := Rel(ctx, p.srcDir, paths[0])
return OptionalPathForPath(PathForSource(ctx, relPath)) return OptionalPathForPath(PathForSource(ctx, relPath))
} }
// OutputPath is a Path representing an intermediates file path rooted from the build directory // OutputPath is a Path representing an intermediates file path rooted from the build directory
type OutputPath struct { type OutputPath struct {
basePath basePath
// The soong build directory, i.e. Config.BuildDir()
buildDir string
fullPath string fullPath string
} }
@@ -1157,8 +1164,8 @@ func (p OutputPath) WithoutRel() OutputPath {
return p return p
} }
func (p OutputPath) buildDir() string { func (p OutputPath) getBuildDir() string {
return p.config.buildDir return p.buildDir
} }
func (p OutputPath) objPathWithExt(ctx ModuleOutPathContext, subdir, ext string) ModuleObjPath { func (p OutputPath) objPathWithExt(ctx ModuleOutPathContext, subdir, ext string) ModuleObjPath {
@@ -1195,7 +1202,7 @@ func PathForOutput(ctx PathContext, pathComponents ...string) OutputPath {
} }
fullPath := filepath.Join(ctx.Config().buildDir, path) fullPath := filepath.Join(ctx.Config().buildDir, path)
path = fullPath[len(fullPath)-len(path):] path = fullPath[len(fullPath)-len(path):]
return OutputPath{basePath{path, ctx.Config(), ""}, fullPath} return OutputPath{basePath{path, ctx.Config(), ""}, ctx.Config().buildDir, fullPath}
} }
// PathsForOutput returns Paths rooted from buildDir // PathsForOutput returns Paths rooted from buildDir
@@ -1430,6 +1437,7 @@ func PathForBazelOut(ctx PathContext, paths ...string) BazelOutPath {
} }
outputPath := OutputPath{basePath{"", ctx.Config(), ""}, outputPath := OutputPath{basePath{"", ctx.Config(), ""},
ctx.Config().buildDir,
ctx.Config().BazelContext.OutputBase()} ctx.Config().BazelContext.OutputBase()}
return BazelOutPath{ return BazelOutPath{
@@ -1523,6 +1531,9 @@ func PathForModuleRes(ctx ModuleOutPathContext, pathComponents ...string) Module
type InstallPath struct { type InstallPath struct {
basePath basePath
// The soong build directory, i.e. Config.BuildDir()
buildDir string
// partitionDir is the part of the InstallPath that is automatically determined according to the context. // 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. // For example, it is host/<os>-<arch> for host modules, and target/product/<device>/<partition> for device modules.
partitionDir string partitionDir string
@@ -1531,8 +1542,8 @@ type InstallPath struct {
makePath bool makePath bool
} }
func (p InstallPath) buildDir() string { func (p InstallPath) getBuildDir() string {
return p.config.buildDir return p.buildDir
} }
func (p InstallPath) ReplaceExtension(ctx PathContext, ext string) OutputPath { func (p InstallPath) ReplaceExtension(ctx PathContext, ext string) OutputPath {
@@ -1547,9 +1558,9 @@ func (p InstallPath) writablePath() {}
func (p InstallPath) String() string { func (p InstallPath) String() string {
if p.makePath { if p.makePath {
// Make path starts with out/ instead of out/soong. // Make path starts with out/ instead of out/soong.
return filepath.Join(p.config.buildDir, "../", p.path) return filepath.Join(p.buildDir, "../", p.path)
} else { } else {
return filepath.Join(p.config.buildDir, p.path) return filepath.Join(p.buildDir, p.path)
} }
} }
@@ -1558,9 +1569,9 @@ func (p InstallPath) String() string {
// The ./soong is dropped if the install path is for Make. // The ./soong is dropped if the install path is for Make.
func (p InstallPath) PartitionDir() string { func (p InstallPath) PartitionDir() string {
if p.makePath { if p.makePath {
return filepath.Join(p.config.buildDir, "../", p.partitionDir) return filepath.Join(p.buildDir, "../", p.partitionDir)
} else { } else {
return filepath.Join(p.config.buildDir, p.partitionDir) return filepath.Join(p.buildDir, p.partitionDir)
} }
} }
@@ -1644,6 +1655,7 @@ func pathForInstall(ctx PathContext, os OsType, arch ArchType, partition string,
base := InstallPath{ base := InstallPath{
basePath: basePath{partionPath, ctx.Config(), ""}, basePath: basePath{partionPath, ctx.Config(), ""},
buildDir: ctx.Config().buildDir,
partitionDir: partionPath, partitionDir: partionPath,
makePath: false, makePath: false,
} }
@@ -1654,6 +1666,7 @@ func pathForInstall(ctx PathContext, os OsType, arch ArchType, partition string,
func pathForNdkOrSdkInstall(ctx PathContext, prefix string, paths []string) InstallPath { func pathForNdkOrSdkInstall(ctx PathContext, prefix string, paths []string) InstallPath {
base := InstallPath{ base := InstallPath{
basePath: basePath{prefix, ctx.Config(), ""}, basePath: basePath{prefix, ctx.Config(), ""},
buildDir: ctx.Config().buildDir,
partitionDir: prefix, partitionDir: prefix,
makePath: false, makePath: false,
} }
@@ -1797,8 +1810,9 @@ type PhonyPath struct {
func (p PhonyPath) writablePath() {} func (p PhonyPath) writablePath() {}
func (p PhonyPath) buildDir() string { func (p PhonyPath) getBuildDir() string {
return p.config.buildDir // A phone path cannot contain any / so cannot be relative to the build directory.
return ""
} }
func (p PhonyPath) ReplaceExtension(ctx PathContext, ext string) OutputPath { func (p PhonyPath) ReplaceExtension(ctx PathContext, ext string) OutputPath {

View File

@@ -909,7 +909,7 @@ func NormalizePathForTesting(path Path) string {
} }
p := path.String() p := path.String()
if w, ok := path.(WritablePath); ok { if w, ok := path.(WritablePath); ok {
rel, err := filepath.Rel(w.buildDir(), p) rel, err := filepath.Rel(w.getBuildDir(), p)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@@ -944,7 +944,7 @@ func PathRelativeToTop(path Path) string {
} }
p := path.String() p := path.String()
if w, ok := path.(WritablePath); ok { if w, ok := path.(WritablePath); ok {
buildDir := w.buildDir() buildDir := w.getBuildDir()
return StringPathRelativeToTop(buildDir, p) return StringPathRelativeToTop(buildDir, p)
} }
return p return p