bazelbuild / rules_pkg

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

pkg_rpm build fails if the source paths contain whitespaces #732

Closed k0walik closed 1 year ago

k0walik commented 1 year ago

While experimenting with pkg_rpm I noticed the rpmbuild will fail to create the package if the source paths (files, symbolic links, directories) contain whitespaces in their paths. Consider the following example:

$ tree test
test
├── BUILD.bazel
├── foo bar
└── foobar
load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "pkg_mkdirs", "pkg_mklink")
load("@rules_pkg//pkg:rpm.bzl", "pkg_rpm")

pkg_files(
    name = "files",
    srcs = [
        "foo bar",
        "foobar",
    ],
)

pkg_mklink(
    name = "symlinks",
    link_name = "sym link",
    target = "/foobar",
)

pkg_mkdirs(
    name = "directories",
    dirs = ["dire ctory"],
)

pkg_rpm(
    name = "test",
    package_name = "test",
    srcs = [
        # Comment out sources and observe failing behavior
        ":directories",
        ":files",
        ":symlinks",
    ],
    description = "description",
    license = "license",
    release = "0",
    summary = "summary",
    version = "0.0.0",
)

The above will fail with the following error message (stops at first error):

Error calling rpmbuild:
Executing(%install): /bin/sh -e /tmp/tmpqxx5wk6d/TMP/rpm-tmp.B9Hhpr
+ umask 022
+ cd /tmp/tmpqxx5wk6d/BUILD
+ /bin/rm -rf /tmp/tmpqxx5wk6d/BUILDROOT
+ /bin/mkdir -p /tmp/tmpqxx5wk6d
+ /bin/mkdir /tmp/tmpqxx5wk6d/BUILDROOT
+ install -d /tmp/tmpqxx5wk6d/BUILDROOT//dire ctory
+ dirname /foo bar
+ install -d /tmp/tmpqxx5wk6d/BUILDROOT// .
+ cp dev/foo bar /tmp/tmpqxx5wk6d/BUILDROOT//foo bar
cp: target 'bar' is not a directory
error: Bad exit status from /tmp/tmpqxx5wk6d/TMP/rpm-tmp.B9Hhpr (%install)

RPM build errors:
    Bad exit status from /tmp/tmpqxx5wk6d/TMP/rpm-tmp.B9Hhpr (%install)

No RPM file created.