bazelbuild / rules_pkg

Bazel rules for creating packages of many types (zip, tar, deb, rpm, ...)
Apache License 2.0
216 stars 174 forks source link

[pkg_tar] Unable to use select in files attribute #717

Closed farcop closed 1 year ago

farcop commented 1 year ago

This way does not work

pkg_tar(
    name = "tar-binaries",
    files = select({
        "@platforms//cpu:arm64": {
            "@kubectl_linux_arm64-lo//file": "kubectl%s" % KUBECTL_LO,
        },
        "@platforms//cpu:x86_64": {
            "@kubectl_linux_amd64-lo//file": "kubectl%s" % KUBECTL_LO,
        },
    }),
    mode = "0555",
    owner = "1001.1001",
    package_dir = "/opt/kublr",
)
DEBUG: /private/var/tmp/_bazel_farcop/e66529431dbede3bc951f821053136ab/external/rules_pkg~0.9.1/pkg/private/tar/tar.bzl:318:22: @//images/kubectl:tar-binaries: you provided a non dictionary to the pkg_tar `files` attribute. This attribute was renamed to `srcs`. Consider renaming it in your BUILD file.

But this notation works fine:

pkg_tar(
    name = "tar-binaries",
    files = {
        "@kubectl_linux_amd64-lo//file": "kubectl%s" % KUBECTL_LO,
    },
    mode = "0555",
    owner = "1001.1001",
    package_dir = "/opt/kublr",
)

I suppose this is a bug in this logic https://github.com/bazelbuild/rules_pkg/blob/main/pkg/private/tar/tar.bzl#L318

Proposed fix: Change if not hasattr(kwargs["files"], "items"): to if not types.is_dict(kwargs["files"]):

aiuto commented 1 year ago

Did you try that? I'll review a PR.

farcop commented 1 year ago

Sorry, I have tested my suggestion and it behaves the same. So the problem is in select() as far as I understand. May be this issue https://github.com/bazelbuild/bazel/issues/8171

farcop commented 1 year ago

Closing this issue.

aiuto commented 1 year ago

Inspecting into a select generally does not work. An alternative might be to drop the support for the super deprecated version and make the breaking change explicit.