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

Apply package_dir to pkg_mklink in pkg_tar #637

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/private/tar/build_tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ def add_link(self, symlink, destination, mode=None, ids=None, names=None):
names: (username, groupname) for the file to set ownership. An empty
file will be created as `destfile` in the layer.
"""
symlink = normpath(symlink)
dest = self.normalize_path(symlink)
self.tarfile.add_file(
symlink,
dest,
tarfile.SYMTYPE,
link=destination,
mode = mode,
Expand Down
18 changes: 12 additions & 6 deletions tests/tar/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"""Tests for pkg_tar."""

# buildifier: disable=bzl-visibility
load("//pkg:mappings.bzl", "pkg_files", "strip_prefix")
load("//pkg:mappings.bzl", "pkg_files", "pkg_mklink", "strip_prefix")
load("//pkg/private/tar:tar.bzl", "SUPPORTED_TAR_COMPRESSIONS", "pkg_tar")
load("//tests:my_package_name.bzl", "my_package_naming")
load("//tests/util:defs.bzl", "directory", "link_tree", "fake_artifact")
load("//tests/util:defs.bzl", "directory", "fake_artifact", "link_tree")
load("@rules_python//python:defs.bzl", "py_test")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")

Expand Down Expand Up @@ -113,9 +113,16 @@ pkg_tar(
package_variables = ":my_package_variables",
)

pkg_mklink(
name = "mylink",
link_name = "mylink",
target = "dangling",
)

pkg_tar(
name = "test_tar_package_dir",
srcs = [
":mylink",
":etc/nsswitch.conf",
],
package_dir = "/my/package",
Expand Down Expand Up @@ -419,13 +426,12 @@ directory(
"foo/bar/baz",
],
links = {
"foo/bar/hello": "../hello.txt",
"foo/bar/alt_baz": "baz",
"foo/alt_baz": "bar/baz",
"foo/bar/hello": "../hello.txt",
"foo/bar/alt_baz": "baz",
"foo/alt_baz": "bar/baz",
},
)


# This target has symlinks 3 ways.
# - mklinks rules.
# - source files that are symlinks
Expand Down
1 change: 1 addition & 0 deletions tests/tar/tar_writer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ def testPackageDirAttribute(self):
expected_content = [
{"name": "my"},
{"name": "my/package"},
{"name": "my/package/mylink"},
aiuto marked this conversation as resolved.
Show resolved Hide resolved
{"name": "my/package/nsswitch.conf"},
]
self.assertTarFileContent(package_dir, expected_content)
Expand Down
7 changes: 7 additions & 0 deletions tests/zip/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,17 @@ filegroup(
],
)

pkg_mklink(
name = "mylink",
link_name = "mylink",
target = "dangling",
)

# All of these should produce the same zip file.
[pkg_zip(
name = "test_zip_package_dir" + str(idx),
srcs = [
":mylink",
"//tests:testdata/hello.txt",
"//tests:testdata/loremipsum.txt",
],
Expand Down
1 change: 1 addition & 0 deletions tests/zip/zip_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def test_package_dir(self):
self.assertZipFileContent("test_zip_package_dir0.zip", [
{"filename": "abc/def/hello.txt", "crc": HELLO_CRC},
{"filename": "abc/def/loremipsum.txt", "crc": LOREM_CRC},
{"filename": "abc/def/mylink", "attr": 0o777},
])

def test_package_dir_substitution(self):
Expand Down