It is well known that macOS Finder .DS_Store files should never be checked in to a repo, or leave the single machine for that matter.
Fairly recently, I noticed that a lot of my iOS resource processing actions were missing the cache for seemingly no reason. That is, until I looked at the Bazel action inputs. There, I noticed that every action that missed the cache had an extra input. Of course, it was the .DS_Store file.
The problem
The problem popped up because of the act of balancing developer convenience and build correctness. Given the following glob pattern:
resources = glob(["Assets.xcassets/**"]),
we allow engineers to freely add or remove files in an iOS asset catalog without needing to constantly modify the list in the BUILD.bazel file.
This, of course, means that .DS_Store files can get picked up if the engineer ever opened a Finder window at the given path. One might say that rules_apple should take care of this. However, that’s easier said than done, since asset catalogs can host many different resource types. Plus, Apple might extend the list of accepted resources at any time, which would require a rules_apple release just to add a file extension to some list.
The solution
The solution to this problem is quite simple: just make a macro for the glob() function:
def safe_glob(include, **kwargs):
exclude_pattern = kwargs.pop("exclude", []) + ["**/.DS_Store"]
return native.glob(
include = include,
exclude = exclude_pattern,
**kwargs
)
Now just load this symbol and use it instead of plain glob(...).
Conclusion
A neat trick to get around the fact that neither .bazelignore nor REPO.bazel solve this problem. I bet similar annoying files exist on Linux as well as Windows.