Allow tests to bypass PathForSource existence checks
Forcing every test to specify every file it wants to pass to
PathForSource or PathForModuleSrc is painful to maintain and
doesn't add any value. Allow tests to reference paths through
PathForSource and PathForModuleSrc without specifying them in
the mock FS.
Bug: 153485543
Test: all soong tests
Change-Id: Ia8a8fd965a338d0645b3721314bf91f50146ad21
Merged-In: Ia8a8fd965a338d0645b3721314bf91f50146ad21
(cherry picked from commit 5e6a79798280bec894ffe8ab5b7e9f30e2eca0eb)
diff --git a/android/config.go b/android/config.go
index bf52c45..3c92bb0 100644
--- a/android/config.go
+++ b/android/config.go
@@ -111,6 +111,10 @@
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 @@
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,
diff --git a/android/paths.go b/android/paths.go
index 1d8d92a..2a0a70a 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -396,7 +396,7 @@
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)
}
@@ -767,7 +767,7 @@
}
} 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