Skip to content

Commit

Permalink
Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
ewianda committed Apr 24, 2024
1 parent 974af11 commit 1a87c87
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build --test_output=errors
9 changes: 5 additions & 4 deletions pkg/private/pkg_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ _MappingContext = provider(
"include_runfiles": "bool: include runfiles",
"workspace_name": "string: name of the main workspace",
"strip_prefix": "strip_prefix",

"path_mapper": "function to map destination paths",

# Defaults
Expand All @@ -94,7 +95,8 @@ def create_mapping_context_from_ctx(
strip_prefix = None,
include_runfiles = None,
default_mode = None,
path_mapper = None):
path_mapper = None
):
"""Construct a MappingContext.
Args: See the provider definition.
Expand Down Expand Up @@ -398,8 +400,7 @@ def add_from_default_info(
all_files = src[DefaultInfo].files.to_list()
for f in all_files:
d_path = mapping_context.path_mapper(
dest_path(f, data_path, data_path_without_prefix),
)
dest_path(f, data_path, data_path_without_prefix))
if f.is_directory:
add_tree_artifact(
mapping_context.content_map,
Expand Down Expand Up @@ -439,7 +440,7 @@ def add_from_default_info(
_check_dest(mapping_context.content_map, d_path, rf, src.label, mapping_context.allow_duplicates_with_different_content)
mapping_context.content_map[d_path] = _DestFile(
src = rf,
entry_type = ENTRY_IS_DIR if rf.is_directory else ENTRY_IS_FILE,
entry_type = ENTRY_IS_TREE if rf.is_directory else ENTRY_IS_FILE,
origin = src.label,
mode = fmode,
user = mapping_context.default_user,
Expand Down
38 changes: 38 additions & 0 deletions tests/tar/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -710,3 +710,41 @@ verify_archive_test(
"new/base/something/this": "that",
},
)
fake_artifact(
name = "program_with_dir_runfiles",
files = ["//tests:testdata/executable.sh"],
runfiles = [
":generate_tree",
],
)

pkg_tar(
name = "program_with_dir_runfiles_tar",
srcs = [
":program_with_dir_runfiles",
],
include_runfiles = True,
)

verify_archive_test(
name = "program_with_dir_runfiles_test",
must_contain = [
"program_with_dir_runfiles.runfiles",
"program_with_dir_runfiles.runfiles/_main",
"program_with_dir_runfiles.runfiles/_main/tests",
"program_with_dir_runfiles.runfiles/_main/tests/tar",
"program_with_dir_runfiles.runfiles/_main/tests/tar/generate_tree",
"program_with_dir_runfiles.runfiles/_main/tests/tar/generate_tree/a",
"program_with_dir_runfiles.runfiles/_main/tests/tar/generate_tree/a/a",
"program_with_dir_runfiles.runfiles/_main/tests/tar/generate_tree/a/b",
"program_with_dir_runfiles.runfiles/_main/tests/tar/generate_tree/a/b/c",
"program_with_dir_runfiles.runfiles/_main/tests/tar/generate_tree/b",
"program_with_dir_runfiles.runfiles/_main/tests/tar/generate_tree/b/c",
"program_with_dir_runfiles.runfiles/_main/tests/tar/generate_tree/b/c/d",
"program_with_dir_runfiles.runfiles/_main/tests/tar/generate_tree/b/d",
"program_with_dir_runfiles.runfiles/_main/tests/tar/generate_tree/b/e",
"executable.sh",
"program_with_dir_runfiles",
],
target = ":program_with_dir_runfiles_tar",
)

0 comments on commit 1a87c87

Please sign in to comment.