Merge changes I12e1854c,I08f7dba4
* changes: Add buildDir to WritablePath implementations Add srcDir to SourcePath
This commit is contained in:
commit
85484e344a
|
@ -181,7 +181,7 @@ type WritablePath interface {
|
|||
Path
|
||||
|
||||
// return the path to the build directory.
|
||||
buildDir() string
|
||||
getBuildDir() string
|
||||
|
||||
// the writablePath method doesn't directly do anything,
|
||||
// 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
|
||||
type SourcePath struct {
|
||||
basePath
|
||||
|
||||
// The sources root, i.e. Config.SrcDir()
|
||||
srcDir string
|
||||
}
|
||||
|
||||
var _ Path = SourcePath{}
|
||||
|
@ -981,7 +984,7 @@ func (p SourcePath) withRel(rel string) SourcePath {
|
|||
// code that is embedding ninja variables in paths
|
||||
func safePathForSource(ctx PathContext, pathComponents ...string) (SourcePath, error) {
|
||||
p, err := validateSafePath(pathComponents...)
|
||||
ret := SourcePath{basePath{p, ctx.Config(), ""}}
|
||||
ret := SourcePath{basePath{p, ctx.Config(), ""}, ctx.Config().srcDir}
|
||||
if err != nil {
|
||||
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.
|
||||
func pathForSource(ctx PathContext, pathComponents ...string) (SourcePath, error) {
|
||||
p, err := validatePath(pathComponents...)
|
||||
ret := SourcePath{basePath{p, ctx.Config(), ""}}
|
||||
ret := SourcePath{basePath{p, ctx.Config(), ""}, ctx.Config().srcDir}
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
|
@ -1091,7 +1094,7 @@ func ExistentPathForSource(ctx PathContext, pathComponents ...string) OptionalPa
|
|||
}
|
||||
|
||||
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
|
||||
|
@ -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)
|
||||
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.
|
||||
if pathtools.IsGlob(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 {
|
||||
return OptionalPath{}
|
||||
}
|
||||
relPath := Rel(ctx, p.config.srcDir, paths[0])
|
||||
relPath := Rel(ctx, p.srcDir, paths[0])
|
||||
return OptionalPathForPath(PathForSource(ctx, relPath))
|
||||
}
|
||||
|
||||
// OutputPath is a Path representing an intermediates file path rooted from the build directory
|
||||
type OutputPath struct {
|
||||
basePath
|
||||
|
||||
// The soong build directory, i.e. Config.BuildDir()
|
||||
buildDir string
|
||||
|
||||
fullPath string
|
||||
}
|
||||
|
||||
|
@ -1157,8 +1164,8 @@ func (p OutputPath) WithoutRel() OutputPath {
|
|||
return p
|
||||
}
|
||||
|
||||
func (p OutputPath) buildDir() string {
|
||||
return p.config.buildDir
|
||||
func (p OutputPath) getBuildDir() string {
|
||||
return p.buildDir
|
||||
}
|
||||
|
||||
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)
|
||||
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
|
||||
|
@ -1430,6 +1437,7 @@ func PathForBazelOut(ctx PathContext, paths ...string) BazelOutPath {
|
|||
}
|
||||
|
||||
outputPath := OutputPath{basePath{"", ctx.Config(), ""},
|
||||
ctx.Config().buildDir,
|
||||
ctx.Config().BazelContext.OutputBase()}
|
||||
|
||||
return BazelOutPath{
|
||||
|
@ -1523,6 +1531,9 @@ func PathForModuleRes(ctx ModuleOutPathContext, pathComponents ...string) Module
|
|||
type InstallPath struct {
|
||||
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.
|
||||
// For example, it is host/<os>-<arch> for host modules, and target/product/<device>/<partition> for device modules.
|
||||
partitionDir string
|
||||
|
@ -1531,8 +1542,8 @@ type InstallPath struct {
|
|||
makePath bool
|
||||
}
|
||||
|
||||
func (p InstallPath) buildDir() string {
|
||||
return p.config.buildDir
|
||||
func (p InstallPath) getBuildDir() string {
|
||||
return p.buildDir
|
||||
}
|
||||
|
||||
func (p InstallPath) ReplaceExtension(ctx PathContext, ext string) OutputPath {
|
||||
|
@ -1547,9 +1558,9 @@ func (p InstallPath) writablePath() {}
|
|||
func (p InstallPath) String() string {
|
||||
if p.makePath {
|
||||
// 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 {
|
||||
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.
|
||||
func (p InstallPath) PartitionDir() string {
|
||||
if p.makePath {
|
||||
return filepath.Join(p.config.buildDir, "../", p.partitionDir)
|
||||
return filepath.Join(p.buildDir, "../", p.partitionDir)
|
||||
} 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{
|
||||
basePath: basePath{partionPath, ctx.Config(), ""},
|
||||
buildDir: ctx.Config().buildDir,
|
||||
partitionDir: partionPath,
|
||||
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 {
|
||||
base := InstallPath{
|
||||
basePath: basePath{prefix, ctx.Config(), ""},
|
||||
buildDir: ctx.Config().buildDir,
|
||||
partitionDir: prefix,
|
||||
makePath: false,
|
||||
}
|
||||
|
@ -1797,8 +1810,9 @@ type PhonyPath struct {
|
|||
|
||||
func (p PhonyPath) writablePath() {}
|
||||
|
||||
func (p PhonyPath) buildDir() string {
|
||||
return p.config.buildDir
|
||||
func (p PhonyPath) getBuildDir() string {
|
||||
// A phone path cannot contain any / so cannot be relative to the build directory.
|
||||
return ""
|
||||
}
|
||||
|
||||
func (p PhonyPath) ReplaceExtension(ctx PathContext, ext string) OutputPath {
|
||||
|
|
|
@ -909,7 +909,7 @@ func NormalizePathForTesting(path Path) string {
|
|||
}
|
||||
p := path.String()
|
||||
if w, ok := path.(WritablePath); ok {
|
||||
rel, err := filepath.Rel(w.buildDir(), p)
|
||||
rel, err := filepath.Rel(w.getBuildDir(), p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -944,7 +944,7 @@ func PathRelativeToTop(path Path) string {
|
|||
}
|
||||
p := path.String()
|
||||
if w, ok := path.(WritablePath); ok {
|
||||
buildDir := w.buildDir()
|
||||
buildDir := w.getBuildDir()
|
||||
return StringPathRelativeToTop(buildDir, p)
|
||||
}
|
||||
return p
|
||||
|
|
Loading…
Reference in New Issue