-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
The glob() function tends to be error-prone, because any typo in a path will silently return an empty list. This has been a source of confusion and bugs for many users.
glob has an optional Boolean argument allow_empty. For example, let's say your code looks like:
glob([pattern_a, pattern_b], exclude = [pattern_c], allow_empty = False)This code will fail if pattern_a or pattern_b doesn't match anything. It also fails if the whole function (after excluding pattern_c) doesn't match anything. We believe this behavior is safer in general.
In rare cases, this is intentional that a pattern doesn't match anything, e.g. when a source file is optional. When it happens, users should tell their intent explicitly by setting allow_empty = True.
-
What's going to change? The default value of
allow_emptyused to be True. It will change to False. -
How to update your code? If a glob fails, use
allow_empty = Trueto keep the old behavior.
In Bazel 8.0, the flag --incompatible_disallow_empty_glob will default to true. This means that the allow_empty argument defaults to False on all glob calls.