|
@@ -90,6 +90,20 @@ func symlinkIntoForest(topdir, dst, src string) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+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 @@ func plantSymlinkForestRecursive(topdir string, forestDir string, buildFilesDir
|
|
|
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 @@ func plantSymlinkForestRecursive(topdir string, forestDir string, buildFilesDir
|
|
|
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 @@ func plantSymlinkForestRecursive(topdir string, forestDir string, buildFilesDir
|
|
|
// 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",
|