bazelbuild / bazelbuild/rules_pkg

Support packaging raw symlinks from declare_symlink

Open
#929 1 comment 3 reactions 0 assignees View on GitHub
feature-request P2
Dominant language
Starlark
Stars
253
Forks
221
Avg merge
10h 33m
Merged PRs (30d)
1

Description

Over in rules_python, declare_symlink() is used to create symlinks for efficiency and correctness reasons. Such artifacts are "raw" symlinks, that is, Bazel will keep them exactly as-is and not try to transform them, as happens when using declare_file().

Unfortunately, pkg_tar gives an error when it sees these artifacts. What happens is it thinks the file is a regular file, so tries to read it. Since its a relative symlink, it either is dangling (in the context of pkg_tar), or will read the actual file (instead of creating a symlink), neither of which is desirable behavior.

Thankfully, starting in Bazel 8, File.is_symlink can be used to detect these artifacts. This allows the manifest that pkg_tar generates, and the build_tar program that uses it, to handle them correctly.

The two basic changes are:
1. When File.is_symlink is true, write a manifest entry with entry_type=raw_symlink (pkg_files.bzl)
2. Modify build_tar.py to handle entry_type=raw_symlink: read os.readlink() from the src file. Then store it as a symlink. This preserves the original symlink.

I prototyped this a bit and it seems to work. I'd reference my branch, but its in a very hacky and broken state right now. The above gets the gist though

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.