From 1a87c8726b2516460d5833203aacdcf755576fb9 Mon Sep 17 00:00:00 2001 From: Elvis Wianda Date: Wed, 24 Apr 2024 11:04:47 -0400 Subject: [PATCH] Add test case --- .bazelrc | 1 + pkg/private/pkg_files.bzl | 9 +++++---- tests/tar/BUILD | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 .bazelrc diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 00000000..feebfd33 --- /dev/null +++ b/.bazelrc @@ -0,0 +1 @@ +build --test_output=errors diff --git a/pkg/private/pkg_files.bzl b/pkg/private/pkg_files.bzl index 00cc58b7..4ab0eb3f 100644 --- a/pkg/private/pkg_files.bzl +++ b/pkg/private/pkg_files.bzl @@ -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 @@ -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. @@ -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, @@ -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, diff --git a/tests/tar/BUILD b/tests/tar/BUILD index 27f231ec..581cab42 100644 --- a/tests/tar/BUILD +++ b/tests/tar/BUILD @@ -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", +)