Skip to content

Conversation

kellyma2
Copy link
Contributor

@kellyma2 kellyma2 commented Oct 11, 2023

If we don't specify the _topdir as part of the install-from path we can't seem to find the correct files to install when using a set of rules like:

pkg_filegroup(
    name = "my_filegroup",
    srcs = [
      "//some/label:foo",
    ],
    prefixs = "/usr/bin",
)

pkg_rpm(
    name = "rpm",
    ...
    srcs = [
        ":my_filegroup",
    ],
)

Adding %{{_topdir}/BUILD/ as a prefix to the source path seems to solve this problem.

If we don't specify the _topdir as part of the install-from path we
can't seem to find the correct files to install when using a set of
rules like:

pkg_filegroup(
    name = "my_filegroup",
    srcs = [
      "//some/label:foo",
    ],
    prefixs = "/usr/bin",
)

pkg_rpm(
    name = "rpm",
    ...
    srcs = [
        ":my_filegroup",
    ],
)

Adding '%{{_topdir}/BUILD/' as a prefix to the source path seems to
solve this problem.
@aiuto aiuto requested a review from nacl October 16, 2023 21:21
@kellyma2 kellyma2 closed this Oct 18, 2023
@kellyma2 kellyma2 reopened this Oct 18, 2023
@aiuto
Copy link
Collaborator

aiuto commented Oct 19, 2023

Can you add a test for this and explain more clearly what is failing?
The RPM builder has been working for a long time, and some test input is from pkg_filegroup, so it is surprising that the code is so for off.

@kellyma2
Copy link
Contributor Author

Can you add a test for this and explain more clearly what is failing? The RPM builder has been working for a long time, and some test input is from pkg_filegroup, so it is surprising that the code is so for off.

I'll try to rig up a test for this tomorrow and also provide more details. The tl;dr was that it couldn't find the expected inputs in the relative path, but putting the prefix in place means it becomes an absolute path and can be resolved.

@kellyma2
Copy link
Contributor Author

Can you add a test for this and explain more clearly what is failing? The RPM builder has been working for a long time, and some test input is from pkg_filegroup, so it is surprising that the code is so for off.

Still working through adding a test for this, but figured I'd provide a bit more detail as to what the failure (and my rules) look like. I'm using https://github.com/bazelbuild/examples/tree/main/cpp-tutorial/stage1 as a simple scaffold for verifying the failure. My rules are as follows:

  • main/BUILD:
load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "pkg_attributes")

pkg_files(
    name = "exe",
    srcs = [
        ":hello-world",
    ],
    visibility = ["//visibility:public"],
    attributes = pkg_attributes(
        mode = "0755",
        user = "root",
        group = "root",
    ),
)

Root BUILD:

load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup")
load("@rules_pkg//pkg:rpm.bzl", "pkg_rpm")

pkg_filegroup(
    name = "rpm_filegroup",
    srcs = [
        "//main:exe",
    ],
    prefix = "/usr/bin",
)

pkg_rpm(
    name = "rpm",
    package_name = "example",
    license = "bar",
    summary = "baz",
    version = "1.0.0",
    release = "foo",
    description = "bam",
    architecture = "x86_64",
    srcs = [
        ":rpm_filegroup",
    ],
)

in WORKSPACE I'm configuring things with:

load("@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild")

find_system_rpmbuild(name="rule_pkg_rpmbuild")

Where @rules_pkg is just pointing at a fresh clone of rules_pkg in my local worktree.

When I run bazel build rpm the output I get is:

