Allow tests to bypass PathForSource existence checks am: 5e6a797982

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

Change-Id: Iba9e38624aef891770a7e64f10ca691462c498b8
This commit is contained in:
Colin Cross 2020-06-11 18:41:55 +00:00 committed by Automerger Merge Worker
commit 439675bf9d
2 changed files with 10 additions and 2 deletions

View File

@ -111,6 +111,10 @@ type config struct {
fs pathtools.FileSystem
mockBpList string
// If testAllowNonExistentPaths is true then PathForSource and PathForModuleSrc won't error
// in tests when a path doesn't exist.
testAllowNonExistentPaths bool
OncePer
}
@ -230,6 +234,10 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string
buildDir: buildDir,
captureBuild: true,
env: envCopy,
// Set testAllowNonExistentPaths so that test contexts don't need to specify every path
// passed to PathForSource or PathForModuleSrc.
testAllowNonExistentPaths: true,
}
config.deviceConfig = &deviceConfig{
config: config,

View File

@ -405,7 +405,7 @@ func expandOneSrcPath(ctx ModuleContext, s string, expandedExcludes []string) (P
p := pathForModuleSrc(ctx, s)
if exists, _, err := ctx.Config().fs.Exists(p.String()); err != nil {
reportPathErrorf(ctx, "%s: %s", p, err.Error())
} else if !exists {
} else if !exists && !ctx.Config().testAllowNonExistentPaths {
reportPathErrorf(ctx, "module source path %q does not exist", p)
}
@ -798,7 +798,7 @@ func PathForSource(ctx PathContext, pathComponents ...string) SourcePath {
}
} else if exists, _, err := ctx.Config().fs.Exists(path.String()); err != nil {
reportPathErrorf(ctx, "%s: %s", path, err.Error())
} else if !exists {
} else if !exists && !ctx.Config().testAllowNonExistentPaths {
reportPathErrorf(ctx, "source path %q does not exist", path)
}
return path