From 580efc8716db460159deb1ff423b81fd4101a8bb Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 24 Mar 2021 09:04:03 +0000 Subject: [PATCH] Add srcDir to SourcePath Bug: 183650682 Test: m droid Change-Id: I08f7dba449538d289a6c4d6b5325c1a833cff834 --- android/paths.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/android/paths.go b/android/paths.go index 0ed988a0f..3a3643c98 100644 --- a/android/paths.go +++ b/android/paths.go @@ -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)) }