Add srcDir to SourcePath

Bug: 183650682
Test: m droid
Change-Id: I08f7dba449538d289a6c4d6b5325c1a833cff834
This commit is contained in:
Paul Duffin 2021-03-24 09:04:03 +00:00
parent 2b1d2b6e4d
commit 580efc8716

View file

@ -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,7 +1139,7 @@ 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))
}