bazel-contrib / bazel-contrib/bazel-lib

[Bug]: copy_to_directory doesn't support "nested" symlinks

Open
#403 0 comments 2 reactions 0 assignees View on GitHub
bug help wanted need: funding
Dominant language
Starlark
Stars
182
Forks
134
Avg merge
1d 46m
Merged PRs (30d)
1

Description

### What happened?

I'm getting the following error when trying to copy a file, `$(bazel info output_base)/external/local_jdk/lib/libatk-wrapper.so`:

```sh
(21:50:15) ERROR: /workspace/thecube/local/BUILD.bazel:30:12: Copying files to directory thecube/local/local failed: (Exit 1): copy_to_directory failed: error executing command (from target //thecube/local:local)
(cd /root/.cache/bazel/_bazel_root/eab0d61a99b6696edb3d2aff87b585e8/execroot/umani && \
exec env - \
external/copy_to_directory_linux_arm64/copy_to_directory bazel-out/aarch64-fastbuild/bin/thecube/local/local_config.json)
2023/04/05 21:50:15 lstat external/local_jdk/lib/libatk-wrapper.so failed: lstat aarch64-linux-gnu/jni/libatk-wrapper.so: no such file or directory
```

The file appears in `local_config.json`:

```json
{
"hardlink": false,
"package": "",
"path": "external/local_jdk/lib/libatk-wrapper.so",
"root_path": "",
"short_path": "../local_jdk/lib/libatk-wrapper.so",
"workspace": "local_jdk",
"workspace_path": "lib/libatk-wrapper.so"
},
```

`$(bazel info output_base)/external/local_jdk/lib/libatk-wrapper.so` is a symlink:

```
# readlink $(bazel info output_base)/external/local_jdk/lib/libatk-wrapper.so
../../../aarch64-linux-gnu/jni/libatk-wrapper.so
```

`copy_to_directory` is apparently resolving this relative to `$(bazel info output_base)`. However, the issue is that `$(bazel info output_base)/external/local_jdk/lib` is itself a symlink:

```
# readlink $(bazel info output_base)/external/local_jdk/lib
/usr/lib/jvm/java-17-openjdk-arm64/lib
```

So, the correct resolution should be `$(bazel info output_base)/external/local_jdk/lib/libatk-wrapper.so -> /usr/lib/aarch64-linux-gnu/jni/libatk-wrapper.so`.

### Version

Development (host) and target OS/architectures:

Output of `bazel --version`: bazel 6.1.1

Version of the Aspect rules, or other relevant rules from your
`WORKSPACE` or `MODULE.bazel` file: 1.29.2

Language(s) and/or frameworks involved: TypeScript, Java

### How to reproduce

_No response_

### Any other information?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at the copy_to_directory entry point and inspect how it handles the path from local_config.json when both the file and its parent directory are symlinks. Use the reported local_jdk/lib/libatk-wrapper.so path as the case to validate; done means nested symlinks resolve to the actual target without the lstat failure.

Written by the indexing model from the issue text.

Assessment

Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.