diff options
author | aiuto <aiuto@google.com> | 2022-11-23 12:45:25 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-23 12:45:25 -0500 |
commit | ecd5112072ee28ff1c384fdf2dcf0da76866ce1d (patch) | |
tree | 0bd166526b248ae75d0ecfc7923853d2c05536ce | |
parent | daa231c2dea74195c95bf1c87e74028cca5aa54a (diff) | |
download | bazelbuild-rules_pkg-ecd5112072ee28ff1c384fdf2dcf0da76866ce1d.tar.gz |
Apply package_dir to pkg_mklink (#637)
- Fix brokenness in pkg_tar
- Add tests (it was working) to pkg_zip
Fixes #610
-rw-r--r-- | pkg/private/tar/build_tar.py | 4 | ||||
-rw-r--r-- | tests/tar/BUILD | 18 | ||||
-rw-r--r-- | tests/tar/tar_writer_test.py | 1 | ||||
-rw-r--r-- | tests/zip/BUILD | 7 | ||||
-rw-r--r-- | tests/zip/zip_test.py | 1 |
5 files changed, 23 insertions, 8 deletions
diff --git a/pkg/private/tar/build_tar.py b/pkg/private/tar/build_tar.py index 6ef057e..ab16610 100644 --- a/pkg/private/tar/build_tar.py +++ b/pkg/private/tar/build_tar.py @@ -176,9 +176,9 @@ class TarFile(object): 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, diff --git a/tests/tar/BUILD b/tests/tar/BUILD index b051b79..19504e1 100644 --- a/tests/tar/BUILD +++ b/tests/tar/BUILD @@ -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") @@ -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", @@ -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 diff --git a/tests/tar/tar_writer_test.py b/tests/tar/tar_writer_test.py index f3e08bf..39008ea 100644 --- a/tests/tar/tar_writer_test.py +++ b/tests/tar/tar_writer_test.py @@ -217,6 +217,7 @@ class TarFileWriterTest(unittest.TestCase): expected_content = [ {"name": "my"}, {"name": "my/package"}, + {"name": "my/package/mylink"}, {"name": "my/package/nsswitch.conf"}, ] self.assertTarFileContent(package_dir, expected_content) diff --git a/tests/zip/BUILD b/tests/zip/BUILD index 46c52dd..56c739b 100644 --- a/tests/zip/BUILD +++ b/tests/zip/BUILD @@ -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", ], diff --git a/tests/zip/zip_test.py b/tests/zip/zip_test.py index 89d2c04..1fddae5 100644 --- a/tests/zip/zip_test.py +++ b/tests/zip/zip_test.py @@ -70,6 +70,7 @@ class ZipContentsTests(zip_test_lib.ZipContentsTestBase): 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): |