Skip to content

Commit 4fa18d1

Browse files
authored
Rename pkg_mklink.src to target (#496)
* rename mklinks src to target * allow src as an alternate * rename dest to link_name * do docs
1 parent 5a976bc commit 4fa18d1

File tree

13 files changed

+105
-58
lines changed

13 files changed

+105
-58
lines changed

docs/latest.md

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -562,12 +562,12 @@ Defines creation and ownership of directories in packages
562562
| <a id="pkg_mkdirs-dirs"></a>dirs | Directory names to make within the package<br><br> If any part of the requested directory structure does not already exist within a package, the package builder will create it for you with a reasonable set of default permissions (typically <code>0755 root.root</code>). | List of strings | required | |
563563

564564

565-
<a id="#pkg_mklink"></a>
565+
<a id="#pkg_mklink_impl"></a>
566566

567-
## pkg_mklink
567+
## pkg_mklink_impl
568568

569569
<pre>
570-
pkg_mklink(<a href="#pkg_mklink-name">name</a>, <a href="#pkg_mklink-attributes">attributes</a>, <a href="#pkg_mklink-dest">dest</a>, <a href="#pkg_mklink-src">src</a>)
570+
pkg_mklink_impl(<a href="#pkg_mklink_impl-name">name</a>, <a href="#pkg_mklink_impl-attributes">attributes</a>, <a href="#pkg_mklink_impl-link_name">link_name</a>, <a href="#pkg_mklink_impl-target">target</a>)
571571
</pre>
572572

573573
Define a symlink within packages
@@ -584,10 +584,10 @@ Define a symlink within packages
584584

585585
| Name | Description | Type | Mandatory | Default |
586586
| :------------- | :------------- | :------------- | :------------- | :------------- |
587-
| <a id="pkg_mklink-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
588-
| <a id="pkg_mklink-attributes"></a>attributes | Attributes to set on packaged symbolic links.<br><br> Always use <code>pkg_attributes()</code> to set this rule attribute.<br><br> Symlink permissions may have different meanings depending on your host operating system; consult its documentation for more details.<br><br> If not otherwise overridden, the link's mode will be set to UNIX "0777", or the target platform's equivalent.<br><br> Consult the "Mapping Attributes" documentation in the rules_pkg reference for more details. | String | optional | "{}" |
589-
| <a id="pkg_mklink-dest"></a>dest | Link "target", a path within the package.<br><br> This is the actual created symbolic link.<br><br> If the directory structure provided by this attribute is not otherwise created when exist within the package when it is built, it will be created implicitly, much like with <code>pkg_files</code>.<br><br> This path may be prefixed or rooted by grouping or packaging rules. | String | required | |
590-
| <a id="pkg_mklink-src"></a>src | Link "source", a path on the filesystem.<br><br> This is what the link "points" to, and may point to an arbitrary filesystem path, even relative paths. | String | required | |
587+
| <a id="pkg_mklink_impl-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
588+
| <a id="pkg_mklink_impl-attributes"></a>attributes | Attributes to set on packaged symbolic links.<br><br> Always use <code>pkg_attributes()</code> to set this rule attribute.<br><br> Symlink permissions may have different meanings depending on your host operating system; consult its documentation for more details.<br><br> If not otherwise overridden, the link's mode will be set to UNIX "0777", or the target platform's equivalent.<br><br> Consult the "Mapping Attributes" documentation in the rules_pkg reference for more details. | String | optional | "{}" |
589+
| <a id="pkg_mklink_impl-link_name"></a>link_name | Link "destination", a path within the package.<br><br> This is the actual created symbolic link.<br><br> If the directory structure provided by this attribute is not otherwise created when exist within the package when it is built, it will be created implicitly, much like with <code>pkg_files</code>.<br><br> This path may be prefixed or rooted by grouping or packaging rules. | String | required | |
590+
| <a id="pkg_mklink_impl-target"></a>target | Link "target", a path on the filesystem.<br><br> This is what the link "points" to, and may point to an arbitrary filesystem path, even relative paths. | String | required | |
591591

592592

593593
<a id="#pkg_attributes"></a>
@@ -629,6 +629,29 @@ rules (e.g. `pkg_files`).
629629
A value usable in the "attributes" attribute in package mapping rules.
630630

631631

632+
<a id="#pkg_mklink"></a>
633+
634+
## pkg_mklink
635+
636+
<pre>
637+
pkg_mklink(<a href="#pkg_mklink-name">name</a>, <a href="#pkg_mklink-link_name">link_name</a>, <a href="#pkg_mklink-target">target</a>, <a href="#pkg_mklink-attributes">attributes</a>, <a href="#pkg_mklink-src">src</a>, <a href="#pkg_mklink-kwargs">kwargs</a>)
638+
</pre>
639+
640+
Create a symlink.
641+
642+
**PARAMETERS**
643+
644+
645+
| Name | Description | Default Value |
646+
| :------------- | :------------- | :------------- |
647+
| <a id="pkg_mklink-name"></a>name | target name | none |
648+
| <a id="pkg_mklink-link_name"></a>link_name | the path in the package that should point to the target. | none |
649+
| <a id="pkg_mklink-target"></a>target | target path that the link should point to. | none |
650+
| <a id="pkg_mklink-attributes"></a>attributes | file attributes. | <code>None</code> |
651+
| <a id="pkg_mklink-src"></a>src | <p align="center"> - </p> | <code>None</code> |
652+
| <a id="pkg_mklink-kwargs"></a>kwargs | <p align="center"> - </p> | none |
653+
654+
632655
<a id="#strip_prefix.files_only"></a>
633656

634657
## strip_prefix.files_only

examples/rich_structure/src/client/BUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ pkg_files(
9494

9595
pkg_mklink(
9696
name = "usr_bin",
97-
src = select(shared_object_path_selector) + "/bin/foo",
98-
dest = "usr/bin/foo",
97+
link_name = "usr/bin/foo",
98+
target = select(shared_object_path_selector) + "/bin/foo",
9999
)
100100

101101
pkg_filegroup(

pkg/mappings.bzl

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -476,13 +476,13 @@ def _pkg_mklink_impl(ctx):
476476
out_attributes.setdefault("mode", "0777")
477477
return [
478478
PackageSymlinkInfo(
479-
destination = ctx.attr.dest,
480-
source = ctx.attr.src,
479+
destination = ctx.attr.link_name,
480+
target = ctx.attr.target,
481481
attributes = out_attributes,
482482
),
483483
]
484484

485-
pkg_mklink = rule(
485+
pkg_mklink_impl = rule(
486486
doc = """Define a symlink within packages
487487
488488
This rule results in the creation of a single link within a package.
@@ -494,8 +494,17 @@ pkg_mklink = rule(
494494
implementation = _pkg_mklink_impl,
495495
# @unsorted-dict-items
496496
attrs = {
497-
"dest": attr.string(
498-
doc = """Link "target", a path within the package.
497+
"target": attr.string(
498+
doc = """Link "target", a path on the filesystem.
499+
500+
This is what the link "points" to, and may point to an arbitrary
501+
filesystem path, even relative paths.
502+
503+
""",
504+
mandatory = True,
505+
),
506+
"link_name": attr.string(
507+
doc = """Link "destination", a path within the package.
499508
500509
This is the actual created symbolic link.
501510
@@ -508,15 +517,6 @@ pkg_mklink = rule(
508517
""",
509518
mandatory = True,
510519
),
511-
"src": attr.string(
512-
doc = """Link "source", a path on the filesystem.
513-
514-
This is what the link "points" to, and may point to an arbitrary
515-
filesystem path, even relative paths.
516-
517-
""",
518-
mandatory = True,
519-
),
520520
"attributes": attr.string(
521521
doc = """Attributes to set on packaged symbolic links.
522522
@@ -537,6 +537,31 @@ pkg_mklink = rule(
537537
provides = [PackageSymlinkInfo],
538538
)
539539

540+
def pkg_mklink(name, link_name, target, attributes=None, src=None, **kwargs):
541+
"""Create a symlink.
542+
543+
Args:
544+
name: target name
545+
target: target path that the link should point to.
546+
link_name: the path in the package that should point to the target.
547+
attributes: file attributes.
548+
"""
549+
if src:
550+
if target:
551+
fail("You can not specify both target and src.")
552+
# buildifier: disable=print
553+
print("Warning: pkg_mklink.src is deprecated. Use target.")
554+
target = src
555+
pkg_mklink_impl(
556+
name = name,
557+
target = target,
558+
link_name = link_name,
559+
attributes = attributes,
560+
**kwargs,
561+
)
562+
563+
564+
540565
def _pkg_filegroup_impl(ctx):
541566
files = []
542567
dirs = []
@@ -575,7 +600,7 @@ def _pkg_filegroup_impl(ctx):
575600
links += [
576601
(
577602
PackageSymlinkInfo(
578-
source = psi.source,
603+
target = psi.target,
579604
destination = paths.join(ctx.attr.prefix, psi.destination),
580605
attributes = psi.attributes,
581606
),
@@ -608,7 +633,7 @@ def _pkg_filegroup_impl(ctx):
608633

609634
if PackageSymlinkInfo in s:
610635
new_psi = PackageSymlinkInfo(
611-
source = s[PackageSymlinkInfo].source,
636+
target = s[PackageSymlinkInfo].target,
612637
destination = paths.join(ctx.attr.prefix, s[PackageSymlinkInfo].destination),
613638
attributes = s[PackageSymlinkInfo].attributes,
614639
)

pkg/private/pkg_files.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def _process_pkg_symlink(content_map, pkg_symlink_info, origin, default_mode, de
122122
user = attrs[1],
123123
group = attrs[2],
124124
origin = origin,
125-
link_to = pkg_symlink_info.source,
125+
link_to = pkg_symlink_info.target,
126126
)
127127

128128
def _process_pkg_filegroup(content_map, pkg_filegroup_info, origin, default_mode, default_user, default_group):

pkg/providers.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ PackageSymlinkInfo = provider(
6565
fields = {
6666
"attributes": """See `attributes` in PackageFilesInfo.""",
6767
"destination": """string: Filesystem link 'name'""",
68-
"source": """string or Label: Filesystem link 'target'.
68+
"target": """string or Label: Filesystem link 'target'.
6969
7070
TODO(nacl): Label sources not yet supported.
7171
""",

pkg/rpm_pfg.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def _process_symlink(psi, origin_label, grouping_label, file_base, dest_check_ma
202202
rpm_files_list.append(file_base + " " + abs_dest)
203203
install_script_pieces.append(_INSTALL_SYMLINK_STANZA_FMT.format(
204204
abs_dest,
205-
psi.source,
205+
psi.target,
206206
psi.attributes["mode"],
207207
))
208208

tests/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
1818
load(":my_package_name.bzl", "my_package_naming")
1919
load(":path_test.bzl", "path_tests")
2020
load("//pkg:deb.bzl", "pkg_deb")
21-
load("//pkg:mappings.bzl", "pkg_attributes", "pkg_mkdirs", "pkg_mklink")
21+
load("//pkg:mappings.bzl", "pkg_attributes", "pkg_mkdirs")
2222
load("//pkg:pkg.bzl", "pkg_tar")
2323
load("//pkg:zip.bzl", "pkg_zip")
2424

tests/deb/BUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ my_package_naming(
3838

3939
pkg_mklink(
4040
name = "java_link",
41-
src = "/path/to/bin/java",
42-
dest = "usr/bin/java",
41+
link_name = "usr/bin/java",
42+
target = "/path/to/bin/java",
4343
)
4444

4545
pkg_tar(

tests/mappings/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ load(
2525
"pkg_filegroup",
2626
"pkg_files",
2727
"pkg_mkdirs",
28-
"pkg_mklink",
2928
"strip_prefix",
3029
)
3130
load("//tests/util:defs.bzl", "directory", "write_content_manifest")

tests/mappings/mappings_test.bzl

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def _test_pkg_files_contents():
213213
),
214214
)
215215

216-
# Test that pkg_files rejects cases where two sources resolve to the same
216+
# Test that pkg_files rejects cases where two targets resolve to the same
217217
# destination.
218218
pkg_files(
219219
name = "pf_destination_collision_invalid_g",
@@ -557,14 +557,14 @@ def _pkg_mklink_contents_test_impl(ctx):
557557

558558
asserts.equals(
559559
env,
560-
ctx.attr.expected_src,
561-
target_under_test[PackageSymlinkInfo].source,
562-
"pkg_mklink source does not match expectations",
560+
ctx.attr.expected_target,
561+
target_under_test[PackageSymlinkInfo].target,
562+
"pkg_mklink target does not match expectations",
563563
)
564564

565565
asserts.equals(
566566
env,
567-
ctx.attr.expected_dest,
567+
ctx.attr.expected_link_name,
568568
target_under_test[PackageSymlinkInfo].destination,
569569
"pkg_mklink destination does not match expectations",
570570
)
@@ -583,35 +583,35 @@ def _pkg_mklink_contents_test_impl(ctx):
583583
pkg_mklink_contents_test = analysistest.make(
584584
_pkg_mklink_contents_test_impl,
585585
attrs = {
586-
"expected_src": attr.string(mandatory = True),
587-
"expected_dest": attr.string(mandatory = True),
588586
"expected_attributes": attr.string(),
587+
"expected_link_name": attr.string(mandatory = True),
588+
"expected_target": attr.string(mandatory = True),
589589
},
590590
)
591591

592592
def _test_pkg_mklink():
593593
pkg_mklink(
594594
name = "pkg_mklink_base_g",
595-
dest = "foo",
596-
src = "bar",
595+
link_name = "foo",
596+
target = "bar",
597597
tags = ["manual"],
598598
attributes = pkg_attributes(mode = "0111"),
599599
)
600600

601601
pkg_mklink_contents_test(
602602
name = "pkg_mklink_base",
603603
target_under_test = ":pkg_mklink_base_g",
604-
expected_dest = "foo",
605-
expected_src = "bar",
604+
expected_link_name = "foo",
605+
expected_target = "bar",
606606
expected_attributes = pkg_attributes(mode = "0111"),
607607
)
608608

609609
# Test that the default mode (0755) is always set regardless of the other
610610
# values in "attributes".
611611
pkg_mklink(
612612
name = "pkg_mklink_mode_overlay_if_not_provided_g",
613-
dest = "foo",
614-
src = "bar",
613+
link_name = "foo",
614+
target = "bar",
615615
attributes = pkg_attributes(
616616
user = "root",
617617
group = "sudo",
@@ -621,8 +621,8 @@ def _test_pkg_mklink():
621621
pkg_mklink_contents_test(
622622
name = "pkg_mklink_mode_overlay_if_not_provided",
623623
target_under_test = ":pkg_mklink_mode_overlay_if_not_provided_g",
624-
expected_dest = "foo",
625-
expected_src = "bar",
624+
expected_link_name = "foo",
625+
expected_target = "bar",
626626
expected_attributes = pkg_attributes(
627627
mode = "0777",
628628
user = "root",
@@ -734,8 +734,8 @@ def _test_pkg_filegroup(name):
734734

735735
pkg_mklink(
736736
name = "{}_pkg_symlink".format(name),
737-
src = "src",
738-
dest = "dest",
737+
link_name = "dest",
738+
target = "src",
739739
tags = ["manual"],
740740
)
741741

@@ -788,8 +788,8 @@ def _test_pkg_filegroup(name):
788788

789789
pkg_mklink(
790790
name = "{}_pkg_symlink_prefixed".format(name),
791-
src = "src",
792-
dest = "prefix/dest",
791+
link_name = "prefix/dest",
792+
target = "src",
793793
tags = ["manual"],
794794
)
795795

@@ -833,8 +833,8 @@ def _test_pkg_filegroup(name):
833833

834834
pkg_mklink(
835835
name = "{}_pkg_symlink_nested_prefixed".format(name),
836-
src = "src",
837-
dest = "nest/prefix/dest",
836+
link_name = "nest/prefix/dest",
837+
target = "src",
838838
tags = ["manual"],
839839
)
840840

0 commit comments

Comments
 (0)