bazelbuild / bazelbuild/bazel

commit e9a4e93ed71 changed the meaning of the patches parameter to patch() in tools/build_defs/repo/utils.bzl

Open
#16,190 4 comments 0 reactions 1 assignee Claimed by @meteorcloudy View on GitHub
P2 team-ExternalDeps type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

### Description of the bug:

Prior to commit e9a4e93ed71, patch() in tools/build_defs/repo/utils.bzl processed its patches parameter as follows:
```
if patches == None and hasattr(ctx.attr, "patches"):
patches = ctx.attr.patches
if patches == None:
patches = []
```
This idiom is consistent with how patch() processes patch_cmds and patch_cmds_win, and means that if a custom repository rule has supplied patches or patch_cmds or patch_cmds_win explicitly, then patch() will not look at the attributes of the repository rule.

commit e9a4e93ed71 altered this logic to
```
if patches == None:
patches = []
if hasattr(ctx.attr, "patches") and ctx.attr.patches:
patches += ctx.attr.patches
```
With this new logic, patch() will now process the _sum_ of any explicitly supplied patches, and any patches supplied to the repository rule.

This change in semantics broke a custom repository rule that called `patch()` multiple times, and which relied on being able to pass `patches = []` to force patch() to ignore the repository rule's ctx.attr.patches.

I cannot see anything in the description of commit e9a4e93ed71 to explain why it makes this breaking change. It appears to be completely orthogonal to adding support for remote_patches. Side note: if patch() is now to support a remote_patches attribute on the repository rules, why did it not add a corresponding remote_patches parameter to patch()?

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

Write a custom repository rule that calls patch() with patches = [] and observe that it applies patches from the patches attribute of a call to that repository rule.

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

Ubuntu 20.04

### What is the output of `bazel info release`?

release 5.3.0

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

_No response_

### What's the output of `git remote get-url origin; git rev-parse master; git rev-parse HEAD` ?

_No response_

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

_No response_

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

_No response_

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.