Execution root symlink forest includes all files in a package instead of only ones needed
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the bug:
When running a build, the symlink forest will include all files from a package beyond files actually needed, used, or referenced by a build.
This leads to various quality-of-life, and reproducibility issues.
An example of the output base from the open source `rules_xcodeproj` looks like this when a target in the root package is built:

### Which category does this issue belong to?
_No response_
### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
- Clone [rules_xcodeproj](https://github.com/MobileNativeFoundation/rules_xcodeproj/)
- `bazel build tools:xcodeproj`
- `cd` into `bazel-output-base/execroot/_main/`
- Notice the execroot has symlinked two packages used in that build
- `cd` back to the workspace root
- `bazel build buildifier.check`
- Notice the execroot has symlnked _all_ files in the root, including BUILD files and `.git` directories
### Which operating system are you running Bazel on?
macOS 14.0
### What is the output of `bazel info release`?
release 6.4.0rc1
### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.
_No response_
### What's the output of `git remote get-url origin; git rev-parse master; git rev-parse HEAD` ?
_No response_
### Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.
No
### Have you found anything relevant by searching the web?
_No response_
### Any other information, logs, or outputs that you want to share?
This has existed for a while as a nuisance (if you traverse `bazel-out`), it almost always tricks tools into thinking it's a Git directory, but became a more acute problem in the iOS community with Xcode 15 as the IDE performance is extremely degraded trying to parse what Git views as an extremely large Git diff in the output base.
[bazelbuild.slack.com discussion](https://bazelbuild.slack.com/archives/C0429BN0F8V/p1695156641392379)
Contributor guide
Assessment
This issue has not been assessed yet.