> bazel build rpm
Loading: 
Loading: 
Loading: 0 packages loaded
Analyzing: target //:rpm (1 packages loaded, 0 targets configured)
INFO: Analyzed target //:rpm (2 packages loaded, 5 targets configured).
INFO: Found 1 target...
bazel: Entering directory `/tmp/mkelly/bazel/execroot/__main__/'
[0 / 8] [Prepa] BazelWorkspaceStatusAction stable-status.txt
INFO: From MakeRpm example-1.0.0-foo.x86_64.rpm:
Error calling rpmbuild:
Executing(%install): /bin/sh -e /tmp/tmp2s0xmxiy/TMP/rpm-tmp.u26xbD
+ umask 022
+ cd /tmp/tmp2s0xmxiy/bld-x86_64/example
+ '[' /tmp/tmp2s0xmxiy/BUILDROOT '!=' / ']'
+ rm -rf /tmp/tmp2s0xmxiy/BUILDROOT
++ dirname /tmp/tmp2s0xmxiy/BUILDROOT
+ mkdir -p /tmp/tmp2s0xmxiy
+ mkdir /tmp/tmp2s0xmxiy/BUILDROOT
++ dirname /usr/bin/hello-world
+ install -d /tmp/tmp2s0xmxiy/BUILDROOT//usr/bin
+ cp bazel-out/k8-fastbuild/bin/main/hello-world /tmp/tmp2s0xmxiy/BUILDROOT//usr/bin/hello-world
cp: cannot stat 'bazel-out/k8-fastbuild/bin/main/hello-world': No such file or directory
error: Bad exit status from /tmp/tmp2s0xmxiy/TMP/rpm-tmp.u26xbD (%install)


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

No RPM file created.
ERROR: /tmp/test/examples/cpp-tutorial/stage1/BUILD:12:8: output 'example-1.0.0-foo.x86_64.rpm' was not created
ERROR: /tmp/test/examples/cpp-tutorial/stage1/BUILD:12:8: MakeRpm example-1.0.0-foo.x86_64.rpm failed: not all outputs were created or valid
bazel: Leaving directory `/tmp/mkelly/bazel/execroot/__main__/'
Target //:rpm failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.255s, Critical Path: 0.17s
INFO: 2 processes: 1 internal, 1 linux-sandbox.
FAILED: Build did NOT complete successfully

@aiuto
Copy link
Collaborator

aiuto commented Oct 31, 2023

  • cp bazel-out/k8-fastbuild/bin/main/hello-world /tmp/tmp2s0xmxiy/BUILDROOT//usr/bin/hello-world
    cp: cannot stat 'bazel-out/k8-fastbuild/bin/main/hello-world': No such file or directory
    I'm scratching my head a bit on this. That should be the path to hello-world.

@kellyma2
Copy link
Contributor Author

  • cp bazel-out/k8-fastbuild/bin/main/hello-world /tmp/tmp2s0xmxiy/BUILDROOT//usr/bin/hello-world
    cp: cannot stat 'bazel-out/k8-fastbuild/bin/main/hello-world': No such file or directory
    I'm scratching my head a bit on this. That should be the path to hello-world.

That would be my expectation and with this PR it actually correctly points to it because the path ceases to be relative. When you take the example repo and apply my BUILD + WORKSPACE setup what do you get?

Also, missed part of my WORKSPACE the correct variant also includes:

local_repository(
    name = "rules_pkg",
    path = "/home/mkelly/repos/bazel/rules_pkg",
)

load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")

rules_pkg_dependencies()

aiuto added a commit to aiuto/rules_pkg that referenced this pull request Oct 31, 2023
@aiuto
Copy link
Collaborator

aiuto commented Oct 31, 2023

Take a look at #770

I tried to prove your change works, but it failed in new and unexpected ways.
Perhaps you do something like that as a test case or example.

@kellyma2
Copy link
Contributor Author

kellyma2 commented Nov 6, 2023

After a bit of thrashing around with the Fedora docker image it seems like I got this working and it's using rpmbuild 4.18.1 - I'll see if I can upgrade rpmbuild in my build environment to determine if this also happens there.

Secondary to this, should there be a minimum version check for the version of rpmbuild being used?

@kellyma2 kellyma2 requested a review from cgrindel as a code owner December 12, 2023 17:19
Copy link
Collaborator

@cgrindel cgrindel left a comment

Choose a reason for hiding this comment

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

The change looks reasonable. However, I noticed that @aiuto requested a test for this. Were you able to create one? Also, could you ping me again when CI is green?

@kellyma2 kellyma2 closed this Dec 12, 2023
@kellyma2 kellyma2 deleted the fix-install-stanza branch February 17, 2024 01:22
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