Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle empty directory when checking for missing file #402

Merged
merged 1 commit into from
Apr 4, 2023

Conversation

acordiner
Copy link
Contributor

@acordiner acordiner commented Apr 3, 2023

Description

The _is_file_missing() function uses a glob to determine if a file is missing. However, it has allow_empty = False, which
means an error will occur if an empty directory is searched.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature or functionality (non-breaking change which adds functionality)
  • Style (white-space, formatting, etc...)
  • Refactor (a code change that neither fixes a bug or adds a new feature)
  • Performance (a code change that improves performance)
  • Documentation (updates to documentation or READMEs)
  • Chore (any other change that doesn't affect source or test files)

Properties of change

  • Breaking change (this change will cause existing functionality to not work as expected)
  • This change requires a documentation update

Test plan

How has this been tested?

  • Covered by existing tests cases
  • New test cases added
  • Local testing

If part of the test plan included local testing, please provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

Using write_source_file() with an empty directory results in the following erro:

Traceback (most recent call last):

File "/Users/alister/example/BUILD.bazel", line 22, column 17, in <toplevel>

example(

File "/Users/alister/example/rules.bzl", line 595, column 22, in example

write_source_file(

File "/private/var/tmp/_bazel_alister/fb38e376d8efddf3cdb91fd1e4a65c39/external/aspect_bazel_lib/lib/private/write_source_file.bzl", line 82, column 40, in 
write_source_file

out_file_missing = _is_file_missing(out_file)

File "/private/var/tmp/_bazel_alister/fb38e376d8efddf3cdb91fd1e4a65c39/external/aspect_bazel_lib/lib/private/write_source_file.bzl", line 374, column 28, in 
_is_file_missing

file_glob = native.glob([file_rel], exclude_directories = 0)

Error in glob: glob pattern 'empty_directory/foobar.txt' didn't match anything, but allow_empty is set to False (the default value of allow_empty can be set with 
--incompatible_disallow_empty_glob).

I believe the correct behaviour should be that _is_file_missing() returns false.

@acordiner acordiner marked this pull request as ready for review April 4, 2023 00:07
Copy link
Collaborator

@alexeagle alexeagle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds correct to me, thanks!

@alexeagle alexeagle merged commit 803d5ec into bazel-contrib:main Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants