summaryrefslogtreecommitdiff
path: root/finder
diff options
context:
space:
mode:
author Lukacs T. Berki <lberki@google.com> 2022-05-02 10:13:19 +0200
committer Lukacs T. Berki <lberki@google.com> 2022-05-04 09:12:01 +0200
commite3487c88482c96b31c8bd5ff4f14d3bc0e70b784 (patch)
tree29dae5eb3240ff3ca8e40629f2edfc6f664dc918 /finder
parenta704eb14690da4533c970e807a4224268cb499a0 (diff)
Add a test for correctness of C++ compilation.
This required the following: - Adding Platform_base_sdk_extension_version to default soong.variables - Teaching the symlink tree creation code to understand symlinks - Making finder.go follow symlinks when requested Adding yet another knob is unfortunate, but I can't allow that unconditionally because the Android code base contains a number of symlinks giving rise to infinite directory trees because they point back to their parent and this seemed preferable to adding complicated logic like "follow symlink but if only its fully resolved version does not point under the source tree". I could be convinced about the latter, though. Test: Presubmits. Change-Id: I453f6b7e5334771f5832c700db00f9d24ed1d82f
Diffstat (limited to 'finder')
-rw-r--r--finder/finder.go15
-rw-r--r--finder/finder_test.go2
2 files changed, 14 insertions, 3 deletions
diff --git a/finder/finder.go b/finder/finder.go
index b4834b16b..c5196c8de 100644
--- a/finder/finder.go
+++ b/finder/finder.go
@@ -94,6 +94,10 @@ type CacheParams struct {
// RootDirs are the root directories used to initiate the search
RootDirs []string
+ // Whether symlinks are followed. If set, symlinks back to their own parent
+ // directory don't work.
+ FollowSymlinks bool
+
// ExcludeDirs are directory names that if encountered are removed from the search
ExcludeDirs []string
@@ -1415,9 +1419,14 @@ func (f *Finder) listDirSync(dir *pathMap) {
// If stat fails this is probably a broken or dangling symlink, treat it as a file.
subfiles = append(subfiles, child.Name())
} else if childStat.IsDir() {
- // Skip symlink dirs.
- // We don't have to support symlink dirs because
- // that would cause duplicates.
+ // Skip symlink dirs if not requested otherwise. Android has a number
+ // of symlinks creating infinite source trees which would otherwise get
+ // us in an infinite loop.
+ // TODO(b/197349722): Revisit this once symlink loops are banned in the
+ // source tree.
+ if f.cacheMetadata.Config.FollowSymlinks {
+ subdirs = append(subdirs, child.Name())
+ }
} else {
// We do have to support symlink files because the link name might be
// different than the target name
diff --git a/finder/finder_test.go b/finder/finder_test.go
index 788dbdd35..8f73719a6 100644
--- a/finder/finder_test.go
+++ b/finder/finder_test.go
@@ -90,6 +90,7 @@ func runSimpleTest(t *testing.T, existentPaths []string, expectedMatches []strin
CacheParams{
"/cwd",
[]string{root},
+ false,
nil,
nil,
[]string{"findme.txt", "skipme.txt"},
@@ -121,6 +122,7 @@ func runTestWithSuffixes(t *testing.T, existentPaths []string, expectedMatches [
CacheParams{
"/cwd",
[]string{root},
+ false,
nil,
nil,
[]string{"findme.txt", "skipme.txt"},