ctx.actions.symlink doesn't make relative symlink, contrary to docs
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
ctx.actions.symlink always makes absolute symlinks when target_path is used, regardless of whether target_path is absolute.
### Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
**WORKSAPCE.bazel**
```py
```
**BUILD.bazel**
```py
load(":rules.bzl", "example")
example(
name = "example",
)
```
**rules.bzl**
```py
def _example_impl(ctx):
example1 = ctx.actions.declare_symlink("example1")
ctx.actions.symlink(output = example1, target_path = "../..")
example2 = ctx.actions.declare_symlink("example2")
ctx.actions.run(executable = "ln", arguments = ["-s", "../..", example2.path], outputs = [example2])
return DefaultInfo(
files = depset([example1, example2])
)
example = rule(
implementation = _example_impl
)
```
```
$ bazel build --experimental_allow_unresolved_symlinks :example
$ ls -l bazel-bin/
lrwxrwxrwx 1 paul paul 68 Nov 4 01:06 example1 -> /home/paul/.cache/bazel/_bazel_paul/fc54cd89f1e9b3d4a2b86f2842cad4ca
lrwxrwxrwx 1 paul paul 5 Nov 4 01:06 example2 -> ../..
```
I expected both symlinks to be ''../.." but only the latter (using executable ln) is.
Documentation: https://docs.bazel.build/versions/main/skylark/lib/actions.html#symlink
> (Experimental) **The exact path that the output symlink will point to. No normalization or other processing is applied.** Access to this feature requires setting --experimental_allow_unresolved_symlinks.
### What operating system are you running Bazel on?
Ubuntu 18.04
### What's the output of `bazel info release`?
4.2.1
Contributor guide
Research direction
Start with the ctx.actions.symlink documentation and reproduce the behavior using the rules.bzl and BUILD.bazel examples. Run bazel build --experimental_allow_unresolved_symlinks :example and compare example1 with the ln-created example2; done means target_path="../.." produces the documented relative symlink.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100