Create a MappingContext to hold behaviors and defaults
Change calls
from process_x(ctx, content_map, file_deps, <important args>, default_x=None, default_y, ...)
to process_x(mapping_context, <important args>)
This brings the code more in line with the preferred rule writing style. Specifically, don't pass ctx around, pass the intent so you can control behavior.
A major motivation for the change is adding include_runfiles to pkg_tar, where we want to sometimes have add_label_list do the runfiles inclusion for us, and other times we want to revert to legacy behavior. If we only signaled runfiles in a single attribute in ctx, that would not be possible.
Other considerations.
This dropped some processing of a default mode for directories being set to 0555. While looking at the code, it turns out the default is always set from pkg_mkdirs, to 0755, which is more often what people expect. In the future, we might add default_dir_mode to mapping_context. I'm not doing that today, because we should look at #385 and #707 first. The whole attribute scheme is not really sufficient.
I discovered a lot of loose behavior around default modes and users/groups. Some places look improved for users/groups, but mode is done a little different. This is intentional to preserve existing behavior so the tests pass. Someone will have to go back later and determine if tightening the behavior fixes bugs or breaks existing good behavior.
If it was not clear from above. I preserved behavior over "correctness" so that the PR is only about code and not features.
process_x(ctx, content_map, file_deps, <important args>, default_x=None, default_y, ...)
process_x(mapping_context, <important args>)
ctx
, that would not be possible.Other considerations.