bazelbuild / bazelbuild/bazel

Should Bazel invoke patch(1) with -E to remove empty files?

Open
#6,976 5 comments 0 reactions 1 assignee Assigned to @meteorcloudy View on GitHub
not stale P3 team-ExternalDeps type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the problem / feature request:

BSD-based systems ship with a copy of patch(1) that has, for historically reasons, diverged from the copy of patch(1) present on GNU-like systems. A subtle difference can be found in the man pages when it comes to the description of `-E`.

GNU:

> Remove output files that are empty after the patches have been applied. Normally this option is unnecessary, since patch can examine the time stamps on the header to determine whether a file should exist after patching. However, if the input is not a context diff or if patch is conforming to POSIX, patch does not remove empty patched files unless this option is given. When patch removes a file, it also attempts to remove any empty ancestor directories.

BSD:

> Causes patch to remove output files that are empty after the patches have been applied. This option is useful when applying patches that create or remove files.

BSD patch misses the logic for automatically detecting that files ought to be deleted, meaning empty files are left behind. This is causing issues in practice, for example when applying this patch to googleapis:

https://github.com/bazelbuild/rules_go/blob/master/third_party/go_googleapis-fix.patch

### Feature requests: what underlying problem are you trying to solve with this feature?

Either one of the following:

- Include our own copy of `patch(1)` that is guaranteed to work consistently across platforms,
- Maybe include `-E` by default and explicitly ask users to set a custom `patch_args` in case they want empty files to remian,
- Document that GNU patch must be installed and alter Bazel to use `/usr/local/bin/patch` on BSD-based systems,
- Simply patch up googleapis to use `-E` there.

### Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Build [Buildbarn](https://github.com/EdSchouten/bazel-buildbarn) on FreeBSD:

```
ERROR: /usr/home/ed/.cache/bazel/_bazel_ed/f3da7d6de993d06f59f4905f27de160a/external/go_googleapis/google/api/BUILD.bazel:15:12: Label '@go_googleapis//google/api:experimental/authorization_config.proto' crosses boundary of subpackage '@go_googleapis//google/api/experimental' (perhaps you meant to put the colon here: '@go_googleapis//google/api/experimental:authorization_config.proto'?)
ERROR: /usr/home/ed/.cache/bazel/_bazel_ed/f3da7d6de993d06f59f4905f27de160a/external/go_googleapis/google/api/BUILD.bazel:15:12: Label '@go_googleapis//google/api:experimental/experimental.proto' crosses boundary of subpackage '@go_googleapis//google/api/experimental' (perhaps you meant to put the colon here: '@go_googleapis//google/api/experimental:experimental.proto'?)
ERROR: /usr/home/ed/.cache/bazel/_bazel_ed/f3da7d6de993d06f59f4905f27de160a/external/go_googleapis/google/api/BUILD.bazel:3:1: Target '@go_googleapis//google/api:annotations.proto' contains an error and its package is in error and referenced by '@go_googleapis//google/api:annotations_proto'
ERROR: /usr/home/ed/.cache/bazel/_bazel_ed/f3da7d6de993d06f59f4905f27de160a/external/go_googleapis/google/api/BUILD.bazel:3:1: Target '@go_googleapis//google/api:http.proto' contains an error and its package is in error and referenced by '@go_googleapis//google/api:annotations_proto'
ERROR: /usr/home/ed/.cache/bazel/_bazel_ed/f3da7d6de993d06f59f4905f27de160a/external/com_github_bazelbuild_remote_apis/build/bazel/remote/execution/v2/BUILD:27:1: Target '@go_googleapis//google/api:annotations_proto' contains an error and its package is in error and referenced by '@com_github_bazelbuild_remote_apis//build/bazel/remote/execution/v2:remoteexecution_proto'
ERROR: /usr/home/ed/.cache/bazel/_bazel_ed/f3da7d6de993d06f59f4905f27de160a/external/com_github_bazelbuild_remote_apis/build/bazel/remote/execution/v2/BUILD:40:1: Target '@go_googleapis//google/api:annotations_go_proto' contains an error and its package is in error and referenced by '@com_github_bazelbuild_remote_apis//build/bazel/remote/execution/v2:remoteexecution_go_proto'
```

### What operating system are you running Bazel on?

FreeBSD 11.2.

### What's the output of `bazel info release`?

release 0.20.0

### Have you found anything relevant by searching the web?

No.

### Any other information, logs, or outputs that you want to share?

None.

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.