Skip to content

Handle cases with only data dependencies in pkg_tar#1044

Merged
aiuto merged 3 commits intobazelbuild:mainfrom
tempoz:patch-1
Mar 17, 2026
Merged

Handle cases with only data dependencies in pkg_tar#1044
aiuto merged 3 commits intobazelbuild:mainfrom
tempoz:patch-1

Conversation

@tempoz
Copy link
Copy Markdown
Contributor

@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
Copy Markdown
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.

@tempoz
Copy link
Copy Markdown
Contributor Author

tempoz commented Mar 16, 2026

done!

Fix buildify lint
@aiuto aiuto merged commit 5449272 into bazelbuild:main Mar 17, 2026
6 checks passed
rdesgroppes added a commit to DataDog/datadog-agent that referenced this pull request Mar 20, 2026
What does this PR do?
bump rules_pkg to Mar 17 main, picking up:
- bazelbuild/rules_pkg#1024: RPM build errors would go unnoticed without it
- bazelbuild/rules_pkg#1035: affects reproducibiliy of builds
- bazelbuild/rules_pkg#1044
- bazelbuild/rules_pkg#1046: a contribution of ours (@chouquette)
- bazelbuild/rules_pkg#1047: we might need this
gh-worker-dd-mergequeue-cf854d bot pushed a commit to DataDog/datadog-agent that referenced this pull request Mar 20, 2026
### What does this PR do?
Bump `rules_pkg` to current `main`.

### Motivation
Pick up:
- bazelbuild/rules_pkg#1021: a contribution of ours
- bazelbuild/rules_pkg#1024: RPM build errors would go unnoticed without it
- bazelbuild/rules_pkg#1035: affects reproducibiliy of builds
- bazelbuild/rules_pkg#1044
- bazelbuild/rules_pkg#1046: another contribution of ours (@chouquette)
- bazelbuild/rules_pkg#1047: we might need this feature

Co-authored-by: regis.desgroppes <[email protected]>
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.

3 participants