From dc7d7f755707f063de7bc789bface069bbc1fa56 Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Thu, 28 Sep 2023 21:23:30 +0000 Subject: [PATCH] Handle symlinks in isPackageBoundary isPackageBoundary looks at ShouldKeepExistingFile before checking if that directory contains a BUILD file or not. ShouldKeepExistingFile should be complemented with a isSymlink check. This is necessary because we copy all symlinks to the synthetic workspace, and the resolved symlink might point to a directory containing a BUILD file. This additional clause is redundant if the directory has been allowlisted for keepExistingBuildFile (e.g. build/bazel, recursive) Test: b build //bionic/libc:versioner-dependencies (top of stack) Change-Id: I5b23262f89ea34a78de4ccade6d27e4c5dd95c2e --- android/bazel_paths.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/android/bazel_paths.go b/android/bazel_paths.go index d8effaa12..dd59c894e 100644 --- a/android/bazel_paths.go +++ b/android/bazel_paths.go @@ -16,6 +16,7 @@ package android import ( "fmt" + "os" "path/filepath" "strings" @@ -228,10 +229,18 @@ func BazelLabelForSrcPatternExcludes(ctx BazelConversionPathContext, dir, patter // 2. An Android.bp doesn't exist, but a checked-in BUILD/BUILD.bazel file exists, and that file // is allowlisted by the bp2build configuration to be merged into the symlink forest workspace. func isPackageBoundary(config Config, prefix string, components []string, componentIndex int) bool { + isSymlink := func(c Config, path string) bool { + f, err := c.fs.Lstat(path) + if err != nil { + // The file does not exist + return false + } + return f.Mode()&os.ModeSymlink == os.ModeSymlink + } prefix = filepath.Join(prefix, filepath.Join(components[:componentIndex+1]...)) if exists, _, _ := config.fs.Exists(filepath.Join(prefix, "Android.bp")); exists { return true - } else if config.Bp2buildPackageConfig.ShouldKeepExistingBuildFileForDir(prefix) { + } else if config.Bp2buildPackageConfig.ShouldKeepExistingBuildFileForDir(prefix) || isSymlink(config, prefix) { if exists, _, _ := config.fs.Exists(filepath.Join(prefix, "BUILD")); exists { return true } else if exists, _, _ := config.fs.Exists(filepath.Join(prefix, "BUILD.bazel")); exists {