Cannot symlink source directories with declare_directory
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the bug:
Source directories cannot be symlinked by using an output declared using `ctx.actions.declare_directory`, whereas generated directories can. This means this cannot be used as a type of hint for whether to create a file or directory symlink on Windows (see https://github.com/bazelbuild/bazel/issues/26701).
This could be the same root cause as https://github.com/bazelbuild/bazel/issues/12954, which is another case where source directories are not considered to be directories.
### Which category does this issue belong to?
Core
### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
I’ve created a reproducer here: [bazel-symlink-source-dir.tar.gz](https://github.com/user-attachments/files/21601992/bazel-symlink-source-dir.tar.gz)
Building `:generated_directory_symlink` works fine, but the similar `:source_directory_symlink` does not, giving the following error:
```
Error in symlink: symlink() with "target_file" file param requires that "output" be declared as a file (did you mean to use declare_file() instead of declare_directory()?)
```
### Which operating system are you running Bazel on?
Ubuntu
### What is the output of `bazel info release`?
release 8.3.1
### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.
N/a
### What's the output of `git remote get-url origin; git rev-parse HEAD` ?
```text
N/a
```
### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.
N/a
### Have you found anything relevant by searching the web?
No
### Any other information, logs, or outputs that you want to share?
No
Contributor guide
Research direction
Start with the attached bazel-symlink-source-dir.tar.gz reproducer and compare the working generated_directory_symlink target with source_directory_symlink using ctx.actions.declare_directory. Trace the handling of source directories and the symlink() target_file validation. Done means the source-directory case builds without the declare_file error and preserves the intended file-versus-directory symlink distinction on Windows.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100