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
This commit is contained in:
Spandan Das
2023-09-28 21:23:30 +00:00
parent c38757d0c0
commit dc7d7f7557

View File

@@ -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 {