Skip to content

Commit

Permalink
Set the pkg_mklink permissions overlay scheme to match the one used i…
Browse files Browse the repository at this point in the history
…n other rules
  • Loading branch information
Andrew Psaltis committed Feb 25, 2021
1 parent bccf403 commit 36717b2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
22 changes: 15 additions & 7 deletions pkg/mappings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ pkg_files = rule(
Always use `pkg_attributes()` to set this rule attribute.
If not otherwise overridden, the file's mode will be set to UNIX
"0644".
"0644", or the target platform's equivalent.
Consult the "Mapping Attributes" documentation in the rules_pkg
reference for more details.
Expand Down Expand Up @@ -418,7 +418,7 @@ pkg_mkdirs = rule(
Always use `pkg_attributes()` to set this rule attribute.
If not otherwise overridden, the directory's mode will be set to
UNIX "0755".
UNIX "0755", or the target platform's equivalent.
Consult the "Mapping Attributes" documentation in the rules_pkg
reference for more details.
Expand All @@ -430,11 +430,17 @@ pkg_mkdirs = rule(
)

def _pkg_mklink_impl(ctx):
out_attributes = json.decode(ctx.attr.attributes)

# The least surprising default mode is that of a symbolic link (0777).
# Permissions on symlinks typically don't matter, as the operation is
# typically moved to where the link is pointing.
out_attributes.setdefault("mode", "0777")
return [
PackageSymlinkInfo(
destination = ctx.attr.dest,
source = ctx.attr.src,
attributes = json.decode(ctx.attr.attributes),
attributes = out_attributes,
),
]

Expand All @@ -448,6 +454,7 @@ pkg_mklink = rule(
""",
implementation = _pkg_mklink_impl,
# @unsorted-dict-items
attrs = {
"dest": attr.string(
doc = """Link "target", a path within the package.
Expand Down Expand Up @@ -477,16 +484,16 @@ pkg_mklink = rule(
Always use `pkg_attributes()` to set this rule attribute.
The default value for this is UNIX "0777", or the target
platform's equivalent. All other values are left unspecified.
Symlink permissions may have different meanings depending on your
host operating system; consult its documentation for more details.
If not otherwise overridden, the link's mode will be set to UNIX
"0777", or the target platform's equivalent.
Consult the "Mapping Attributes" documentation in the rules_pkg
reference for more details.
""",
default = pkg_attributes(mode = "0777"),
default = "{}", # Empty JSON
),
},
provides = [PackageSymlinkInfo],
Expand Down Expand Up @@ -562,6 +569,7 @@ pkg_filegroup = rule(
such as a prefix or a human-readable category.
""",
implementation = _pkg_filegroup_impl,
# @unsorted-dict-items
attrs = {
"srcs": attr.label_list(
doc = """A list of packaging specifications to be grouped together.""",
Expand Down
28 changes: 27 additions & 1 deletion pkg/tests/mappings/mappings_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -655,14 +655,39 @@ def _test_pkg_mklink():
dest = "foo",
src = "bar",
tags = ["manual"],
attributes = pkg_attributes(mode = "0111"),
)

pkg_mklink_contents_test(
name = "pkg_mklink_base",
target_under_test = ":pkg_mklink_base_g",
expected_dest = "foo",
expected_src = "bar",
expected_attributes = pkg_attributes(mode = "0777"),
expected_attributes = pkg_attributes(mode = "0111"),
)

# Test that the default mode (0755) is always set regardless of the other
# values in "attributes".
pkg_mklink(
name = "pkg_mklink_mode_overlay_if_not_provided_g",
dest = "foo",
src = "bar",
attributes = pkg_attributes(
user = "root",
group = "sudo",
),
tags = ["manual"],
)
pkg_mklink_contents_test(
name = "pkg_mklink_mode_overlay_if_not_provided",
target_under_test = ":pkg_mklink_mode_overlay_if_not_provided_g",
expected_dest = "foo",
expected_src = "bar",
expected_attributes = pkg_attributes(
mode = "0777",
user = "root",
group = "sudo",
),
)

##########
Expand Down Expand Up @@ -919,6 +944,7 @@ def mappings_analysis_tests():
":pkg_mkdirs_mode_overlay_if_not_provided",
# Tests involving pkg_mklink
":pkg_mklink_base",
":pkg_mklink_mode_overlay_if_not_provided",
# Tests involving pkg_filegroup
":pfg_tests",
],
Expand Down

0 comments on commit 36717b2

Please sign in to comment.