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
diff --git a/bp2build/symlink_forest.go b/bp2build/symlink_forest.go
index 15a6335..7d48191 100644
--- a/bp2build/symlink_forest.go
+++ b/bp2build/symlink_forest.go
@@ -90,6 +90,20 @@
 	}
 }
 
+func isDir(path string, fi os.FileInfo) bool {
+	if (fi.Mode() & os.ModeSymlink) != os.ModeSymlink {
+		return fi.IsDir()
+	}
+
+	fi2, err := os.Stat(path)
+	if err != nil {
+		fmt.Fprintf(os.Stderr, "Cannot stat '%s': %s\n", path, err)
+		os.Exit(1)
+	}
+
+	return fi2.IsDir()
+}
+
 // Recursively plants a symlink forest at forestDir. The symlink tree will
 // contain every file in buildFilesDir and srcDir excluding the files in
 // exclude. Collects every directory encountered during the traversal of srcDir
@@ -145,8 +159,18 @@
 			continue
 		}
 
+		sDir := false
+		bDir := false
+		if sExists {
+			sDir = isDir(shared.JoinPath(topdir, srcChild), srcChildEntry)
+		}
+
+		if bExists {
+			bDir = isDir(shared.JoinPath(topdir, buildFilesChild), buildFilesChildEntry)
+		}
+
 		if !sExists {
-			if buildFilesChildEntry.IsDir() && excludeChild != nil {
+			if bDir && excludeChild != nil {
 				// Not in the source tree, but we have to exclude something from under
 				// this subtree, so descend
 				plantSymlinkForestRecursive(topdir, forestChild, buildFilesChild, srcChild, excludeChild, acc, okay)
@@ -155,7 +179,7 @@
 				symlinkIntoForest(topdir, forestChild, buildFilesChild)
 			}
 		} else if !bExists {
-			if srcChildEntry.IsDir() && excludeChild != nil {
+			if sDir && excludeChild != nil {
 				// Not in the build file tree, but we have to exclude something from
 				// under this subtree, so descend
 				plantSymlinkForestRecursive(topdir, forestChild, buildFilesChild, srcChild, excludeChild, acc, okay)
@@ -163,10 +187,10 @@
 				// Not in the build file tree, symlink source tree, carry on
 				symlinkIntoForest(topdir, forestChild, srcChild)
 			}
-		} else if srcChildEntry.IsDir() && buildFilesChildEntry.IsDir() {
+		} else if sDir && bDir {
 			// Both are directories. Descend.
 			plantSymlinkForestRecursive(topdir, forestChild, buildFilesChild, srcChild, excludeChild, acc, okay)
-		} else if !srcChildEntry.IsDir() && !buildFilesChildEntry.IsDir() {
+		} else if !sDir && !bDir {
 			// Neither is a directory. Prioritize BUILD files generated by bp2build
 			// over any BUILD file imported into external/.
 			fmt.Fprintf(os.Stderr, "Both '%s' and '%s' exist, symlinking the former to '%s'\n",