From fc3c3181f3cd3ede5be99913b5ac70cdb608d47b Mon Sep 17 00:00:00 2001 From: Ted Kaplan Date: Mon, 18 Sep 2023 19:58:27 -0700 Subject: [PATCH] docs: Add --incompatible_disallow_empty_glob to correctness.bazelrc (#524) --- .aspect/bazelrc/correctness.bazelrc | 6 ++++++ e2e/smoke/.aspect/bazelrc/correctness.bazelrc | 6 ++++++ lib/private/utils.bzl | 2 +- lib/tests/bazelrc_presets/all/correctness.bazelrc | 6 ++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.aspect/bazelrc/correctness.bazelrc b/.aspect/bazelrc/correctness.bazelrc index 56fad5f..a540eb8 100644 --- a/.aspect/bazelrc/correctness.bazelrc +++ b/.aspect/bazelrc/correctness.bazelrc @@ -60,3 +60,9 @@ query --experimental_allow_tags_propagation # https://github.com/bazelbuild/bazel/issues/10076. # Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_default_to_explicit_init_py build --incompatible_default_to_explicit_init_py + +# Set default value of `allow_empty` to `False` in `glob()`. This prevents a common mistake when +# attempting to use `glob()` to match files in a subdirectory that is opaque to the current package +# because it contains a BUILD file. See https://github.com/bazelbuild/bazel/issues/8195. +# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_disallow_empty_glob +common --incompatible_disallow_empty_glob diff --git a/e2e/smoke/.aspect/bazelrc/correctness.bazelrc b/e2e/smoke/.aspect/bazelrc/correctness.bazelrc index 56fad5f..a540eb8 100644 --- a/e2e/smoke/.aspect/bazelrc/correctness.bazelrc +++ b/e2e/smoke/.aspect/bazelrc/correctness.bazelrc @@ -60,3 +60,9 @@ query --experimental_allow_tags_propagation # https://github.com/bazelbuild/bazel/issues/10076. # Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_default_to_explicit_init_py build --incompatible_default_to_explicit_init_py + +# Set default value of `allow_empty` to `False` in `glob()`. This prevents a common mistake when +# attempting to use `glob()` to match files in a subdirectory that is opaque to the current package +# because it contains a BUILD file. See https://github.com/bazelbuild/bazel/issues/8195. +# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_disallow_empty_glob +common --incompatible_disallow_empty_glob diff --git a/lib/private/utils.bzl b/lib/private/utils.bzl index 162522c..ae07598 100644 --- a/lib/private/utils.bzl +++ b/lib/private/utils.bzl @@ -133,7 +133,7 @@ def _file_exists(path): label = _to_label(path) file_abs = "%s/%s" % (label.package, label.name) file_rel = file_abs[len(native.package_name()) + 1:] - file_glob = native.glob([file_rel], exclude_directories = 1) + file_glob = native.glob([file_rel], exclude_directories = 1, allow_empty = True) return len(file_glob) > 0 def _default_timeout(size, timeout): diff --git a/lib/tests/bazelrc_presets/all/correctness.bazelrc b/lib/tests/bazelrc_presets/all/correctness.bazelrc index 56fad5f..a540eb8 100644 --- a/lib/tests/bazelrc_presets/all/correctness.bazelrc +++ b/lib/tests/bazelrc_presets/all/correctness.bazelrc @@ -60,3 +60,9 @@ query --experimental_allow_tags_propagation # https://github.com/bazelbuild/bazel/issues/10076. # Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_default_to_explicit_init_py build --incompatible_default_to_explicit_init_py + +# Set default value of `allow_empty` to `False` in `glob()`. This prevents a common mistake when +# attempting to use `glob()` to match files in a subdirectory that is opaque to the current package +# because it contains a BUILD file. See https://github.com/bazelbuild/bazel/issues/8195. +# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_disallow_empty_glob +common --incompatible_disallow_empty_glob