bazelbuild / bazelbuild/rules_pkg

Auto-detecting executable bit in `pkg_tar` can't be used in conjunction with `pkg_files`

Open
#762 2 comments 0 reactions 0 assignees View on GitHub
feature-request P3
Dominant language
Starlark
Stars
253
Forks
221
Avg merge
10h 33m
Merged PRs (30d)
1

Description

The `build_tar.py` has logic to auto-detect the executable bit of the source files and also apply that in the final tar file:
```
# If mode is unspecified, derive the mode from the file's mode.
if mode is None:
f_mode = 0o755 if os.access(content_path, os.X_OK) else 0o644
else:
f_mode = mode
```
https://github.com/bazelbuild/rules_pkg/blob/main/pkg/private/tar/build_tar.py#L283

This logic cannot be reached however when using `pkg_tar` in conjunction with `pkg_files`, as the `_pkg_files_impl` doesn't allow `None` to pass through, it overwrites it with a `0644` default.

```
# The least surprising default mode is that of a normal file (0644)
out_attributes.setdefault("mode", "0644")
```
https://github.com/bazelbuild/rules_pkg/blob/main/pkg/mappings.bzl#L256

Is that default there on purpose? There is another default for `mode` in `pkg_tar` of `0555`. So the default in `pkg_files` make the default of `pkg_tar` not usable.

The initial problem could be solved by simply removing that default in `_pkg_files_impl`, then this code would be using the auto-detection of the executable bit:
```
pkg_files(
name ="files",
srcs = [src],
)

pkg_tar(
name = package,
srcs = ["files"],
mode = None,
)
```

For the case where neither `pkg_files` nor `pkg_tar` specify a mode, the files are created with the default mode of tar (555).

Would that make sense? I didn't look at the other packaging rules yet how they would be impacted.

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.