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

add recurse option to pkg_zip to maintain directory structure #428

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 2 additions & 1 deletion pkg/pkg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ def _pkg_zip_impl(ctx):
):
# Add in the files of srcs which are not pkg_* types
for f in src.files.to_list():
d_path = dest_path(f, data_path, data_path_without_prefix)
d_path = dest_path(f, data_path, data_path_without_prefix) if not ctx.attr.recurse else dest_path(f, data_path_without_prefix, data_path_without_prefix)
if f.is_directory:
# Tree artifacts need a name, but the name is never really
# the important part. The likely behavior people want is
Expand Down Expand Up @@ -670,6 +670,7 @@ pkg_zip_impl = rule(
"srcs": attr.label_list(allow_files = True),
"strip_prefix": attr.string(),
"timestamp": attr.int(default = 315532800),
"recurse": attr.bool(default = False),

# Common attributes
"out": attr.output(mandatory = True),
Expand Down
23 changes: 23 additions & 0 deletions pkg/tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,27 @@ filegroup(
"/abc/def/",
])]

pkg_zip(
name = "test_zip_recurse",
srcs = glob([
"testdata/nested/*.txt",
"testdata/hello.txt",
"testdata/loremipsum.txt",
]),
recurse = True
)

pkg_zip(
name = "test_zip_recurse_package_dir",
srcs = glob([
"testdata/nested/*.txt",
"testdata/hello.txt",
"testdata/loremipsum.txt",
]),
recurse = True,
package_dir = "abc/def"
)

py_test(
name = "zip_test",
srcs = [
Expand All @@ -337,6 +358,8 @@ py_test(
"test-zip-strip_prefix-none.zip",
"test-zip-strip_prefix-zipcontent.zip",
"test-zip-strip_prefix-dot.zip",
"test_zip_recurse.zip",
"test_zip_recurse_package_dir.zip",

# these could be replaced with diff_test() rules (from skylib)
"test_zip_basic_timestamp_before_epoch.zip",
Expand Down
1 change: 1 addition & 0 deletions pkg/tests/testdata/nested/nested.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Nested Text
15 changes: 15 additions & 0 deletions pkg/tests/zip_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

HELLO_CRC = 2069210904
LOREM_CRC = 2178844372
NESTED_CRC = 143981220
EXECUTABLE_CRC = 342626072

# Unix dir bit and Windows dir bit. Magic from zip spec
Expand Down Expand Up @@ -89,6 +90,20 @@ def test_basic(self):
{"filename": "loremipsum.txt", "crc": LOREM_CRC},
])

def test_recurse(self):
self.assertZipFileContent("test_zip_recurse.zip", [
{"filename": "testdata/hello.txt", "crc": HELLO_CRC},
{"filename": "testdata/loremipsum.txt", "crc": LOREM_CRC},
{"filename": "testdata/nested/nested.txt", "crc": NESTED_CRC},
])

def test_recurse_package_dir(self):
self.assertZipFileContent("test_zip_recurse_package_dir.zip", [
{"filename": "abc/def/testdata/hello.txt", "crc": HELLO_CRC},
{"filename": "abc/def/testdata/loremipsum.txt", "crc": LOREM_CRC},
{"filename": "abc/def/testdata/nested/nested.txt", "crc": NESTED_CRC},
])

def test_timestamp(self):
self.assertZipFileContent("test_zip_timestamp.zip", [
{"filename": "hello.txt", "crc": HELLO_CRC, "timestamp": 1234567890},
Expand Down