bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
23.31k stars 4.1k forks source link

[bazel.build] Problem with /reference/be/functions: effect of glob(allow_empty = False) #20377

Open lingithub1 opened 1 year ago

lingithub1 commented 1 year ago

Page link:

https://bazel.build/reference/be/functions

Problem description (include actual vs expected text, if applicable):

A part of the effect of allow_empty is missing in the description:

Where do you see this issue? (include link to specific section of the page, if applicable)

https://bazel.build/reference/be/functions#glob_example states:

If the allow_empty argument is set to False, the glob function will error-out if the result would otherwise be the empty list.

https://github.com/bazelbuild/bazel/issues/8195 states:

We've just added a new argument to glob: 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.

Therefor, the documentation is missing that allow_empty = True will error out not only if the result is empty but also if any of the patterns does not match a single file (or directory, depending on exclude_directories).

Any other information you'd like to share?

No response

brentleyjones commented 1 month ago

Now that --incompatible_disallow_empty_glob is being flipped in Bazel 8.0, this needs to be a higher priority than P3. I was about to file a bug on incorrect allow_empty behavior, since it was surprising that it was erroring on patterns instead of the overall result being empty.