Skip to content

[pkg_files]: index-out-of-range error when src[DefaultInfo].files is empty #1070

Description

@grrtrr

Problem description

Under the following condition add_from_default_info() produces the index out of range error below:

  1. include_runfiles=True,
  2. src[DefaultInfo].files is empty,
  3. src[DefaultInfo].default_runfiles is not empty.

In that case, add_from_default_info() assumes that (2) is False, and so causes the exception:

  File "/home/grenker/.cache/bazel/_bazel_grenker/d2508ebd25597e9a92cadc5f3ae02937/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/grenker/.cache/bazel/_bazel_grenker/d2508ebd25597e9a92cadc5f3ae02937/external/rules_pkg/pkg/private/pkg_files.bzl", line 373, column 34, in add_label_list
          add_from_default_info(
  File "/home/grenker/.cache/bazel/_bazel_grenker/d2508ebd25597e9a92cadc5f3ae02937/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)

What to do

Return early if either (1) DefaultInfo is not an attribute of src or (2) src[DefaultInfo].files is empty.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions