Skip to content

Handle cases with only data dependencies in pkg_tar#1044

Open
tempoz wants to merge 1 commit intobazelbuild:mainfrom
tempoz:patch-1
Open

Handle cases with only data dependencies in pkg_tar#1044
tempoz wants to merge 1 commit intobazelbuild:mainfrom
tempoz:patch-1

Conversation

@tempoz
Copy link

@tempoz tempoz commented Mar 9, 2026

If there is no base_path because there are no files, just use the empty string for the base_file_path.

The use case I have for this is packaging something of the following form:

filegroup(
    name = "foo_runfiles",
    data = [
        ":foo1",
        ":foo2",
        ":foo3",
        ":foo4",
    ],
)

pkg_tar(
    name = "foo_runfiles_tar",
    srcs = [ 
        ":foo_runfiles",
    ],  
    remap_paths = { 
        ".runfiles/": "%s.runfiles/" % BINARY_NAME,
    },  
    include_runfiles = True,
    package_dir = PACKAGE_ROOT,
)

Without this fix, I get the error:

ERROR: /home/user/workspace/BUILD:100:8: in pkg_tar_impl rule //:runfiles_tar:                                                                                                                                          
Traceback (most recent call last):                                                                                                                                                                                                                                                       
        File "/home/user/.cache/bazel/_bazel_user/4f6a42b622be4073a123bfbe9178017e/external/rules_pkg+/pkg/private/tar/tar.bzl", line 136, column 19, in _pkg_tar_impl                                                                                                                   
                add_label_list(mapping_context, srcs = ctx.attr.srcs)                                                                                                                                                                                                                    
        File "/home/user/.cache/bazel/_bazel_user/4f6a42b622be4073a123bfbe9178017e/external/rules_pkg+/pkg/private/pkg_files.bzl", line 374, column 34, in add_label_list                                                                                                                
                add_from_default_info(                                                                                                                                                                                                                                                   
        File "/home/user/.cache/bazel/_bazel_user/4f6a42b622be4073a123bfbe9178017e/external/rules_pkg+/pkg/private/pkg_files.bzl", line 440, column 52, in add_from_default_info                                                                                                         
                base_file = the_executable or all_files[0]                                                                                                                                                                                                                               
Error: index out of range (index is 0, but sequence has 0 elements)                                                                                                                                                                                                                      
ERROR: /home/user/workspace/BUILD:100:8: Analysis of target '//:runfiles_tar' (config: 3689c9b) failed                                                                                                                  
ERROR: Analysis of target '//:runfiles_tar' failed; build aborted

I am using version 1.2.0 of rules_pkg.

If there is no `base_path` because there are no files, just use the empty string for the `base_file_path`.
@tempoz tempoz requested review from aiuto and cgrindel as code owners March 9, 2026 17:28
Copy link
Collaborator

@tonyaiuto tonyaiuto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a test case for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants