Skip to content

cockpit: set RPM_BUILD_ROOT w/ installing#2989

Merged
jirihnidek merged 1 commit intomainfrom
ptoscano/newer-distutils
Mar 4, 2022
Merged

cockpit: set RPM_BUILD_ROOT w/ installing#2989
jirihnidek merged 1 commit intomainfrom
ptoscano/newer-distutils

Conversation

@ptoscano
Copy link
Copy Markdown
Contributor

@ptoscano ptoscano commented Mar 1, 2022

Due to a recent change in Fedora 36 [1], the installation prefix is
mangled in certain scenarios [2].

Hence, set a $RPM_BUILD_ROOT environment variable when invoking
setup.py install, so it works again as it used in older versions of
Fedora. This script is used only for the cockpit CI testing, so there
is no change for usual builds.

[1] https://src.fedoraproject.org/rpms/python3.10/pull-request/63
[2] https://bugzilla.redhat.com/show_bug.cgi?id=2026979

@cnsnyder cnsnyder requested review from a team and jirihnidek and removed request for a team March 1, 2022 12:52
@ptoscano
Copy link
Copy Markdown
Contributor Author

ptoscano commented Mar 1, 2022

Forgot to mention, thanks @jelly for reporting this problem while adding fedora-36 to the cockpit CI images for subscription-manager [1]!

[1] cockpit-project/bots#3016

Copy link
Copy Markdown
Contributor

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

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

This is an absolutely terrible hack and workaround. I asked in pypa/distutils#70 (comment) , but it is still plain wrong to install custom stuff into /usr.

Can't you install this into /usr/local/ (the correct location for non-distribution code) and run tests with that? E.g. cockpit is totally fine with reading packages from /usr/local/share/cockpit/subscription-manager, and it prefers that over an existing /usr/share/cockpit/subscription-manager/.

@martinpitt
Copy link
Copy Markdown
Contributor

Or rather, as it fails here:

+ mv /usr/bin/rhsm-facts-service /usr/bin/rhsm-service /usr/bin/rhsmcertd-worker /usr/libexec
mv: cannot stat '/usr/bin/rhsm-facts-service': No such file or directory
mv: cannot stat '/usr/bin/rhsm-service': No such file or directory
mv: cannot stat '/usr/bin/rhsmcertd-worker': No such file or directory

explicitly install into /usr/local and adjust the mv to move from /usr/local/bin/ ?

@martinpitt
Copy link
Copy Markdown
Contributor

Or even better, actually call rpmbuild -tb on your make dist tarball to build rpms, and install these? This will then also validate your spec file on the corresponding distributions, which is an additional win

@hroncok
Copy link
Copy Markdown
Contributor

hroncok commented Mar 1, 2022

For the record, I doubt this is due to the recent change in https://github.com/pypa/distutils -- we have carried this patch in distutils in the standard library since Fedora 27.

@hroncok
Copy link
Copy Markdown
Contributor

hroncok commented Mar 1, 2022

Forgot to mention, thanks @jelly for reporting this problem while adding fedora-36 to the cockpit CI images for subscription-manager [1]!

[1] cockpit-project/bots#3016

If this indeed started to happen in Fedora 36, this is much more likely caused by https://src.fedoraproject.org/rpms/python3.10/pull-request/63 -- that change landed in rawhide 5 months ago and I am quite sad that you have only discovered this now.

See also https://discuss.python.org/t/mechanism-for-distributors-to-add-site-install-schemes-to-python-installations/8467/1 and https://bugs.python.org/issue43976

@ptoscano
Copy link
Copy Markdown
Contributor Author

ptoscano commented Mar 1, 2022

but it is still plain wrong to install custom stuff into /usr.

The environment is a testing VM, it does not matter that /usr is polluted. Also, it installed on /usr to make sure to properly override the system installation.

If this indeed started to happen in Fedora 36, this is much more likely caused by https://src.fedoraproject.org/rpms/python3.10/pull-request/63 -- that change landed in rawhide 5 months ago and I am quite sad that you have only discovered this now.

We don't regularly test on Dedora rawhide, and AFAIK the cockpit CI doesn't test on it because of "not exactly stable" (AFAICR).

Or even better, actually call rpmbuild -tb on your make dist tarball to build rpms, and install these? This will then also validate your spec file on the corresponding distributions, which is an additional win

We have already other CI jobs that check that the spec file works and the package build is correct. Personally I'd like to limit the scope of the testing of this as much as possible.

@hroncok
Let me say explicitly: I appreciate your work in trying to make Python usable in Fedora (and RHEL too), as good platform for the Python-based ecosystem. So I don't want to imply that this is a bad/negative critique on your work, be the upstream changes or the Fedora-specific one.
That said: even in the context of a distribution, I don't understand why explicit install locations are not properly honoured; the invocation here is a simple

python3 ./setup.py install --prefix /usr --root /

I get the reasons behind not installing to /usr but rather to /usr/local for "system installations". However, if I explicitly want to install in a certain location, including /usr, I'd expect it to be respected and not silently mangled. This breaks the usability of existing scripts (like this) that, for certain reasons, may want to explicitly install to /usr.

@hroncok
Copy link
Copy Markdown
Contributor

hroncok commented Mar 1, 2022

I get the reasons behind not installing to /usr but rather to /usr/local for "system installations". However, if I explicitly want to install in a certain location, including /usr, I'd expect it to be respected and not silently mangled. This breaks the usability of existing scripts (like this) that, for certain reasons, may want to explicitly install to /usr.

I don't disagree. The culprit is in the fact that /local/ is technically not part of the prefix. See https://bugzilla.redhat.com/show_bug.cgi?id=2026979 for details.

@ptoscano
Copy link
Copy Markdown
Contributor Author

ptoscano commented Mar 1, 2022

I get the reasons behind not installing to /usr but rather to /usr/local for "system installations". However, if I explicitly want to install in a certain location, including /usr, I'd expect it to be respected and not silently mangled. This breaks the usability of existing scripts (like this) that, for certain reasons, may want to explicitly install to /usr.

I don't disagree. The culprit is in the fact that /local/ is technically not part of the prefix. See https://bugzilla.redhat.com/show_bug.cgi?id=2026979 for details.

Well, technically yes, however adding unexpected parts like this is not exactly a fair chance to the build system, IMHO.

Reading the bug makes me think that there is no solution for this in sight soon. Would it be OK from your POV if I amend the message of this to reflect the actual case, and keep the workaround?

@hroncok
Copy link
Copy Markdown
Contributor

hroncok commented Mar 1, 2022

Would it be OK from your POV if I amend the message of this to reflect the actual case, and keep the workaround?

I care for the amended message because I think it's not good to reference an unrelated change in pypa/distutils. Thanks for that.

Whether or not you keep the workaround, I don't have a preference, as I don't have enough knowledge about your use case. If you think you must install to /usr directly, keep the workaround.

@martinpitt
Copy link
Copy Markdown
Contributor

@ptoscano : What's wrong with just installing to /usr/local? (not by accident, but deliberately)?

tar xzf ../subscription-manager-build-extra.tar.gz
python3 ./setup.py build
python3 ./setup.py install --prefix /usr --root /
RPM_BUILD_ROOT="" python3 ./setup.py install --prefix /usr --root /
Copy link
Copy Markdown
Contributor

@hroncok hroncok Mar 1, 2022

Choose a reason for hiding this comment

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

As for the workaround itself, I suggest the following:

Suggested change
RPM_BUILD_ROOT="" python3 ./setup.py install --prefix /usr --root /
# Simulate installation via RPM package by setting $RPM_BUILD_ROOT
# That way, we install to /usr instead of /usr/local, which is needed to ???
RPM_BUILD_ROOT=/ python3 ./setup.py install

Note three things:

  • the intent of setting $RPM_BUILD_ROOT is visible
  • the value of $RPM_BUILD_ROOT actually make sense (while technically, it doesn't matter)
  • the --prefix and --root arguments are probably useless so I've removed them

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can make $RPM_BUILD_ROOT more visible and more correct, however --prefix and --root have to stay as they are, as they are needed in older Fedora and RHEL version (the current cockpit testing matrix for main is fedora >= 34 and rhel >= 8.4).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

as they are needed in older Fedora and RHEL version

Are you sure?

Copy link
Copy Markdown
Contributor

@hroncok hroncok Mar 1, 2022

Choose a reason for hiding this comment

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

Root always defaults to /. And prefix defaults to /usr when $RPM_BUILD_ROOT is set.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you please a least try this?

Suggested change
RPM_BUILD_ROOT="" python3 ./setup.py install --prefix /usr --root /
RPM_BUILD_ROOT="/" python3 ./setup.py install

Copy link
Copy Markdown
Contributor Author

@ptoscano ptoscano Mar 1, 2022

Choose a reason for hiding this comment

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

I need --root, as at least on RHEL >= 8.5 it did change the behaviour; see commit c7d74b7 (from #2840).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Mea culpa. I've just tested this on CentOS Stream 8 and there is indeed a very weird error happening without --root:

running install_data
error: [Errno 2] No such file or directory: 'build/locale'

With --root /, it is gone. The reason appears to be that without --root the build process goes through bdist_egg and the build fails as your custom build class does not support that. It appears the --root option serves as another undocumented workaround here. Oh my.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So... should we go ahead with the current changes? (note I updated this PR a couple of hours ago)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I consider my concerns resolved. Note however that IMHO you are piling up workarounds on top of workarounds and actually building the RPM might be safer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Well, the bigger workaround here is the sucky buildsystem, so there isn't much "good" doable when the baseline is already poor... :-(

@ptoscano
Copy link
Copy Markdown
Contributor Author

ptoscano commented Mar 1, 2022

@ptoscano : What's wrong with just installing to /usr/local? (not by accident, but deliberately)?

Note that this was added originally with #2091.

Personally speaking, I had bad past experiences with locally installed stuff in /usr/local that was supposed to shadow things in /usr but it really didn't, resulting in broken setups. That's why I never use /usr/local myself on my systems.

Another point is that sub-man has bits that have to be in certain system locations, e.g. the package manager plugins. Right now (because of the awful build system we have) they are not installed in the testing system during the cockpit testing, and this is a minor issue that so far has not hit us yet.

So we really need to keep doing system installations to fully test sub-man.

Due to a recent change in Fedora 36 [1], the installation prefix is
mangled in certain scenarios [2].

Hence, set a $RPM_BUILD_ROOT environment variable when invoking
'setup.py install', so it works again as it used in older versions of
Fedora. This script is used only for the cockpit CI testing, so there
is no change for usual builds.

[1] https://src.fedoraproject.org/rpms/python3.10/pull-request/63
[2] https://bugzilla.redhat.com/show_bug.cgi?id=2026979
@ptoscano ptoscano force-pushed the ptoscano/newer-distutils branch from eb26c57 to 763e0ca Compare March 1, 2022 16:22
Copy link
Copy Markdown
Contributor

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

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

Thanks! I still can't say I like it, but at least the situation is properly analyzed now, and it's the best you can do if you don't want to build/install an rpm. As a non-project member I can't formally approve, but I can at least revoke my "suggesting changes".

Thanks @hroncok for your help here!

Copy link
Copy Markdown
Contributor

@jirihnidek jirihnidek left a comment

Choose a reason for hiding this comment

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

Thanks for all your reviews 👍

@jirihnidek jirihnidek merged commit 9eb80b3 into main Mar 4, 2022
@jirihnidek jirihnidek deleted the ptoscano/newer-distutils branch March 4, 2022 10:16
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.

4 participants